Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
ModifiableAdvisor.java
Upload User: jiancairen
Upload Date: 2007-08-27
Package Size: 26458k
Code Size: 3k
Category:
Java Develop
Development Platform:
Java
- /*
- * Copyright 2002-2004 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package org.springframework.aop.framework.autoproxy.metadata;
- import java.util.Collection;
- import java.util.Iterator;
- import org.aopalliance.intercept.MethodInvocation;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.springframework.aop.framework.AopConfigException;
- import org.springframework.aop.support.DelegatingIntroductionInterceptor;
- import org.springframework.aop.support.DefaultIntroductionAdvisor;
- import org.springframework.beans.factory.InitializingBean;
- import org.springframework.metadata.Attributes;
- /**
- *
- * @author Rod Johnson
- */
- public class ModifiableAdvisor extends DefaultIntroductionAdvisor implements InitializingBean {
- protected final Log log = LogFactory.getLog(getClass());
- private Attributes attributes;
- public ModifiableAdvisor() {
- super(new ModifiableIntroductionInterceptor(), Modifiable.class);
- }
- public void setAttributes(Attributes atts) {
- this.attributes = atts;
- }
- private boolean matches(Collection c) {
- //log.info("Checking for modifiable attribute; atts.length=" + atts.size());
- for (Iterator itr = c.iterator(); itr.hasNext(); ) {
- Object next = itr.next();
- if (next instanceof ModifiableAttribute) {
- log.info("FOUND modifiable attribute " + next);
- return true;
- }
- }
- return false;
- }
- /**
- * @see org.springframework.core.Ordered#getOrder()
- */
- public int getOrder() {
- throw new UnsupportedOperationException();
- }
- /**
- * @see org.springframework.aop.ClassFilter#matches(java.lang.Class)
- */
- public boolean matches(Class targetClass) {
- log.info("Checking for mod attribute on " + targetClass + " attributes=" + attributes);
- Collection atts = this.attributes.getAttributes(targetClass);
- return matches(atts);
- }
- private static class ModifiableIntroductionInterceptor
- extends DelegatingIntroductionInterceptor
- implements Modifiable {
- private boolean dirty = false;
- /**
- * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
- */
- public Object invoke(MethodInvocation mi) throws Throwable {
- if (!isMethodOnIntroducedInterface(mi)) {
- if (!mi.getMethod().getName().startsWith("get")) {
- this.dirty = true;
- }
- }
- return super.invoke(mi);
- }
- /**
- * @see org.springframework.enterpriseservices.mod.Modifable#isModified()
- */
- public boolean isModified() {
- logger.info("isModified");
- return this.dirty;
- }
- public void acceptChanges() {
- logger.info("Accepting changes");
- this.dirty = false;
- }
- }
- /**
- * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
- */
- public void afterPropertiesSet() throws Exception {
- if (this.attributes == null)
- throw new AopConfigException("Must set Attributes property on ModifiableAdvice");
- }
- }