Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

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

Open
glassfishrobot opened this issue Aug 23, 2010 · 6 comments

Comments

@glassfishrobot
Copy link
Contributor

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
Copy link
Contributor Author

Reported by ralfhergert

@glassfishrobot
Copy link
Contributor Author

Was assigned to lexi

@glassfishrobot
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@glassfishrobot
Copy link
Contributor Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant