-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b0bbac
commit 828f231
Showing
16 changed files
with
379 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
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,2 @@ | ||
.settings | ||
.project |
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,4 @@ | ||
.settings | ||
.project | ||
.classpath | ||
target |
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,38 @@ | ||
<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> | ||
<parent> | ||
<groupId>org.jvnet.jaxb2_commons</groupId> | ||
<artifactId>jaxb2-basics-test-superclass</artifactId> | ||
<version>0.10.1-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>jaxb2-basics-test-superclass-a</artifactId> | ||
<packaging>jar</packaging> | ||
<name>JAXB2 Basics - Test [superclass-a]</name> | ||
<build> | ||
<defaultGoal>test</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jvnet.jaxb2.maven2</groupId> | ||
<artifactId>maven-jaxb2-plugin</artifactId> | ||
<configuration> | ||
<extension>true</extension> | ||
<args> | ||
<arg>-XtoString</arg> | ||
<arg>-Xequals</arg> | ||
<arg>-XhashCode</arg> | ||
<arg>-Xcopyable</arg> | ||
<arg>-Xmergeable</arg> | ||
</args> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jvnet.jaxb2_commons</groupId> | ||
<artifactId>jaxb2-basics</artifactId> | ||
</plugin> | ||
</plugins> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,11 @@ | ||
<xsd:schema | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
targetNamespace="a" | ||
xmlns:a="a" | ||
elementFormDefault="qualified"> | ||
|
||
<xsd:complexType name="AbstractObject"> | ||
<xsd:attribute name="id" type="xsd:string" use="optional"/> | ||
</xsd:complexType> | ||
|
||
</xsd:schema> |
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,15 @@ | ||
<jaxb:bindings | ||
version="1.0" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations" | ||
jaxb:extensionBindingPrefixes="xjc" | ||
xmlns:a="a"> | ||
|
||
<jaxb:bindings scd="x-schema::a"> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="org.jvnet.jaxb2_commons.test.superclass.a"/> | ||
</jaxb:schemaBindings> | ||
</jaxb:bindings> | ||
</jaxb:bindings> |
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,4 @@ | ||
.settings | ||
.project | ||
.classpath | ||
target |
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,61 @@ | ||
<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> | ||
<parent> | ||
<groupId>org.jvnet.jaxb2_commons</groupId> | ||
<artifactId>jaxb2-basics-test-superclass</artifactId> | ||
<version>0.10.1-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>jaxb2-basics-test-superclass-b</artifactId> | ||
<packaging>jar</packaging> | ||
<name>JAXB2 Basics - Test [superclass-b]</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jvnet.jaxb2_commons</groupId> | ||
<artifactId>jaxb2-basics-test-superclass-a</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jvnet.jaxb2_commons</groupId> | ||
<artifactId>jaxb2-basics</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jvnet.jaxb2.maven2</groupId> | ||
<artifactId>maven-jaxb2-plugin-testing</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<defaultGoal>test</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jvnet.jaxb2.maven2</groupId> | ||
<artifactId>maven-jaxb2-plugin</artifactId> | ||
<configuration> | ||
<extension>true</extension> | ||
<args> | ||
<arg>-XtoString</arg> | ||
<arg>-Xequals</arg> | ||
<arg>-XhashCode</arg> | ||
<arg>-Xcopyable</arg> | ||
<arg>-Xmergeable</arg> | ||
</args> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jvnet.jaxb2_commons</groupId> | ||
<artifactId>jaxb2-basics</artifactId> | ||
</plugin> | ||
</plugins> | ||
<episodes> | ||
<episode> | ||
<groupId>org.jvnet.jaxb2_commons</groupId> | ||
<artifactId>jaxb2-basics-test-superclass-a</artifactId> | ||
</episode> | ||
</episodes> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,32 @@ | ||
<jaxb:bindings | ||
version="1.0" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations" | ||
jaxb:extensionBindingPrefixes="xjc" | ||
xmlns:b="b"> | ||
|
||
<jaxb:globalBindings> | ||
<xjc:superClass name="org.jvnet.jaxb2_commons.test.superclass.a.AbstractObject"/> | ||
</jaxb:globalBindings> | ||
|
||
<jaxb:bindings scd="x-schema::b"> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="org.jvnet.jaxb2_commons.test.superclass.b"/> | ||
</jaxb:schemaBindings> | ||
</jaxb:bindings> | ||
|
||
<!--jaxb:bindings scd="x-schema::a"> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="org.jvnet.hyperjaxb3.ejb.tests.episodes.a.tests"/> | ||
</jaxb:schemaBindings> | ||
<jaxb:bindings scd="~a:AType"> | ||
<jaxb:class ref="org.jvnet.hyperjaxb3.ejb.tests.episodes.a.tests.AType"/> | ||
</jaxb:bindings> | ||
<jaxb:bindings scd="~a:A1Type"> | ||
<jaxb:class ref="org.jvnet.hyperjaxb3.ejb.tests.episodes.a.tests.A1Type"/> | ||
</jaxb:bindings> | ||
</jaxb:bindings--> | ||
|
||
</jaxb:bindings> |
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,15 @@ | ||
<xsd:schema | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
targetNamespace="b" | ||
xmlns:b="b" | ||
elementFormDefault="qualified"> | ||
|
||
<xsd:element name="AnotherObject" type="b:AnotherObjectType"/> | ||
|
||
<xsd:complexType name="AnotherObjectType"> | ||
<xsd:sequence> | ||
<xsd:element name="data" type="xsd:string"/> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
|
||
</xsd:schema> |
20 changes: 20 additions & 0 deletions
20
...uperclass/b/src/test/java/org/jvnet/jaxb2_commons/test/superclass/b/tests/CopyToTest.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,20 @@ | ||
package org.jvnet.jaxb2_commons.test.superclass.b.tests; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.jvnet.jaxb2_commons.test.superclass.b.AnotherObjectType; | ||
|
||
public class CopyToTest { | ||
|
||
@Test | ||
public void correctlyCopies() { | ||
final AnotherObjectType source = new AnotherObjectType(); | ||
source.setId("Id"); | ||
source.setData("Data"); | ||
final AnotherObjectType target = (AnotherObjectType) source.clone(); | ||
Assert.assertEquals("Id", target.getId()); | ||
Assert.assertEquals("Data", target.getData()); | ||
Assert.assertEquals(source, target); | ||
Assert.assertEquals(source.hashCode(), target.hashCode()); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...uperclass/b/src/test/java/org/jvnet/jaxb2_commons/test/superclass/b/tests/RunPlugins.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,42 @@ | ||
package org.jvnet.jaxb2_commons.test.superclass.b.tests; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.sun.codemodel.JCodeModel; | ||
import com.sun.tools.xjc.ConsoleErrorReporter; | ||
import com.sun.tools.xjc.ModelLoader; | ||
import com.sun.tools.xjc.Options; | ||
import com.sun.tools.xjc.model.Model; | ||
|
||
public class RunPlugins { | ||
|
||
@Before | ||
public void setUp() { | ||
System.setProperty("javax.xml.accessExternalSchema", "all"); | ||
} | ||
|
||
@Test | ||
public void compilesSchema() throws Exception { | ||
|
||
new File("target/generated-sources/xjc").mkdirs(); | ||
|
||
URL schema = getClass().getResource("/schema.xsd"); | ||
URL binding = getClass().getResource("/binding.xjb"); | ||
final String[] arguments = new String[] { "-xmlschema", | ||
schema.toExternalForm(), "-b", binding.toExternalForm(), "-d", | ||
"target/generated-sources/xjc", "-extension", "-XtoString", | ||
"-Xequals", "-XhashCode", "-Xcopyable", "-Xmergeable" }; | ||
|
||
Options options = new Options(); | ||
options.parseArguments(arguments); | ||
ConsoleErrorReporter receiver = new ConsoleErrorReporter(); | ||
Model model = ModelLoader.load(options, new JCodeModel(), receiver); | ||
model.generateCode(options, receiver); | ||
com.sun.codemodel.CodeWriter cw = options.createCodeWriter(); | ||
model.codeModel.build(cw); | ||
} | ||
} |
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,8 @@ | ||
<b xmlns:a="a" xmlns="b"> | ||
<a:a> | ||
<a:a1>test</a:a1> | ||
</a:a> | ||
<b> | ||
<b1>test</b1> | ||
</b> | ||
</b> |
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,20 @@ | ||
<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> | ||
<parent> | ||
<groupId>org.jvnet.jaxb2_commons</groupId> | ||
<artifactId>jaxb2-basics-tests</artifactId> | ||
<version>0.10.1-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>jaxb2-basics-test-superclass</artifactId> | ||
<packaging>pom</packaging> | ||
<name>JAXB2 Basics - Test [superclass]</name> | ||
<modules> | ||
<module>a</module> | ||
<module>b</module> | ||
</modules> | ||
<build> | ||
<defaultGoal>test</defaultGoal> | ||
</build> | ||
</project> |
45 changes: 45 additions & 0 deletions
45
tools/src/main/java/org/jvnet/jaxb2_commons/util/JClassUtils.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,45 @@ | ||
package org.jvnet.jaxb2_commons.util; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.apache.commons.lang3.Validate; | ||
|
||
import com.sun.codemodel.JClass; | ||
|
||
public class JClassUtils { | ||
|
||
public static <T> boolean isInstanceOf(JClass _class, | ||
Class<? extends T> _interface) { | ||
Validate.notNull(_class); | ||
Validate.notNull(_interface); | ||
|
||
final String className = _class.fullName(); | ||
|
||
try { | ||
if (_interface.isAssignableFrom(Class.forName(className))) { | ||
return true; | ||
} | ||
} catch (ClassNotFoundException cnfex) { | ||
// Unknown | ||
} | ||
|
||
final JClass superClass = _class._extends(); | ||
if (superClass != null) { | ||
if (isInstanceOf(superClass, _interface)) { | ||
return true; | ||
} | ||
} | ||
|
||
for (final Iterator<? extends JClass> implementsIterator = _class | ||
._implements(); implementsIterator.hasNext();) { | ||
final JClass superInterface = implementsIterator.next(); | ||
|
||
if (isInstanceOf(superInterface, _interface)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.