Project

General

Profile

« Previous | Next » 

Revision 479c80d3

Added by Andreas Müller almost 9 years ago

improve handling of titlecache in terms #3148

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/aspectj/PropertyChangeAspect.aj
16 16
public aspect PropertyChangeAspect {
17 17
	static Logger logger = Logger.getLogger(PropertyChangeAspect.class);
18 18
	
19
//	pointcut execAdder(CdmBase cb): target(cb) && execution(void CdmBase+.add*(..) );
19
//	pointcut execAdder(CdmBase cb): target(cb) && execution(void CdmBase+.add*(..) );  //once implemented we may want to remove addToSetWithChangeEvent and remove... from CdmBase
20 20
	
21 21
	pointcut execSetter(CdmBase cb): target(cb) && execution(void CdmBase+.set*(..) );
22 22
//	/** *********** OLD ***********************/
......
79 79
	}
80 80

  
81 81

  
82
		/**
83
		 * @param signature
84
		 * Return the Field object that belongs to the signature of a setter method
85
		 * If no matching attribute can be found return null instead of throwing an NoSuchFieldException
86
		 * Removes first 3 characters of method name to find property name
87
		 */
88
		private Field getFieldOfSetter( Signature signature ){
89
			Field field = null;
90
			String propertyName = "";
91
			//logger.debug( "Getting the field name of setter ["+signature.getName() + "]" );
82
	/**
83
	 * @param signature
84
	 * Return the Field object that belongs to the signature of a setter method
85
	 * If no matching attribute can be found return null instead of throwing an NoSuchFieldException
86
	 * Removes first 3 characters of method name to find property name
87
	 */
88
	private Field getFieldOfSetter( Signature signature ){
89
		Field field = null;
90
		String propertyName = "";
91
		//logger.debug( "Getting the field name of setter ["+signature.getName() + "]" );
92
		try{
93
			String methodName = signature.getName();
94
			propertyName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
95
			field = signature.getDeclaringType().getDeclaredField( propertyName );
96
		}catch( NoSuchFieldException e ){
92 97
			try{
93
				String methodName = signature.getName();
94
				propertyName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
98
				propertyName = "is"+propertyName.substring(0, 1).toUpperCase()+ propertyName.substring(1);
95 99
				field = signature.getDeclaringType().getDeclaredField( propertyName );
96
			}catch( NoSuchFieldException e ){
97
				try{
98
					propertyName = "is"+propertyName.substring(0, 1).toUpperCase()+ propertyName.substring(1);
99
					field = signature.getDeclaringType().getDeclaredField( propertyName );
100
				}catch( NoSuchFieldException nsfe ){
101
					// can't find any matching attribute. catch error and return null
102
					return null;
103
				}
100
			}catch( NoSuchFieldException nsfe ){
101
				// can't find any matching attribute. catch error and return null
102
				return null;
104 103
			}
105
			return field;
106
		}	
107
		/**
108
		 * Fires a propertyChange Event
109
		 * @param cb  CdmBase that fires that Event
110
		 * @param property the property's name
111
		 * @param oldval the old value
112
		 * @param newval the new value
113
		  */
114
		void fireLoggingPropertyChange( CdmBase cb,
115
				String property,
116
				Object oldval,
117
				Object newval) {
118

  
119
			//logger.debug( "PropertyChangeEvent: property [" + property + "], old value [" + oldval + "], new value [" + newval + "]");
120
			// call firePropertyChange in original class. Method defined in CdmBase superclass!
121
			cb.firePropertyChange( property,
122
					( oldval == null ) ? oldval : oldval.toString(),
123
					( newval == null ) ? newval : newval.toString());
124 104
		}
105
		return field;
106
	}
107
		
108
	/**
109
	 * Fires a propertyChange Event
110
	 * @param cb  CdmBase that fires that Event
111
	 * @param property the property's name
112
	 * @param oldval the old value
113
	 * @param newval the new value
114
	  */
115
	void fireLoggingPropertyChange( CdmBase cb,
116
			String property,
117
			Object oldval,
118
			Object newval) {
119

  
120
		//logger.debug( "PropertyChangeEvent: property [" + property + "], old value [" + oldval + "], new value [" + newval + "]");
121
		// call firePropertyChange in original class. Method defined in CdmBase superclass!
122
		cb.firePropertyChange( property,
123
				( oldval == null ) ? oldval : oldval.toString(),
124
				( newval == null ) ? newval : newval.toString());
125
	}
125 126
		
126 127
}

Also available in: Unified diff