Skip to content

Commit c3488a9

Browse files
[#460] take back plugins from org.andromda.thirdparty.jaxb2_commons groupId
1 parent 2f082dc commit c3488a9

File tree

34 files changed

+1522
-3
lines changed

34 files changed

+1522
-3
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,13 @@ JAXB2 Basics can only be used with JAXB/XJC 2.3.x. JAXB/XJC versions 2.2.x and e
137137
* [Commons Lang Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB2-Commons-Lang-Plugin) - generates the `toString()`, `hashCode()` and `equals()` methods using Apache commons-lang3.
138138
* [Default Value Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB2-Default-Value-Plugin) - modifies the JAXB code model to set default values to the schema `default` attribute.
139139
* [Fluent API Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB2-Fluent-API-Plugin) - support a fluent api in addition to the default (JavaBean) setter methods.
140-
* [Namespace Prefix Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB2-Namespace-Prefix-Plugin) - adds `javax.xml.bind.annotation.XmlNs` annotations to `package-info.java` files
140+
* [Namespace Prefix Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB2-Namespace-Prefix-Plugin) - adds `jakarta.xml.bind.annotation.XmlNs` annotations to `package-info.java` files
141141
* [Value Constructor Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB2-Value-Constructor-Plugin) - generates another constructor, taking an argument for each field in the class and initialises the field with the argument value.
142+
* [Boolean Getter Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB-Boolean-Getter-Plugin) - generates getters for boolean property in `getXXX` instead of `isXXX`.
143+
* [CamelCase Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB-CamelCase-Plugin) - modifies the classes name generated by XJC to always be in CamelCase.
144+
* [Xml ElementWrapper Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB-XML-ElementWrapper-Plugin) - generates `jakarta.xml.bind.annotation.XmlElementWrapper` annotation to simplify generated structure.
145+
* [Parent Pointer Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB-Parent-Pointer-Plugin) - generates getter in child elements to get the parent object (depends on `jaxb-plugins-runtime`)
146+
* [Property Listener Injector Plugin](https://github.com/highsource/jaxb-tools/wiki/JAXB-Property-Listener-Injector-Plugin) - adds methods in order to configure the generation of events on each `setXXX` method
142147

143148
## Credits
144149

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.jvnet.jaxb2_commons.plugin.booleangetter;
2+
3+
import com.sun.codemodel.JMethod;
4+
import com.sun.tools.xjc.Options;
5+
import com.sun.tools.xjc.Plugin;
6+
import com.sun.tools.xjc.outline.ClassOutline;
7+
import com.sun.tools.xjc.outline.Outline;
8+
import org.xml.sax.ErrorHandler;
9+
import org.xml.sax.SAXException;
10+
11+
import java.util.Collection;
12+
13+
/**
14+
* XJC plugin to generate getXX functions instead of isXX functions for boolean values.
15+
* The motivation is to make using XJC generated classes easier to use with Spring, since
16+
* Spring expects accessors to be called getXX.
17+
*
18+
* @author Adam Burnett
19+
*
20+
* This plugin came from here : org.andromda.thirdparty.jaxb2_commons:booleangetter:1.0
21+
*/
22+
public class BooleanGetter extends Plugin {
23+
24+
protected final String OPTION_NAME = "Xboolean-getter";
25+
26+
@Override
27+
public String getOptionName() {
28+
return OPTION_NAME;
29+
}
30+
31+
@Override
32+
public String getUsage() {
33+
return "-" + OPTION_NAME + " : Generate getXX instead of isXX functions for boolean values\n";
34+
}
35+
36+
@Override
37+
public boolean run(Outline model, Options opts, ErrorHandler errors) throws SAXException {
38+
for (ClassOutline co : model.getClasses()) {
39+
Collection<JMethod> methods = co.implClass.methods();
40+
// pretty simple, just look at all our generated methods and rename isXX to getXX
41+
for (JMethod m : methods) {
42+
if (m.name().startsWith("is")) {
43+
m.name("get" + m.name().substring("is".length()));
44+
}
45+
}
46+
}
47+
return true;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.jvnet.jaxb2_commons.plugin.camelcase;
2+
3+
import com.sun.xml.bind.api.impl.NameConverter;
4+
5+
/**
6+
* Name converter that unconditionally converts to camel case.
7+
*/
8+
class CamelCaseNameConverter extends NameConverter.Standard {
9+
10+
/**
11+
* Changes the first character of the specified string to uppercase,
12+
* and the rest of characters to lowercase.
13+
*
14+
* @param
15+
* s string to capitalize
16+
*
17+
* @return
18+
* capitalized string
19+
*/
20+
@Override
21+
public String capitalize(String s) {
22+
StringBuilder sb = new StringBuilder(s.length());
23+
sb.append(Character.toUpperCase(s.charAt(0)));
24+
sb.append(s.substring(1).toLowerCase());
25+
return sb.toString();
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package org.jvnet.jaxb2_commons.plugin.camelcase;
2+
3+
import com.sun.tools.xjc.BadCommandLineException;
4+
import com.sun.tools.xjc.Options;
5+
import com.sun.tools.xjc.Plugin;
6+
import com.sun.tools.xjc.outline.Outline;
7+
import org.xml.sax.ErrorHandler;
8+
9+
/**
10+
* {@link Plugin} that always converts an XML name into a camel case java name.
11+
* This plugin changes the first character of every word composing an XML name
12+
* to uppercase and the others to lowercase, while the default XJC behavior is
13+
* to do so only if the first character of the word is lowercase.
14+
* <pre>
15+
*
16+
* XJC default:
17+
* FIRST_NAME -&gt; FIRSTNAME
18+
* FOOBar -&gt; FOOBar
19+
* SSNCode -&gt; SSNCode
20+
*
21+
* Camel case always:
22+
* FIRST_NAME -&gt; FirstName
23+
* FOOBar -&gt; FooBar
24+
* SSNCode -&gt; SsnCode
25+
*
26+
* </pre>
27+
*
28+
* @author Nicola Fagnani
29+
*
30+
* This plugin came from here : org.andromda.thirdparty.jaxb2_commons:camelcase-always:1.0
31+
*/
32+
public class CamelCasePlugin extends Plugin {
33+
34+
/** Constant for the option string. */
35+
protected final String OPTION_NAME = "Xcamelcase";
36+
37+
/**
38+
* Returns the option string used to turn on this plugin.
39+
*
40+
* @return
41+
* option string to invoke this plugin
42+
*/
43+
@Override
44+
public String getOptionName() {
45+
return OPTION_NAME;
46+
}
47+
48+
/**
49+
* Returns a string specifying how to use this plugin and what it does.
50+
*
51+
* @return
52+
* string containing the plugin usage message
53+
*/
54+
@Override
55+
public String getUsage() {
56+
return " -" + OPTION_NAME +
57+
" : converts every XML name to camel case";
58+
}
59+
60+
/**
61+
* On plugin activation, sets a customized NameConverter to adjust code
62+
* generation.
63+
*
64+
* @param opts
65+
* options used to invoke XJC
66+
*
67+
* @throws com.sun.tools.xjc.BadCommandLineException
68+
* if the plugin is invoked with wrong parameters
69+
*/
70+
@Override
71+
public void onActivated(Options opts) throws BadCommandLineException {
72+
opts.setNameConverter( new CamelCaseNameConverter(), this );
73+
}
74+
75+
/**
76+
* Returns true without touching the generated code. All the relevant
77+
* work is done during name conversion.
78+
*
79+
* @param model
80+
* This object allows access to various generated code.
81+
*
82+
* @param opts
83+
* options used to invoke XJC
84+
85+
* @param errorHandler
86+
* Errors should be reported to this handler.
87+
*
88+
* @return
89+
* If the add-on executes successfully, return true.
90+
* If it detects some errors but those are reported and
91+
* recovered gracefully, return false.
92+
*/
93+
@Override
94+
public boolean run(Outline model, Options opts, ErrorHandler errorHandler ) {
95+
return true;
96+
}
97+
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.jvnet.jaxb2_commons.plugin.elementwrapper;
2+
3+
import com.sun.codemodel.JDefinedClass;
4+
import com.sun.codemodel.JFieldVar;
5+
import com.sun.tools.xjc.model.CClassInfo;
6+
import com.sun.tools.xjc.model.CPropertyInfo;
7+
import com.sun.tools.xjc.model.CTypeInfo;
8+
9+
/**
10+
* @author bjh
11+
*/
12+
class Candidate {
13+
protected CClassInfo classInfo;
14+
protected CPropertyInfo propertyInfo;
15+
protected CTypeInfo propertyTypeInfo;
16+
17+
protected JDefinedClass implClass;
18+
protected JFieldVar field;
19+
protected String wrappedSchemaTypeName = null;
20+
21+
public Candidate(CClassInfo classInfo) {
22+
this.classInfo = classInfo;
23+
this.propertyInfo = classInfo.getProperties().get(0);
24+
this.propertyTypeInfo = propertyInfo.ref().iterator().next();
25+
this.wrappedSchemaTypeName = XmlElementWrapperPlugin.elementName(propertyInfo);
26+
}
27+
28+
public CClassInfo getClassInfo() {
29+
return classInfo;
30+
}
31+
32+
public CPropertyInfo getPropertyInfo() {
33+
return propertyInfo;
34+
}
35+
36+
public CTypeInfo getPropertyTypeInfo() {
37+
return propertyTypeInfo;
38+
}
39+
40+
public String getClassName() {
41+
return classInfo.fullName();
42+
}
43+
44+
public String getFieldName() {
45+
return getPropertyInfo().getName(false);
46+
}
47+
48+
public String getFieldTypeName() {
49+
return propertyTypeInfo.getType().fullName();
50+
}
51+
52+
public String getWrappedSchemaTypeName() {
53+
return wrappedSchemaTypeName;
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.jvnet.jaxb2_commons.plugin.elementwrapper;
2+
3+
enum Instantiation {
4+
EARLY, LAZY
5+
}

basics/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/elementwrapper/ElementWrapperPlugin.java basics/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/elementwrapper/OldElementWrapperPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import com.sun.tools.xjc.model.nav.NClass;
3131
import com.sun.tools.xjc.model.nav.NType;
3232

33-
public class ElementWrapperPlugin extends AbstractModelPlugin {
33+
public class OldElementWrapperPlugin extends AbstractModelPlugin {
3434

3535
@Override
3636
public String getOptionName() {

0 commit comments

Comments
 (0)