Skip to content

Commit 4534e1b

Browse files
committed
Issue #35. Adding isRequired(), SchemaComponentAware and functions
support.
1 parent 27c4e6b commit 4534e1b

24 files changed

+270
-45
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ protected void processWrappedElementPropertyInfo(
182182
new DummyPropertyInfoOrigin(), wrapperClassInfo,
183183
wrapperPropertyInfo.getPrivateName(),
184184
wrappedPropertyInfo.isCollection(),
185+
wrappedPropertyInfo.isRequired(),
185186
wrappedPropertyInfo.getTypeInfo(),
186187
wrappedPropertyInfo.getElementName(),
187188
wrapperPropertyInfo.getWrapperElementName(),
@@ -212,7 +213,7 @@ protected void processWrappedElementsPropertyInfo(
212213
new DummyPropertyInfoOrigin(), wrapperClassInfo,
213214
wrapperPropertyInfo.getPrivateName(),
214215
wrappedPropertyInfo.isCollection(),
215-
216+
wrappedPropertyInfo.isRequired(),
216217
wrappedPropertyInfo.getElementTypeInfos(),
217218
wrapperPropertyInfo.getElementName());
218219

@@ -240,6 +241,7 @@ protected void processWrappedElementRefPropertyInfo(
240241
new DummyPropertyInfoOrigin(), wrapperClassInfo,
241242
wrapperPropertyInfo.getPrivateName(),
242243
wrappedPropertyInfo.isCollection(),
244+
wrappedPropertyInfo.isRequired(),
243245
wrappedPropertyInfo.getTypeInfo(),
244246
wrappedPropertyInfo.getElementName(),
245247
wrapperPropertyInfo.getElementName(),
@@ -272,7 +274,7 @@ protected void processWrappedElementRefsPropertyInfo(
272274
new DummyPropertyInfoOrigin(), wrapperClassInfo,
273275
wrapperPropertyInfo.getPrivateName(),
274276
wrappedPropertyInfo.isCollection(),
275-
277+
wrappedPropertyInfo.isRequired(),
276278
wrappedPropertyInfo.getElementTypeInfos(),
277279
wrapperPropertyInfo.getElementName(),
278280
wrappedPropertyInfo.isMixed(),

runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/MClassInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public interface MClassInfo<T, C extends T> extends MClassTypeInfo<T, C>,
1414

1515
public List<MPropertyInfo<T, C>> getProperties();
1616

17+
public MPropertyInfo<T, C> getProperty(String publicName);
18+
1719
public QName getElementName();
1820

1921
public MElementInfo<T, C> createElementInfo(MTypeInfo<T, C> scope,

runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/MPropertyInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public interface MPropertyInfo<T, C extends T> extends MOriginated<MPropertyInfo
1212
public String getPublicName();
1313

1414
public boolean isCollection();
15+
16+
public boolean isRequired();
1517

1618
public <V> V acceptPropertyInfoVisitor(MPropertyInfoVisitor<T, C, V> visitor);
1719
}

runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMAnyAttributePropertyInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class CMAnyAttributePropertyInfo<T, C extends T> extends
1010

1111
public CMAnyAttributePropertyInfo(MPropertyInfoOrigin origin,
1212
MClassInfo<T, C> classInfo, String privateName) {
13-
super(origin, classInfo, privateName, false);
13+
super(origin, classInfo, privateName, false, false);
1414
}
1515

1616
public <V> V acceptPropertyInfoVisitor(MPropertyInfoVisitor<T, C, V> visitor) {

runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMAnyElementPropertyInfo.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
import org.jvnet.jaxb2_commons.xml.bind.model.MPropertyInfoVisitor;
66
import org.jvnet.jaxb2_commons.xml.bind.model.origin.MPropertyInfoOrigin;
77

8-
public class CMAnyElementPropertyInfo<T, C extends T> extends CMPropertyInfo<T, C>
9-
implements MAnyElementPropertyInfo<T, C> {
8+
public class CMAnyElementPropertyInfo<T, C extends T> extends
9+
CMPropertyInfo<T, C> implements MAnyElementPropertyInfo<T, C> {
1010

1111
private final boolean mixed;
1212
private final boolean domAllowed;
1313
private final boolean typedObjectAllowed;
1414

1515
public CMAnyElementPropertyInfo(MPropertyInfoOrigin origin,
1616
MClassInfo<T, C> classInfo, String privateName, boolean collection,
17-
boolean mixed, boolean domAllowed, boolean typedObjectAllowed) {
18-
super(origin, classInfo, privateName, collection);
17+
boolean required, boolean mixed, boolean domAllowed,
18+
boolean typedObjectAllowed) {
19+
super(origin, classInfo, privateName, collection, required);
1920
this.mixed = mixed;
2021
this.domAllowed = domAllowed;
2122
this.typedObjectAllowed = typedObjectAllowed;

runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMAttributePropertyInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class CMAttributePropertyInfo<T, C extends T> extends
1313
CMSingleTypePropertyInfo<T, C> implements MAttributePropertyInfo<T, C> {
1414

1515
private final QName attributeName;
16-
16+
1717
public CMAttributePropertyInfo(MPropertyInfoOrigin origin,
1818
MClassInfo<T, C> classInfo, String privateName,
19-
MTypeInfo<T, C> typeInfo, QName attributeName) {
20-
super(origin, classInfo, privateName, false, typeInfo);
19+
MTypeInfo<T, C> typeInfo, QName attributeName, boolean required) {
20+
super(origin, classInfo, privateName, false, typeInfo, required);
2121
Validate.notNull(attributeName);
2222
this.attributeName = attributeName;
2323
}

runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMClassInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.util.ArrayList;
44
import java.util.Collections;
5+
import java.util.HashMap;
56
import java.util.List;
7+
import java.util.Map;
68

79
import javax.xml.namespace.QName;
810

@@ -36,6 +38,7 @@ public class CMClassInfo<T, C extends T> implements MClassInfo<T, C> {
3638
private final MClassTypeInfo<T, C> baseTypeInfo;
3739
private final QName elementName;
3840

41+
private Map<String, MPropertyInfo<T, C>> propertiesMap = new HashMap<String, MPropertyInfo<T, C>>();
3942
private List<MPropertyInfo<T, C>> properties = new ArrayList<MPropertyInfo<T, C>>();
4043
private List<MPropertyInfo<T, C>> unmodifiableProperties = Collections
4144
.unmodifiableList(properties);
@@ -133,6 +136,11 @@ public MClassTypeInfo<T, C> getBaseTypeInfo() {
133136
public List<MPropertyInfo<T, C>> getProperties() {
134137
return unmodifiableProperties;
135138
}
139+
140+
@Override
141+
public MPropertyInfo<T, C> getProperty(String privateName) {
142+
return this.propertiesMap.get(privateName);
143+
}
136144

137145
public QName getElementName() {
138146
return elementName;
@@ -141,12 +149,14 @@ public QName getElementName() {
141149
public void addProperty(MPropertyInfo<T, C> propertyInfo) {
142150
Validate.notNull(propertyInfo);
143151
this.properties.add(propertyInfo);
152+
this.propertiesMap.put(propertyInfo.getPrivateName(), propertyInfo);
144153
}
145154

146155
@SuppressWarnings("unchecked")
147156
public void removeProperty(MPropertyInfo<T, C> propertyInfo) {
148157
Validate.notNull(propertyInfo);
149158
this.properties.remove(propertyInfo);
159+
this.propertiesMap.remove(propertyInfo.getPrivateName());
150160

151161
if (getOrigin() instanceof ClassInfoOrigin
152162
&& propertyInfo.getOrigin() instanceof PropertyInfoOrigin) {

runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMElementPropertyInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public class CMElementPropertyInfo<T, C extends T> extends CMPropertyInfo<T, C>
1919

2020
public CMElementPropertyInfo(MPropertyInfoOrigin origin,
2121
MClassInfo<T, C> classInfo, String privateName, boolean collection,
22-
MTypeInfo<T, C> typeInfo, QName elementName,
22+
boolean required, MTypeInfo<T, C> typeInfo, QName elementName,
2323
QName wrapperElementName, boolean nillable, String defaultValue) {
24-
super(origin, classInfo, privateName, collection);
24+
super(origin, classInfo, privateName, collection, required);
2525
this.typeInfo = typeInfo;
2626
this.elementName = elementName;
2727
this.wrapperElementName = wrapperElementName;

runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMElementRefPropertyInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import org.jvnet.jaxb2_commons.xml.bind.model.MTypeInfo;
99
import org.jvnet.jaxb2_commons.xml.bind.model.origin.MPropertyInfoOrigin;
1010

11-
public class CMElementRefPropertyInfo<T, C extends T> extends CMPropertyInfo<T, C>
12-
implements MElementRefPropertyInfo<T, C> {
11+
public class CMElementRefPropertyInfo<T, C extends T> extends
12+
CMPropertyInfo<T, C> implements MElementRefPropertyInfo<T, C> {
1313

1414
private final MTypeInfo<T, C> typeInfo;
1515
private final QName elementName;
@@ -22,10 +22,10 @@ public class CMElementRefPropertyInfo<T, C extends T> extends CMPropertyInfo<T,
2222

2323
public CMElementRefPropertyInfo(MPropertyInfoOrigin origin,
2424
MClassInfo<T, C> classInfo, String privateName, boolean collection,
25-
MTypeInfo<T, C> typeInfo, QName elementName,
25+
boolean required, MTypeInfo<T, C> typeInfo, QName elementName,
2626
QName wrapperElementName, boolean mixed, boolean domAllowed,
2727
boolean typedObjectAllowed, String defaultValue) {
28-
super(origin, classInfo, privateName, collection);
28+
super(origin, classInfo, privateName, collection, required);
2929
this.typeInfo = typeInfo;
3030
this.elementName = elementName;
3131
this.wrapperElementName = wrapperElementName;
@@ -58,7 +58,7 @@ public boolean isDomAllowed() {
5858
public boolean isTypedObjectAllowed() {
5959
return typedObjectAllowed;
6060
}
61-
61+
6262
@Override
6363
public boolean isNillable() {
6464
return true;

runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMElementRefsPropertyInfo.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import org.jvnet.jaxb2_commons.xml.bind.model.MPropertyInfoVisitor;
1515
import org.jvnet.jaxb2_commons.xml.bind.model.origin.MPropertyInfoOrigin;
1616

17-
public class CMElementRefsPropertyInfo<T, C extends T> extends CMPropertyInfo<T, C>
18-
implements MElementRefsPropertyInfo<T, C> {
17+
public class CMElementRefsPropertyInfo<T, C extends T> extends
18+
CMPropertyInfo<T, C> implements MElementRefsPropertyInfo<T, C> {
1919

2020
private final QName wrapperElementName;
2121

@@ -29,13 +29,14 @@ public class CMElementRefsPropertyInfo<T, C extends T> extends CMPropertyInfo<T,
2929

3030
public CMElementRefsPropertyInfo(MPropertyInfoOrigin origin,
3131
MClassInfo<T, C> classInfo, String privateName, boolean collection,
32+
boolean required,
3233
Collection<MElementTypeInfo<T, C>> elementTypeInfos,
3334
QName wrapperElementName, boolean mixed, boolean domAllowed,
3435
boolean typedObjectAllowed) {
35-
super(origin, classInfo, privateName, collection);
36+
super(origin, classInfo, privateName, collection, required);
3637
Validate.noNullElements(elementTypeInfos);
37-
// Validate.notEmpty(elementTypeInfos);
38-
// Validate.isTrue(elementTypeInfos.size() > 1);
38+
// Validate.notEmpty(elementTypeInfos);
39+
// Validate.isTrue(elementTypeInfos.size() > 1);
3940
this.elementTypeInfos.addAll(elementTypeInfos);
4041
this.wrapperElementName = wrapperElementName;
4142
this.mixed = mixed;

0 commit comments

Comments
 (0)