Author: dkulp
Date: Thu Feb 18 21:08:01 2010
New Revision: 911586
URL: http://svn.apache.org/viewvc?rev=911586&view=rev
Log:
Add a plugin for adding a property listener
Added:
cxf/xjc-utils/trunk/property-listener/ (with props)
cxf/xjc-utils/trunk/property-listener/pom.xml (with props)
cxf/xjc-utils/trunk/property-listener/src/
cxf/xjc-utils/trunk/property-listener/src/main/
cxf/xjc-utils/trunk/property-listener/src/main/java/
cxf/xjc-utils/trunk/property-listener/src/main/java/com/
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/PropertyListenerPlugin.java
(with props)
cxf/xjc-utils/trunk/property-listener/src/main/java/org/
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties
(with props)
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/PropertyListenerPlugin.java
(with props)
cxf/xjc-utils/trunk/property-listener/src/main/resources/
cxf/xjc-utils/trunk/property-listener/src/main/resources/META-INF/
cxf/xjc-utils/trunk/property-listener/src/main/resources/META-INF/services/
cxf/xjc-utils/trunk/property-listener/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin
Modified:
cxf/xjc-utils/trunk/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
cxf/xjc-utils/trunk/pom.xml
Modified:
cxf/xjc-utils/trunk/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
URL:
http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java?rev=911586&r1=911585&r2=911586&view=diff
==============================================================================
---
cxf/xjc-utils/trunk/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
(original)
+++
cxf/xjc-utils/trunk/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
Thu Feb 18 21:08:01 2010
@@ -43,6 +43,7 @@
import com.sun.codemodel.JOp;
import com.sun.codemodel.JTryBlock;
import com.sun.codemodel.JType;
+import com.sun.codemodel.JVar;
import com.sun.tools.xjc.Options;
import com.sun.tools.xjc.outline.ClassOutline;
import com.sun.tools.xjc.outline.FieldOutline;
@@ -337,7 +338,6 @@
LOG.fine("Updating getter: " + getterName);
}
// remove existing method and define new one
-
dc.methods().remove(method);
method = dc.method(mods, mtype, getterName);
@@ -376,10 +376,10 @@
method = dc.method(mods, method.type(), setterName);
method.javadoc().append(doc);
- method.param(mtype, "value");
+ JVar var = method.param(mtype, "value");
JFieldRef fr = JExpr.ref(fieldName);
- method.body().assign(fr, JExpr.ref("value"));
+ method.body().assign(fr, var);
method = dc.method(mods, method.type(), "unset" +
fo.getPropertyInfo().getName(true));
method.body().assign(fr, JExpr._null());
Modified: cxf/xjc-utils/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/pom.xml?rev=911586&r1=911585&r2=911586&view=diff
==============================================================================
--- cxf/xjc-utils/trunk/pom.xml (original)
+++ cxf/xjc-utils/trunk/pom.xml Thu Feb 18 21:08:01 2010
@@ -32,6 +32,8 @@
</parent>
<properties>
+ <jdk.version>1.6</jdk.version>
+
<jaxb.version>2.1</jaxb.version>
<jaxb.xjc.version>2.1.12</jaxb.xjc.version>
<jaxb.impl.version>2.1.12</jaxb.impl.version>
@@ -55,6 +57,7 @@
<module>wsdlextension</module>
<module>wsdlextension-test</module>
<module>bug671</module>
+ <module>property-listener</module>
</modules>
<repositories>
<repository>
@@ -316,12 +319,12 @@
<outputDirectory>${eclipse.outputDirectory}</outputDirectory>
<buildcommands>
<java.lang.String>org.eclipse.jdt.core.javabuilder</java.lang.String>
-
<java.lang.String>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</java.lang.String>
+
<java.lang.String>net.sf.eclipsecs.core.CheckstyleBuilder</java.lang.String>
<java.lang.String>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</java.lang.String>
</buildcommands>
<projectnatures>
<nature>org.eclipse.jdt.core.javanature</nature>
-
<nature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</nature>
+
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
<nature>net.sourceforge.pmd.eclipse.plugin.pmdNature</nature>
</projectnatures>
<ajdtVersion>none</ajdtVersion>
@@ -422,6 +425,15 @@
<profiles>
<profile>
+ <id>jdk15</id>
+ <activation>
+ <jdk>1.5</jdk>
+ </activation>
+ <properties>
+ <jdk.version>1.5</jdk.version>
+ </properties>
+ </profile>
+ <profile>
<id>fastinstall</id>
<properties>
<maven.test.skip>true</maven.test.skip>
@@ -436,6 +448,45 @@
<checkstyle.skip>true</checkstyle.skip>
</properties>
</profile>
+
+ <profile>
+ <id>setup.eclipse</id>
+ <properties>
+
<eclipse.workspace.dir>${basedir}/../workspace</eclipse.workspace.dir>
+ </properties>
+ <build>
+ <defaultGoal>process-test-sources</defaultGoal>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.1</version>
+ <configuration>
+ <source>${jdk.version}</source>
+ <target>${jdk.version}</target>
+ <maxmem>256M</maxmem>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>setup.eclipse.project</id>
+ <phase>process-test-sources</phase>
+ <goals>
+ <goal>eclipse</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
</project>
Propchange: cxf/xjc-utils/trunk/property-listener/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Feb 18 21:08:01 2010
@@ -0,0 +1,10 @@
+.pmd
+.checkstyle
+.ruleset
+target
+eclipse-classes
+.settings
+.classpath
+.project
+.wtpmodules
+
Added: cxf/xjc-utils/trunk/property-listener/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/property-listener/pom.xml?rev=911586&view=auto
==============================================================================
--- cxf/xjc-utils/trunk/property-listener/pom.xml (added)
+++ cxf/xjc-utils/trunk/property-listener/pom.xml Thu Feb 18 21:08:01 2010
@@ -0,0 +1,52 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.cxf.xjcplugins</groupId>
+ <artifactId>cxf-xjc-pl</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache CXF XJC Property Listener Plugin</name>
+ <url>http://cxf.apache.org</url>
+
+ <parent>
+ <groupId>org.apache.cxf.xjc-utils</groupId>
+ <artifactId>xjc-utils</artifactId>
+ <version>2.3.0-SNAPSHOT</version>
+ </parent>
+
+
+ <properties>
+ <maven.test.skip>true</maven.test.skip>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-xjc</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+
+</project>
Propchange: cxf/xjc-utils/trunk/property-listener/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/xjc-utils/trunk/property-listener/pom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/xjc-utils/trunk/property-listener/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/PropertyListenerPlugin.java
URL:
http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/PropertyListenerPlugin.java?rev=911586&view=auto
==============================================================================
---
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/PropertyListenerPlugin.java
(added)
+++
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/PropertyListenerPlugin.java
Thu Feb 18 21:08:01 2010
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 com.sun.tools.xjc.addon.apache_cxf.property_listener;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+
+import com.sun.tools.xjc.Options;
+import com.sun.tools.xjc.Plugin;
+import com.sun.tools.xjc.outline.Outline;
+
+/**
+ * Thin wrapper around the DefaultValuePlugin. This must be in the
com.sun.tools.xjc.addon package
+ * for it to work with Java 6. See
https://issues.apache.org/jira/browse/CXF-1880.
+ */
+public class PropertyListenerPlugin extends Plugin {
+
+ org.apache.cxf.xjc.property_listener.PropertyListenerPlugin impl
+ = new org.apache.cxf.xjc.property_listener.PropertyListenerPlugin();
+
+ /* (non-Javadoc)
+ * @see com.sun.tools.xjc.Plugin#getOptionName()
+ */
+ @Override
+ public String getOptionName() {
+ return impl.getOptionName();
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.tools.xjc.Plugin#getUsage()
+ */
+ @Override
+ public String getUsage() {
+ return impl.getUsage();
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline,
+ * com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler)
+ */
+ @Override
+ public boolean run(Outline outline, Options opt, ErrorHandler
errorHandler) throws SAXException {
+ return impl.run(outline, opt, errorHandler);
+ }
+}
Propchange:
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/PropertyListenerPlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/xjc-utils/trunk/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/PropertyListenerPlugin.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties
URL:
http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties?rev=911586&view=auto
==============================================================================
---
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties
(added)
+++
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties
Thu Feb 18 21:08:01 2010
@@ -0,0 +1,20 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+#
Propchange:
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/PropertyListenerPlugin.java
URL:
http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/PropertyListenerPlugin.java?rev=911586&view=auto
==============================================================================
---
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/PropertyListenerPlugin.java
(added)
+++
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/PropertyListenerPlugin.java
Thu Feb 18 21:08:01 2010
@@ -0,0 +1,169 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.cxf.xjc.property_listener;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.List;
+import java.util.logging.Logger;
+
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.xml.sax.ErrorHandler;
+
+import com.sun.codemodel.JAssignment;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JExpression;
+import com.sun.codemodel.JFieldRef;
+import com.sun.codemodel.JFieldVar;
+import com.sun.codemodel.JMethod;
+import com.sun.codemodel.JType;
+import com.sun.codemodel.JVar;
+import com.sun.tools.xjc.Options;
+import com.sun.tools.xjc.outline.ClassOutline;
+import com.sun.tools.xjc.outline.Outline;
+
+/**
+ * Modifies the JAXB code model to add a PropertyChangeListener to the
+ * setter methods
+ */
+public class PropertyListenerPlugin {
+
+ private static final Logger LOG =
Logger.getLogger(PropertyListenerPlugin.class.getName()); //NOPMD
+
+ public PropertyListenerPlugin() {
+ }
+
+ public String getOptionName() {
+ return "Xproperty-listener";
+ }
+
+ public String getUsage() {
+ return " -Xproperty-listener : Adds a PropertyChangeListener to
all the set methods";
+ }
+
+
+ public boolean run(Outline outline, Options opt, ErrorHandler
errorHandler) {
+ LOG.fine("Running property-listener plugin.");
+ for (ClassOutline co : outline.getClasses()) {
+ if (co.getDeclaredFields().length == 0) {
+ continue;
+ }
+
+ //add listener support
+ JType listenerType =
co.parent().getCodeModel()._ref(PropertyChangeSupport.class);
+ JFieldVar newVar = co.implClass.field(Modifier.PRIVATE,
+ listenerType,
+ "propertyListener",
+
JExpr._new(listenerType).arg(JExpr._this()));
+ newVar.annotate(XmlTransient.class);
+
+ JMethod method = co.implClass.method(Modifier.PUBLIC, Void.TYPE,
"addPropertyChangeListener");
+ JVar listener = method.param(PropertyChangeListener.class,
"listener");
+ method.body().invoke(newVar,
"addPropertyChangeListener").arg(listener);
+
+ method = co.implClass.method(Modifier.PUBLIC, Void.TYPE,
"removePropertyChangeListener");
+ listener = method.param(PropertyChangeListener.class, "listener");
+ method.body().invoke(newVar,
"removePropertyChangeListener").arg(listener);
+
+ //add firePropertyChange to set methods
+ List<JMethod> methods = (List<JMethod>)co.implClass.methods();
+ for (int x = 0; x < methods.size(); x++) {
+ JMethod m = methods.get(x);
+ if (m.name().startsWith("set")) {
+ m.body().pos(0);
+ List<Object> contents = m.body().getContents();
+ JFieldRef target = null;
+ String targetName = null;
+ JExpression value = null;
+ for (Object o : contents) {
+ if (o instanceof JAssignment) {
+ JAssignment jass = (JAssignment)o;
+ try {
+ Field f =
jass.getClass().getDeclaredField("lhs");
+ f.setAccessible(true);
+ Object t = f.get(jass);
+ if (t instanceof JFieldRef) {
+ f =
jass.getClass().getDeclaredField("rhs");
+ f.setAccessible(true);
+ value = (JExpression)f.get(jass);
+ target = (JFieldRef)t;
+ }
+ } catch (Throwable t) {
+ //ignore
+ }
+ }
+ }
+ if (target != null) {
+ try {
+ targetName = getName(target);
+
+ JFieldVar field =
co.implClass.fields().get(targetName);
+
+ if (value instanceof JVar) {
+ JVar var = (JVar)value;
+ JType t = var.type();
+ if ("int".equals(t.fullName())
+ && !"int".equals(field.type().fullName()))
{
+ value =
JExpr.cast(co.parent().getCodeModel()._ref(Integer.class),
+ value);
+ } else if ("boolean".equals(t.fullName())
+ &&
!"boolean".equals(field.type().fullName())) {
+ value =
JExpr.cast(co.parent().getCodeModel()._ref(Boolean.class),
+ value);
+ }
+ }
+
+ m.body().invoke(newVar,
"firePropertyChange").arg(targetName)
+ .arg(target).arg(value);
+ } catch (Throwable t) {
+ //ignore
+ t.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+ }
+ return true;
+ }
+
+ String getName(JFieldRef ref) {
+ try {
+ Field f = ref.getClass().getDeclaredField("name");
+ f.setAccessible(true);
+ String targetName = (String)f.get(ref);
+ if (targetName == null) {
+ f = ref.getClass().getDeclaredField("var");
+ f.setAccessible(true);
+ JVar v = (JVar)f.get(ref);
+ targetName = v.name();
+ }
+ return targetName;
+ } catch (Throwable t) {
+ //ignore
+ }
+ return null;
+ }
+
+}
Propchange:
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/PropertyListenerPlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/xjc-utils/trunk/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/PropertyListenerPlugin.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/xjc-utils/trunk/property-listener/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin
URL:
http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/property-listener/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin?rev=911586&view=auto
==============================================================================
---
cxf/xjc-utils/trunk/property-listener/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin
(added)
+++
cxf/xjc-utils/trunk/property-listener/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin
Thu Feb 18 21:08:01 2010
@@ -0,0 +1 @@
+com.sun.tools.xjc.addon.apache_cxf.property_listener.PropertyListenerPlugin
\ No newline at end of file