Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,23 @@ private boolean ofTheSameType(final List<String> collisions) {
String typeString = null;
while (iterator.hasNext()) {
String xPath = iterator.next();
String newTypeString = xPath.substring(xPath.indexOf("[") + 1, xPath.indexOf("]"));
// fix StringIndexOutOfBoundException when the input does not have '[' or ']'(by jiangdequan)
String newTypeString = "";
int leftBracket = xPath.indexOf("[");
int rightBracket = xPath.indexOf("]");
if (leftBracket == rightBracket) {
newTypeString = xPath;
} else {
if (leftBracket != -1) {
leftBracket += 1;
} else {
leftBracket = 0;
}
if (rightBracket == -1) {
rightBracket = xPath.length();
}
newTypeString = xPath.substring(leftBracket, rightBracket);
}
if (typeString != null) {
if (!typeString.equals(newTypeString)) {
allSame = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public final class ExtendedBinding extends Binding {
* Prefix used to identify a model group.
*/
public static final String GROUP_ID = "group:";
/**
* Suffix used to identify a spacename.
*/
public static final String SPACENAME_SUFFIX = "}";

private static final short ATTRIBUTE = 10;
private static final short ELEMENT = 11;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ protected String calculateXPathPrefix(final String xpath) {
|| token.startsWith(ExtendedBinding.GROUP_ID)) {
token = token.substring(token.indexOf(":") + 1);
}

// remove some invalid identifiers,such as '}'.(by jiangdequan)
if (token.endsWith(ExtendedBinding.SPACENAME_SUFFIX)) {
token = token.substring(0, token.indexOf(ExtendedBinding.SPACENAME_SUFFIX));
}

prefix += _sourceGenerator.getJavaNaming().toJavaClassName(token);
}
return prefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.exolab.castor.builder.BuilderConfiguration;
import org.exolab.castor.builder.SGTypes;
import org.exolab.castor.builder.factory.XMLFieldHandlerFactory;
Expand Down Expand Up @@ -642,6 +642,10 @@ private static String classType(final JType jType) {
JPrimitiveType primitive = (JPrimitiveType) jType;
return primitive.getWrapperName() + ".TYPE";
}
// fix syntax error, such as 'java.util.Vector<java.lang.Object>.class'(by jiangdequan)
if (StringUtils.equals("java.util.Vector", jType.getName())) {
return "java.util.Vector.class";
}
return jType.toString() + ".class";
} // -- classType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ private boolean createExtraMethods(final CollectionInfo fieldInfo) {
private void createGetAsArrayMethod(final CollectionInfo fieldInfo, final JClass jClass,
final boolean useJava50, AnnotationBuilder[] annotationBuilders) {
JType baseType = fieldInfo.getContentType().getJType();
JType arrayType = new JArrayType(baseType, useJava50);
// fix sync error, such as 'new java.util.Vector<Object>[]...'(by jiangdequan)
String baseTypeName = baseType.toString();
boolean isVector = baseType.toString().startsWith("java.util.Vector<java.lang.Object>");
JType arrayType = null;
if (isVector) {
arrayType = baseType;
} else {
arrayType = new JArrayType(baseType, useJava50);
}
JMethod method =
new JMethod(fieldInfo.getReadMethodName(), arrayType, "this collection as an Array");

Expand All @@ -173,13 +181,17 @@ private void createGetAsArrayMethod(final CollectionInfo fieldInfo, final JClass
comment.appendComment("into the API call. This way we <i>know</i> that the Array ");
comment.appendComment("returned is of exactly the correct length.");

String baseTypeName = baseType.toString();
if (baseType.isArray()) {
sourceCode.add(arrayType.toString() + " array = new ");
sourceCode.append(baseTypeName.substring(0, baseTypeName.length() - 2) + "[0][];");
} else {
sourceCode.add(arrayType.toString() + " array = new ");
sourceCode.append(baseTypeName + "[0];");
if (isVector) {
sourceCode.add("java.util.Vector<java.lang.Object> array = new ");
sourceCode.append(baseTypeName + "();");
} else {
sourceCode.add(arrayType.toString() + " array = new ");
sourceCode.append(baseTypeName + "[0];");
}
}

sourceCode.add("return ");
Expand All @@ -189,7 +201,11 @@ private void createGetAsArrayMethod(final CollectionInfo fieldInfo, final JClass
sourceCode.add(arrayType.toString());
sourceCode.add(") ");
}
sourceCode.append("this." + fieldInfo.getName() + ".toArray(array);");
if (isVector) {
sourceCode.append("array;");
} else {
sourceCode.append("this." + fieldInfo.getName() + ".toArray(array);");
}
} else {
// For primitive types, we have to do this the hard way
sourceCode.add("int size = this.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public FieldInfo createFieldInfoForContent(final XMLBindingComponent component,
FieldInfo fInfo = null;
if (xsType.isCollection()) {
fInfo = this.getInfoFactory().createCollection(((XSListType) xsType).getContentType(),
fieldName, null, getJavaNaming(), useJava50);
fieldName, fieldName, getJavaNaming(), useJava50);
} else {
fInfo = this.getInfoFactory().createFieldInfo(xsType, fieldName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,18 @@ public boolean isCollection() {
* @return Source code for dealing with default values.
*/
public String createDefaultValueWithString(final String variableName) {
return " new " + getJType() + "(" + variableName + ")";
// fix syntax error, such as 'java.lang.Object(variableName)'(by jiangdequan)
String jTypeStr = getJType().toString();
if (jTypeStr.startsWith("java.util.List<java.lang.Object>")) {
return " new java.lang.Object[]{" + variableName + "}";
}
if(jTypeStr.startsWith("java.lang.String")) {
return variableName;
}
if (jTypeStr.startsWith("java.lang.Object")) {
return variableName;
}
return " new " + jTypeStr + "(" + variableName + ")";
}

/**
Expand Down
111 changes: 111 additions & 0 deletions demo-source-generate/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.io</groupId>
<artifactId>demo-source-generate</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo-source-generate</name>
<properties>
<castor.version>1.4.2-SNAPSHOT</castor.version>
</properties>
<dependencies>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-codegen</artifactId>
<version>${castor.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-core</artifactId>
<version>${castor.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-ddlgen</artifactId>
<version>1.3.3-rc1</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-jdo</artifactId>
<version>1.3.3-rc1</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-xml</artifactId>
<version>${castor.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-xml-schema</artifactId>
<version>${castor.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.0</version>
<!-- <configuration> <packaging>com.test.io.xml.dto.ndc.baggagelist</packaging> </configuration> -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-codegen</artifactId>
<version>${castor.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-core</artifactId>
<version>${castor.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-ddlgen</artifactId>
<version>1.3.3-rc1</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-jdo</artifactId>
<version>1.3.3-rc1</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-xml</artifactId>
<version>${castor.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-xml-schema</artifactId>
<version>${castor.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<targetPath>${project.basedir}/target/classes/otaxsd/ndc</targetPath>
<filtering>false</filtering>
<directory>${project.basedir}/src/main/castor</directory>
<includes>
<include>**/*.xsd</include>
</includes>
</resource>
</resources>
</build>
</project>
Loading