forked from highsource/jaxb-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[highsource#460] take back plugins from org.andromda.thirdparty.jaxb2…
…_commons groupId
- Loading branch information
1 parent
8285be6
commit 945011d
Showing
34 changed files
with
1,515 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
jaxb-plugins-parent/jaxb-plugins-runtime/src/main/java/org/jvnet/jaxb/lang/Child.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.jvnet.jaxb.lang; | ||
|
||
public interface Child { | ||
Object getParent(); | ||
|
||
void setParent(Object parent); | ||
} |
49 changes: 49 additions & 0 deletions
49
...-parent/jaxb-plugins/src/main/java/org/jvnet/jaxb/plugin/booleangetter/BooleanGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.jvnet.jaxb.plugin.booleangetter; | ||
|
||
import com.sun.codemodel.JMethod; | ||
import com.sun.tools.xjc.Options; | ||
import com.sun.tools.xjc.Plugin; | ||
import com.sun.tools.xjc.outline.ClassOutline; | ||
import com.sun.tools.xjc.outline.Outline; | ||
import org.xml.sax.ErrorHandler; | ||
import org.xml.sax.SAXException; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* XJC plugin to generate getXX functions instead of isXX functions for boolean values. | ||
* The motivation is to make using XJC generated classes easier to use with Spring, since | ||
* Spring expects accessors to be called getXX. | ||
* | ||
* @author Adam Burnett | ||
* | ||
* This plugin came from here : org.andromda.thirdparty.jaxb2_commons:booleangetter:1.0 | ||
*/ | ||
public class BooleanGetter extends Plugin { | ||
|
||
protected final String OPTION_NAME = "Xboolean-getter"; | ||
|
||
@Override | ||
public String getOptionName() { | ||
return OPTION_NAME; | ||
} | ||
|
||
@Override | ||
public String getUsage() { | ||
return "-" + OPTION_NAME + " : Generate getXX instead of isXX functions for boolean values\n"; | ||
} | ||
|
||
@Override | ||
public boolean run(Outline model, Options opts, ErrorHandler errors) throws SAXException { | ||
for (ClassOutline co : model.getClasses()) { | ||
Collection<JMethod> methods = co.implClass.methods(); | ||
// pretty simple, just look at all our generated methods and rename isXX to getXX | ||
for (JMethod m : methods) { | ||
if (m.name().startsWith("is")) { | ||
m.name("get" + m.name().substring("is".length())); | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...nt/jaxb-plugins/src/main/java/org/jvnet/jaxb/plugin/camelcase/CamelCaseNameConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.jvnet.jaxb.plugin.camelcase; | ||
|
||
import org.glassfish.jaxb.core.api.impl.NameConverter; | ||
|
||
/** | ||
* Name converter that unconditionally converts to camel case. | ||
*/ | ||
class CamelCaseNameConverter extends NameConverter.Standard { | ||
|
||
/** | ||
* Changes the first character of the specified string to uppercase, | ||
* and the rest of characters to lowercase. | ||
* | ||
* @param | ||
* s string to capitalize | ||
* | ||
* @return | ||
* capitalized string | ||
*/ | ||
@Override | ||
public String capitalize(String s) { | ||
StringBuilder sb = new StringBuilder(s.length()); | ||
sb.append(Character.toUpperCase(s.charAt(0))); | ||
sb.append(s.substring(1).toLowerCase()); | ||
return sb.toString(); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...ns-parent/jaxb-plugins/src/main/java/org/jvnet/jaxb/plugin/camelcase/CamelCasePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.jvnet.jaxb.plugin.camelcase; | ||
|
||
import com.sun.tools.xjc.BadCommandLineException; | ||
import com.sun.tools.xjc.Options; | ||
import com.sun.tools.xjc.Plugin; | ||
import com.sun.tools.xjc.outline.Outline; | ||
import org.xml.sax.ErrorHandler; | ||
|
||
/** | ||
* {@link Plugin} that always converts an XML name into a camel case java name. | ||
* This plugin changes the first character of every word composing an XML name | ||
* to uppercase and the others to lowercase, while the default XJC behavior is | ||
* to do so only if the first character of the word is lowercase. | ||
* <pre> | ||
* | ||
* XJC default: | ||
* FIRST_NAME -> FIRSTNAME | ||
* FOOBar -> FOOBar | ||
* SSNCode -> SSNCode | ||
* | ||
* Camel case always: | ||
* FIRST_NAME -> FirstName | ||
* FOOBar -> FooBar | ||
* SSNCode -> SsnCode | ||
* | ||
* </pre> | ||
* | ||
* @author Nicola Fagnani | ||
* | ||
* This plugin came from here : org.andromda.thirdparty.jaxb2_commons:camelcase-always:1.0 | ||
*/ | ||
public class CamelCasePlugin extends Plugin { | ||
|
||
/** Constant for the option string. */ | ||
protected final String OPTION_NAME = "Xcamelcase"; | ||
|
||
/** | ||
* Returns the option string used to turn on this plugin. | ||
* | ||
* @return | ||
* option string to invoke this plugin | ||
*/ | ||
@Override | ||
public String getOptionName() { | ||
return OPTION_NAME; | ||
} | ||
|
||
/** | ||
* Returns a string specifying how to use this plugin and what it does. | ||
* | ||
* @return | ||
* string containing the plugin usage message | ||
*/ | ||
@Override | ||
public String getUsage() { | ||
return " -" + OPTION_NAME + | ||
" : converts every XML name to camel case"; | ||
} | ||
|
||
/** | ||
* On plugin activation, sets a customized NameConverter to adjust code | ||
* generation. | ||
* | ||
* @param opts | ||
* options used to invoke XJC | ||
* | ||
* @throws com.sun.tools.xjc.BadCommandLineException | ||
* if the plugin is invoked with wrong parameters | ||
*/ | ||
@Override | ||
public void onActivated(Options opts) throws BadCommandLineException { | ||
opts.setNameConverter( new CamelCaseNameConverter(), this ); | ||
} | ||
|
||
/** | ||
* Returns true without touching the generated code. All the relevant | ||
* work is done during name conversion. | ||
* | ||
* @param model | ||
* This object allows access to various generated code. | ||
* | ||
* @param opts | ||
* options used to invoke XJC | ||
* @param errorHandler | ||
* Errors should be reported to this handler. | ||
* | ||
* @return | ||
* If the add-on executes successfully, return true. | ||
* If it detects some errors but those are reported and | ||
* recovered gracefully, return false. | ||
*/ | ||
@Override | ||
public boolean run(Outline model, Options opts, ErrorHandler errorHandler ) { | ||
return true; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...ins-parent/jaxb-plugins/src/main/java/org/jvnet/jaxb/plugin/elementwrapper/Candidate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.jvnet.jaxb.plugin.elementwrapper; | ||
|
||
import com.sun.codemodel.JDefinedClass; | ||
import com.sun.codemodel.JFieldVar; | ||
import com.sun.tools.xjc.model.CClassInfo; | ||
import com.sun.tools.xjc.model.CPropertyInfo; | ||
import com.sun.tools.xjc.model.CTypeInfo; | ||
|
||
/** | ||
* @author bjh | ||
*/ | ||
class Candidate { | ||
protected CClassInfo classInfo; | ||
protected CPropertyInfo propertyInfo; | ||
protected CTypeInfo propertyTypeInfo; | ||
|
||
protected JDefinedClass implClass; | ||
protected JFieldVar field; | ||
protected String wrappedSchemaTypeName = null; | ||
|
||
public Candidate(CClassInfo classInfo) { | ||
this.classInfo = classInfo; | ||
this.propertyInfo = classInfo.getProperties().get(0); | ||
this.propertyTypeInfo = propertyInfo.ref().iterator().next(); | ||
this.wrappedSchemaTypeName = XmlElementWrapperPlugin.elementName(propertyInfo); | ||
} | ||
|
||
public CClassInfo getClassInfo() { | ||
return classInfo; | ||
} | ||
|
||
public CPropertyInfo getPropertyInfo() { | ||
return propertyInfo; | ||
} | ||
|
||
public CTypeInfo getPropertyTypeInfo() { | ||
return propertyTypeInfo; | ||
} | ||
|
||
public String getClassName() { | ||
return classInfo.fullName(); | ||
} | ||
|
||
public String getFieldName() { | ||
return getPropertyInfo().getName(false); | ||
} | ||
|
||
public String getFieldTypeName() { | ||
return propertyTypeInfo.getType().fullName(); | ||
} | ||
|
||
public String getWrappedSchemaTypeName() { | ||
return wrappedSchemaTypeName; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...parent/jaxb-plugins/src/main/java/org/jvnet/jaxb/plugin/elementwrapper/Instantiation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.jvnet.jaxb.plugin.elementwrapper; | ||
|
||
enum Instantiation { | ||
EARLY, LAZY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.