Skip to content

Commit 5f4ca8f

Browse files
committed
Issue #4.
1 parent 6e221a3 commit 5f4ca8f

File tree

6 files changed

+67
-5
lines changed

6 files changed

+67
-5
lines changed

basic/src/main/java/org/jvnet/jaxb2_commons/plugin/simplify/SimplifyPlugin.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ private void simplifyReferencePropertyInfoAsReferencePropertyInfo(
161161
model, property, element);
162162
classInfo.getProperties().add(index++, referencePropertyInfo);
163163
}
164+
if (property.isMixed()) {
165+
classInfo.getProperties().add(index++,
166+
createContentReferencePropertyInfo(model, property));
167+
}
164168
classInfo.getProperties().remove(property);
165169
}
166170

@@ -192,6 +196,10 @@ private void simplifyReferencePropertyInfoAsElementPropertyInfo(
192196
classInfo.getProperties().add(index++, elementPropertyInfo);
193197
}
194198
}
199+
if (property.isMixed()) {
200+
classInfo.getProperties().add(index++,
201+
createContentReferencePropertyInfo(model, property));
202+
}
195203
classInfo.getProperties().remove(property);
196204
}
197205

@@ -242,14 +250,24 @@ private CReferencePropertyInfo createReferencePropertyInfo(
242250
final Model model, CReferencePropertyInfo property, CElement element) {
243251
final String propertyName = createPropertyName(model, element);
244252
final CReferencePropertyInfo referencePropertyInfo = new CReferencePropertyInfo(
245-
propertyName, true, false, property.isMixed(),
246-
element.getSchemaComponent(), element.getCustomizations(),
247-
element.getLocator(), property.isDummy(), property.isContent(),
253+
propertyName, true, false, false, element.getSchemaComponent(),
254+
element.getCustomizations(), element.getLocator(),
255+
property.isDummy(), property.isContent(),
248256
property.isMixedExtendedCust());
249257
referencePropertyInfo.getElements().add(element);
250258
return referencePropertyInfo;
251259
}
252260

261+
private CReferencePropertyInfo createContentReferencePropertyInfo(
262+
final Model model, CReferencePropertyInfo property) {
263+
final String propertyName = "content";
264+
final CReferencePropertyInfo referencePropertyInfo = new CReferencePropertyInfo(
265+
propertyName, true, false, true, property.getSchemaComponent(),
266+
property.getCustomizations(), property.getLocator(), false,
267+
true, property.isMixedExtendedCust());
268+
return referencePropertyInfo;
269+
}
270+
253271
private CElementPropertyInfo createElementPropertyInfo(final Model model,
254272
CElementPropertyInfo property, CTypeRef typeRef) {
255273
final String propertyName = createPropertyName(model, typeRef);

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
<dependency>
153153
<groupId>javax.xml.bind</groupId>
154154
<artifactId>jaxb-api</artifactId>
155-
<version>2.1</version>
155+
<version>${jaxb.version}</version>
156156
</dependency>
157157
<dependency>
158158
<groupId>com.sun.xml.bind</groupId>

tests/issues/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</attributes>
88
</classpathentry>
99
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/resources"/>
10-
<classpathentry kind="src" output="target/classes" path="target/generated-sources/xjc">
10+
<classpathentry including="**/*.java" kind="src" output="target/classes" path="target/generated-sources/xjc">
1111
<attributes>
1212
<attribute name="optional" value="true"/>
1313
<attribute name="maven.pomderived" value="true"/>

tests/issues/.settings/org.eclipse.core.resources.prefs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ encoding//src/main/java=UTF-8
33
encoding//src/main/resources=UTF-8
44
encoding//src/test/java=UTF-8
55
encoding//src/test/resources=UTF-8
6+
encoding//target/generated-sources/xjc=UTF-8
67
encoding/<project>=UTF-8

tests/issues/src/main/resources/schema.xsd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,5 +332,18 @@
332332
</xs:sequence>
333333
</xs:complexType>
334334

335+
<xs:complexType name="ghIssue4" mixed="true">
336+
<xs:sequence>
337+
<xs:element name="a" type="xs:string">
338+
<xs:annotation>
339+
<xs:appinfo>
340+
<simplify:as-element-property/>
341+
</xs:appinfo>
342+
</xs:annotation>
343+
</xs:element>
344+
<xs:element name="b" type="xs:int"/>
345+
</xs:sequence>
346+
</xs:complexType>
347+
335348

336349
</xs:schema>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.jvnet.jaxb2_commons.tests.issues;
2+
3+
import java.io.StringWriter;
4+
5+
import javax.xml.bind.JAXBContext;
6+
import javax.xml.bind.JAXBElement;
7+
import javax.xml.bind.JAXBException;
8+
import javax.xml.namespace.QName;
9+
10+
import org.junit.Assert;
11+
import org.junit.Test;
12+
13+
public class GhIssue4Test {
14+
15+
@Test
16+
public void contextIsSuccessfullyCreated() throws JAXBException {
17+
final JAXBContext context = JAXBContext.newInstance(GhIssue4.class);
18+
final GhIssue4 value = new GhIssue4();
19+
value.getA().add("a");
20+
value.getB().add(2);
21+
value.getcontent().add("Test");
22+
23+
final StringWriter sw = new StringWriter();
24+
context.createMarshaller().marshal(
25+
new JAXBElement<GhIssue4>(new QName("test"), GhIssue4.class,
26+
value), sw);
27+
Assert.assertTrue(sw.toString().endsWith(
28+
"<test><a>a</a><b>2</b>Test</test>"));
29+
}
30+
}

0 commit comments

Comments
 (0)