methods = classOutline.implClass.methods();
41 | for (JMethod method : methods) {
42 | if (method.name().equals(methodName)) {
43 | return method;
44 | }
45 | }
46 | return null;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/javadoc/src/main/java/org/apache/cxf/xjc/javadoc/PropertyJavadoc.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.cxf.xjc.javadoc;
20 |
21 | import com.sun.codemodel.JCodeModel;
22 | import com.sun.codemodel.JDocComment;
23 | import com.sun.codemodel.JFieldVar;
24 | import com.sun.codemodel.JMethod;
25 | import com.sun.codemodel.JType;
26 | import com.sun.tools.xjc.Options;
27 | import com.sun.tools.xjc.model.CPropertyInfo;
28 | import com.sun.tools.xjc.outline.ClassOutline;
29 | import com.sun.tools.xjc.outline.FieldOutline;
30 | import com.sun.xml.xsom.XSAttributeUse;
31 | import com.sun.xml.xsom.XSComponent;
32 | import com.sun.xml.xsom.XSParticle;
33 |
34 | public class PropertyJavadoc {
35 |
36 | private JCodeModel codeModel;
37 |
38 | private Options options;
39 |
40 | private ClassOutline classOutline;
41 |
42 | private FieldOutline fieldOutline;
43 |
44 | public PropertyJavadoc(JCodeModel codeModel, Options options, ClassOutline classOutline,
45 | FieldOutline fieldOutline) {
46 | this.codeModel = codeModel;
47 | this.options = options;
48 | this.classOutline = classOutline;
49 | this.fieldOutline = fieldOutline;
50 | }
51 |
52 | public void addJavadocs() {
53 | CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();
54 | if (propertyInfo == null) {
55 | return;
56 | }
57 | if (propertyInfo.javadoc.length() > 0) {
58 | return; // JAXB binding customization overwrites xsd:documentation
59 | }
60 | XSComponent component = getDocumentedComponent(propertyInfo);
61 |
62 | String documentation = XSComponentHelper.getDocumentation(component);
63 | if (documentation == null || "".equals(documentation.trim())) {
64 | return;
65 | }
66 | setJavadoc(documentation.trim());
67 | }
68 |
69 | private XSComponent getDocumentedComponent(CPropertyInfo propertyInfo) {
70 | XSComponent schemaComponent = propertyInfo.getSchemaComponent();
71 | if (schemaComponent instanceof XSParticle) {
72 | return ((XSParticle)schemaComponent).getTerm();
73 | } else if (schemaComponent instanceof XSAttributeUse) {
74 | return ((XSAttributeUse)schemaComponent).getDecl();
75 | } else {
76 | return null;
77 | }
78 | }
79 |
80 | private void setJavadoc(String documentation) {
81 | setJavadocToField(documentation);
82 | setJavadocToGetter(documentation);
83 | setSeeTagToSetter();
84 | }
85 |
86 | private void setJavadocToField(String documentation) {
87 | JFieldVar fieldVar = classOutline.implClass.fields().get(fieldOutline.getPropertyInfo()
88 | .getName(false));
89 | if (fieldVar == null) {
90 | return;
91 | }
92 | fieldVar.javadoc().append(documentation);
93 | }
94 |
95 | private void setJavadocToGetter(String documentation) {
96 | String getterMethod = getGetterMethod();
97 | JMethod getter = MethodHelper.findMethod(classOutline, getterMethod);
98 | JDocComment javadoc = getter.javadoc();
99 | if (javadoc.size() != 0) {
100 | documentation = "\n\n" + documentation;
101 | }
102 | javadoc.add(javadoc.size(), documentation); // add comment as last
103 | // non-tag element
104 | }
105 |
106 | private void setSeeTagToSetter() {
107 | JMethod setterMethod = MethodHelper.findMethod(classOutline, "set"
108 | + fieldOutline.getPropertyInfo()
109 | .getName(true));
110 | if (setterMethod == null) {
111 | return;
112 | }
113 | setterMethod.javadoc().addXdoclet("see #" + getGetterMethod() + "()");
114 | }
115 |
116 | private String getGetterMethod() {
117 | JType type = fieldOutline.getRawType();
118 | if (options.enableIntrospection) {
119 | return ((type.isPrimitive() && type.boxify().getPrimitiveType() == codeModel.BOOLEAN)
120 | ? "is" : "get") + fieldOutline.getPropertyInfo().getName(true);
121 | }
122 | return (type.boxify().getPrimitiveType() == codeModel.BOOLEAN ? "is" : "get")
123 | + fieldOutline.getPropertyInfo().getName(true);
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/javadoc/src/main/java/org/apache/cxf/xjc/javadoc/XSComponentHelper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.cxf.xjc.javadoc;
20 |
21 | import com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo;
22 | import com.sun.xml.xsom.XSAnnotation;
23 | import com.sun.xml.xsom.XSComponent;
24 |
25 | public final class XSComponentHelper {
26 |
27 | private XSComponentHelper() {
28 | // no constructor for utility class
29 | }
30 |
31 | public static String getDocumentation(XSComponent schemaComponent) {
32 | if (schemaComponent == null) {
33 | return null;
34 | }
35 | XSAnnotation xsAnnotation = schemaComponent.getAnnotation();
36 | if (xsAnnotation == null) {
37 | return null;
38 | }
39 | BindInfo annotation = (BindInfo)xsAnnotation.getAnnotation();
40 | if (annotation == null) {
41 | return null;
42 | }
43 | return annotation.getDocumentation();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/javadoc/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin:
--------------------------------------------------------------------------------
1 | org.apache.cxf.xjc.javadoc.JavadocPlugin
--------------------------------------------------------------------------------
/javadoc/src/test/java/org/apache/cxf/xjc/javadoc/JavadocTestHelper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.cxf.xjc.javadoc;
20 |
21 | import java.util.List;
22 |
23 | import org.eclipse.jdt.core.dom.Javadoc;
24 | import org.eclipse.jdt.core.dom.TagElement;
25 | import org.hamcrest.Description;
26 | import org.hamcrest.Matcher;
27 | import org.hamcrest.TypeSafeMatcher;
28 |
29 | /**
30 | * Utility methods for tests
31 | *
32 | * @author Dawid Pytel
33 | */
34 | public final class JavadocTestHelper {
35 | private JavadocTestHelper() {
36 | //utility class
37 | }
38 |
39 | public static Matcher javadocContains(final String comment) {
40 | return new TypeSafeMatcher(Javadoc.class) {
41 |
42 | @Override
43 | protected boolean matchesSafely(Javadoc javadoc) {
44 | if (!javadoc.tags().isEmpty()) {
45 | TagElement tagElement = (TagElement)javadoc.tags().get(0);
46 | List> fragments = tagElement.fragments();
47 | for (Object fragment : fragments) {
48 | if (fragment != null && fragment.toString().contains(comment)) {
49 | return true;
50 | }
51 | }
52 | }
53 | return false;
54 | }
55 |
56 | public void describeTo(Description description) {
57 | description.appendText("javadoc contains given comment: " + comment);
58 | }
59 | };
60 | }
61 |
62 | public static Matcher containsTag(final String tagName, final String tagValue) {
63 | return new TypeSafeMatcher(Javadoc.class) {
64 |
65 | @Override
66 | protected boolean matchesSafely(Javadoc javadoc) {
67 | @SuppressWarnings("unchecked")
68 | List tags = javadoc.tags();
69 | for (TagElement tagElement : tags) {
70 | if (tagName.equals(tagElement.getTagName())) {
71 | return tagValue.equals(tagElement.fragments().get(0).toString());
72 | }
73 | }
74 |
75 | return false;
76 | }
77 |
78 | public void describeTo(Description description) {
79 | description.appendText("javadoc contains tag " + tagName + " " + tagValue);
80 | }
81 | };
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/javadoc/src/test/resources/anonymousEnum-javadoc-bindings.xjb:
--------------------------------------------------------------------------------
1 |
19 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/javadoc/src/test/resources/anonymousEnum.xsd:
--------------------------------------------------------------------------------
1 |
2 |
20 |
22 |
23 |
24 |
25 |
26 | Documentation of anonymous enum simpleType
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/javadoc/src/test/resources/complexTypeWithDocumentedAttribute.xsd:
--------------------------------------------------------------------------------
1 |
2 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | Documentation of attribute
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/javadoc/src/test/resources/complexTypeWithDocumentedProperties-javadoc-bindings.xjb:
--------------------------------------------------------------------------------
1 |
19 |
25 |
26 |
27 | Documentation from JAXB binding customization
28 |
29 |
30 |
--------------------------------------------------------------------------------
/javadoc/src/test/resources/complexTypeWithDocumentedProperties.xsd:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | Some documentation of element
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/javadoc/src/test/resources/complexTypeWithoutProperties.xsd:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/javadoc/src/test/resources/enumDocumented-javadoc-bindings.xjb:
--------------------------------------------------------------------------------
1 |
19 |
25 |
26 |
27 | Documentation from JAXB binding customization
28 |
29 |
30 |
--------------------------------------------------------------------------------
/javadoc/src/test/resources/enumDocumented.xsd:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
23 | Documentation of enumDocumented
24 |
25 |
26 |
27 |
28 | Documentation of ONE
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/property-listener/pom.xml:
--------------------------------------------------------------------------------
1 |
19 |
20 | 4.0.0
21 | org.apache.cxf.xjcplugins
22 | cxf-xjc-pl
23 | jar
24 | Apache CXF XJC Property Listener Plugin
25 | https://cxf.apache.org
26 |
27 |
28 | org.apache.cxf.xjc-utils
29 | xjc-utils
30 | 4.1.1-SNAPSHOT
31 |
32 |
33 |
34 |
35 | org.glassfish.jaxb
36 | jaxb-xjc
37 | provided
38 |
39 |
40 | org.glassfish.jaxb
41 | jaxb-runtime
42 | provided
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/PropertyListenerPlugin.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package com.sun.tools.xjc.addon.apache_cxf.property_listener;
21 |
22 | import org.xml.sax.ErrorHandler;
23 | import org.xml.sax.SAXException;
24 |
25 | import com.sun.tools.xjc.Options;
26 | import com.sun.tools.xjc.Plugin;
27 | import com.sun.tools.xjc.outline.Outline;
28 |
29 | /**
30 | * Thin wrapper around the DefaultValuePlugin. This must be in the com.sun.tools.xjc.addon package
31 | * for it to work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880.
32 | */
33 | public class PropertyListenerPlugin extends Plugin {
34 |
35 | org.apache.cxf.xjc.property_listener.PropertyListenerPlugin impl
36 | = new org.apache.cxf.xjc.property_listener.PropertyListenerPlugin();
37 |
38 | /* (non-Javadoc)
39 | * @see com.sun.tools.xjc.Plugin#getOptionName()
40 | */
41 | @Override
42 | public String getOptionName() {
43 | return impl.getOptionName();
44 | }
45 |
46 | /* (non-Javadoc)
47 | * @see com.sun.tools.xjc.Plugin#getUsage()
48 | */
49 | @Override
50 | public String getUsage() {
51 | return impl.getUsage();
52 | }
53 |
54 | /* (non-Javadoc)
55 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline,
56 | * com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler)
57 | */
58 | @Override
59 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException {
60 | return impl.run(outline, opt, errorHandler);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties:
--------------------------------------------------------------------------------
1 | #
2 | #
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | #
20 | #
21 |
--------------------------------------------------------------------------------
/property-listener/src/main/java/org/apache/cxf/xjc/property_listener/PropertyListenerPlugin.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package org.apache.cxf.xjc.property_listener;
21 |
22 | import java.beans.PropertyChangeListener;
23 | import java.beans.PropertyChangeSupport;
24 | import java.lang.reflect.Field;
25 | import java.lang.reflect.Modifier;
26 | import java.util.List;
27 | import java.util.logging.Logger;
28 |
29 |
30 | import org.xml.sax.ErrorHandler;
31 |
32 | import com.sun.codemodel.JAssignment;
33 | import com.sun.codemodel.JExpr;
34 | import com.sun.codemodel.JExpression;
35 | import com.sun.codemodel.JFieldRef;
36 | import com.sun.codemodel.JFieldVar;
37 | import com.sun.codemodel.JMethod;
38 | import com.sun.codemodel.JType;
39 | import com.sun.codemodel.JVar;
40 | import com.sun.tools.xjc.Options;
41 | import com.sun.tools.xjc.outline.ClassOutline;
42 | import com.sun.tools.xjc.outline.Outline;
43 |
44 | import jakarta.xml.bind.annotation.XmlTransient;
45 |
46 | /**
47 | * Modifies the JAXB code model to add a PropertyChangeListener to the
48 | * setter methods
49 | */
50 | public class PropertyListenerPlugin {
51 |
52 | private static final Logger LOG = Logger.getLogger(PropertyListenerPlugin.class.getName()); //NOPMD
53 |
54 | public PropertyListenerPlugin() {
55 | }
56 |
57 | public String getOptionName() {
58 | return "Xproperty-listener";
59 | }
60 |
61 | public String getUsage() {
62 | return " -Xproperty-listener : Adds a PropertyChangeListener to all the set methods";
63 | }
64 |
65 |
66 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
67 | LOG.fine("Running property-listener plugin.");
68 | for (ClassOutline co : outline.getClasses()) {
69 | if (co.getDeclaredFields().length == 0) {
70 | continue;
71 | }
72 |
73 | //add listener support
74 | JType listenerType = co.parent().getCodeModel()._ref(PropertyChangeSupport.class);
75 | JFieldVar newVar = co.implClass.field(Modifier.PRIVATE,
76 | listenerType,
77 | "propertyListener",
78 | JExpr._new(listenerType).arg(JExpr._this()));
79 | newVar.annotate(XmlTransient.class);
80 |
81 | JMethod method = co.implClass.method(Modifier.PUBLIC, Void.TYPE, "addPropertyChangeListener");
82 | JVar listener = method.param(PropertyChangeListener.class, "listener");
83 | method.body().invoke(newVar, "addPropertyChangeListener").arg(listener);
84 |
85 | method = co.implClass.method(Modifier.PUBLIC, Void.TYPE, "removePropertyChangeListener");
86 | listener = method.param(PropertyChangeListener.class, "listener");
87 | method.body().invoke(newVar, "removePropertyChangeListener").arg(listener);
88 |
89 | //add firePropertyChange to set methods
90 | List methods = (List)co.implClass.methods();
91 | for (int x = 0; x < methods.size(); x++) {
92 | JMethod m = methods.get(x);
93 | if (m.name().startsWith("set")) {
94 | m.body().pos(0);
95 | List