javaee / jaxb2-commons

JAXB Implementation project has been contributed to Eclipse Foundation. This repository is for legacy review only. Please refer to the Eclipse EE4J Metro project for the very latest
https://eclipse-ee4j.github.io/jaxb-ri/
Other
17 stars 15 forks source link

property-listener-injector: PropertyChangeEvent should be fired after value was changed, not before (incl. patch) #25

Open glassfishrobot opened 14 years ago

glassfishrobot commented 14 years ago

So far I did not found any explicit statement in the Java Bean Specification, that PropertyChangeEvents have not to be fired before an attribute was changed. But in all implementations of the Java framework and all examples using PropertyChangedEvents the events are fired only after a change and not before.

Maybe the property-listener-injector should be follow this behavior too? Arranging this is pretty simple. Just modify the code generating the body of the setMethod in:

com.sun.tools.xjc.addon.property_listener_injector.SingleField:201

JBlock body = $set.body(); if (boundType!=null) { if (boundType==Kind.VETOABLE)

{ JTryBlock tryBlock = body._try(); JClass vetoableClass = (JClass) codeModel._ref(java.beans.PropertyVetoException.class); tryBlock.body().add( JExpr.ref("support").invoke("fireVetoableChange"). arg(prop.getName(false)).arg(JExpr.refthis(ref().name())).arg($value)); //tryBlock.body().directStatement("support.fireVetoableChange(\"" + prop.getName(false)+ "\"," + ref().name() + ", value);"); JCatchBlock catchBlock = tryBlock._catch(vetoableClass); catchBlock.body().directStatement("return;"); body.assign(JExpr._this().ref(ref()),castToImplType($value)); }

else

{ JVar $oldValue = body.decl(setterType, "oldValue", JExpr.ref("value")); body.assign(JExpr._this().ref(ref()),castToImplType($value)); body.add(JExpr.ref("support").invoke("firePropertyChange"). arg(prop.getName(false)).arg($oldValue).arg($value)); }

} else

{ body.assign(JExpr._this().ref(ref()),castToImplType($value)); }

The pom.xml needs an update too. I compiled it versus com.sun.xml.bind/jaxb-xjc/2.2

Environment

Operating System: All Platform: All

Affected Versions

[current]

glassfishrobot commented 14 years ago

Reported by ralfhergert

glassfishrobot commented 14 years ago

lexi said: I'll address this; however the plugin will then be overtaken to the JAXB2 Basics (http://confluence.highsource.org/display/J2B/Home).

glassfishrobot commented 11 years ago

mwise said: Was this ever addressed? I've downloaded the latest version 1.1-SNAPSHOT from http://download.java.net/maven/2/org/jvnet/jaxb2-commons/property-listener-injector/ and this still has the bug. Also properties that are primitives rather than objects don't get firePropertyChange calls injected.

Having got hold of the sources from the above location, I can attempt to fix this myself, but I would rather pull in a publically-available plugin/dependency...

glassfishrobot commented 10 years ago

lexi said: Seems like the plugin was not maintained since cvs->svn move.

glassfishrobot commented 14 years ago

Was assigned to lexi

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA JAXB2_COMMONS-25