66import com .sun .codemodel .JInvocation ;
77import com .sun .codemodel .JMethod ;
88import com .sun .codemodel .JMod ;
9+ import com .sun .codemodel .JType ;
10+ import com .sun .codemodel .JVar ;
911import com .sun .tools .xjc .Options ;
1012import com .sun .tools .xjc .Plugin ;
1113import com .sun .tools .xjc .model .CPluginCustomization ;
1214import com .sun .tools .xjc .outline .ClassOutline ;
15+ import com .sun .tools .xjc .outline .FieldOutline ;
1316import com .sun .tools .xjc .outline .Outline ;
1417import com .sun .tools .xjc .util .DOMUtils ;
1518import javax .xml .bind .annotation .XmlTransient ;
@@ -73,29 +76,30 @@ public boolean run(Outline model, Options opt, ErrorHandler errorHandler) {
7376 interfaceName = globalInterfaceSetting ;
7477 }
7578 if (VetoableChangeListener .class .getName ().equals (interfaceName )) {
76- addSupport (VetoableChangeListener .class , VetoableChangeSupport .class , co . implClass );
79+ addSupport (VetoableChangeListener .class , VetoableChangeSupport .class , co );
7780 }
7881 if (PropertyChangeListener .class .getName ().equals (interfaceName )) {
79- addSupport (PropertyChangeListener .class , PropertyChangeSupport .class , co . implClass );
82+ addSupport (PropertyChangeListener .class , PropertyChangeSupport .class , co );
8083 }
8184
8285 }
8386
8487 return true ;
8588 }
8689
87- private void addSupport (Class listener , Class support , JDefinedClass target ) {
90+ private void addSupport (Class listener , Class support , ClassOutline classOutline ) {
8891
92+ JDefinedClass target = classOutline .implClass ;
8993 // add the support field.
9094 // JFieldVar field = target.field(JMod.PRIVATE|JMod.TRANSIENT, support, "support");
91- JFieldVar field = target .field (JMod .PRIVATE , support , "support" );
95+ JFieldVar fieldSupport = target .field (JMod .PRIVATE , support , "support" );
9296
93- field .annotate (XmlTransient .class );
97+ fieldSupport .annotate (XmlTransient .class );
9498
9599 // and initialize it....
96- field .init (JExpr .direct ("new " + support .getSimpleName () + "(this)" ));
100+ fieldSupport .init (JExpr .direct ("new " + support .getSimpleName () + "(this)" ));
97101
98- // we need to hadd
102+ // we need to add
99103 for (Method method : support .getMethods ()) {
100104 if (Modifier .isPublic (method .getModifiers ())) {
101105 if (method .getName ().startsWith ("add" )) {
@@ -118,6 +122,38 @@ private void addSupport(Class listener, Class support, JDefinedClass target) {
118122 }
119123 }
120124 }
125+
126+ final FieldOutline [] declaredFields = classOutline .getDeclaredFields ();
127+ for (final FieldOutline fieldOutline : declaredFields ) {
128+
129+ final String publicName = fieldOutline .getPropertyInfo ().getName (true );
130+
131+ final String setterName = "set" + publicName ;
132+
133+ final JType rawType = fieldOutline .getRawType ();
134+ final JMethod boxifiedSetter = target .getMethod (setterName , new JType [] { rawType .boxify () });
135+ final JMethod unboxifiedSetter = target .getMethod (setterName , new JType [] { rawType .unboxify () });
136+ final JMethod setter = boxifiedSetter != null ? boxifiedSetter : unboxifiedSetter ;
137+
138+ if (setter != null ) {
139+ final String privateName = fieldOutline .getPropertyInfo ().getName (false );
140+ final JFieldVar field = target .fields ().get (privateName );
141+ if (field != null ) {
142+ /*
143+ * String oldValue = this.value;
144+ * this.value = newValue;
145+ * this.pcs.firePropertyChange("value", oldValue, newValue);
146+ */
147+ setter .body ().pos (0 );
148+
149+ final JVar oldPropertyValue = setter .body ().decl (JMod .FINAL ,
150+ rawType , "old" + publicName ,
151+ field );
152+ setter .body ().pos (setter .body ().getContents ().size ());
153+ setter .body ().add (fieldSupport .invoke ("firePropertyChange" ).arg (privateName ).arg (oldPropertyValue ).arg (field ));
154+ }
155+ }
156+ }
121157 }
122158
123159 private void addMethod (Method method , JDefinedClass target ) {
0 commit comments