Skip to content

Commit

Permalink
Fixes #26.
Browse files Browse the repository at this point in the history
  • Loading branch information
highsource committed Dec 23, 2015
1 parent 3d68a18 commit c483ce9
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ protected void processWrappedElementPropertyInfo(
wrappedPropertyInfo.getElementName(),
wrapperPropertyInfo.getWrapperElementName(),
wrappedPropertyInfo.isNillable(),
wrappedPropertyInfo.getDefaultValue());
wrappedPropertyInfo.getDefaultValue(),
wrappedPropertyInfo.getDefaultValueNamespaceContext());

rootClassInfo.addProperty(propertyInfo);

Expand Down Expand Up @@ -248,7 +249,8 @@ protected void processWrappedElementRefPropertyInfo(
wrappedPropertyInfo.isMixed(),
wrappedPropertyInfo.isDomAllowed(),
wrappedPropertyInfo.isTypedObjectAllowed(),
wrappedPropertyInfo.getDefaultValue());
wrappedPropertyInfo.getDefaultValue(),
wrappedPropertyInfo.getDefaultValueNamespaceContext());

rootClassInfo.addProperty(propertyInfo);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.jvnet.jaxb2_commons.xml.bind.model;

import javax.xml.namespace.NamespaceContext;

public interface MDefaultValue {

public NamespaceContext getDefaultValueNamespaceContext();

public String getDefaultValue();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jvnet.jaxb2_commons.xml.bind.model;

public interface MSingleTypePropertyInfo<T, C extends T> extends MPropertyInfo<T, C>,
MTyped<T, C> {
MTyped<T, C>, MDefaultValue {

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jvnet.jaxb2_commons.xml.bind.model.concrete;

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;

import org.jvnet.jaxb2_commons.lang.Validate;
Expand All @@ -13,11 +14,13 @@ public class CMAttributePropertyInfo<T, C extends T> extends
CMSingleTypePropertyInfo<T, C> implements MAttributePropertyInfo<T, C> {

private final QName attributeName;

public CMAttributePropertyInfo(MPropertyInfoOrigin origin,
MClassInfo<T, C> classInfo, String privateName,
MTypeInfo<T, C> typeInfo, QName attributeName, boolean required) {
super(origin, classInfo, privateName, false, typeInfo, required);
MTypeInfo<T, C> typeInfo, QName attributeName, boolean required,
String defaultValue, NamespaceContext defaultValueNamespaceContext) {
super(origin, classInfo, privateName, false, typeInfo, required,
defaultValue, defaultValueNamespaceContext);
Validate.notNull(attributeName);
this.attributeName = attributeName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public MElementInfo<T, C> createElementInfo(MTypeInfo<T, C> scope,
QName substitutionHead) {
return new CMElementInfo<T, C>(getOrigin().createElementInfoOrigin(),
getPackageInfo(), getContainer(), getLocalName(),
getElementName(), scope, this, substitutionHead, null);
getElementName(), scope, this, substitutionHead, null, null);
}

public MPackageInfo getPackageInfo() {
Expand Down Expand Up @@ -136,7 +136,7 @@ public MClassTypeInfo<T, C> getBaseTypeInfo() {
public List<MPropertyInfo<T, C>> getProperties() {
return unmodifiableProperties;
}

@Override
public MPropertyInfo<T, C> getProperty(String privateName) {
return this.propertiesMap.get(privateName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.text.MessageFormat;

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;

import org.jvnet.jaxb2_commons.lang.Validate;
Expand Down Expand Up @@ -31,10 +32,13 @@ public class CMElementInfo<T, C extends T> implements MElementInfo<T, C> {

private final String defaultValue;

private final NamespaceContext defaultValueNamespaceContext;

public CMElementInfo(MElementInfoOrigin origin, MPackageInfo _package,
MContainer container, String localName, QName elementName,
MTypeInfo<T, C> scope, MTypeInfo<T, C> typeInfo,
QName substitutionHead, String defaultValue) {
QName substitutionHead, String defaultValue,
NamespaceContext defaultValueNamespaceContext) {
super();
Validate.notNull(origin);
Validate.notNull(elementName);
Expand All @@ -48,6 +52,7 @@ public CMElementInfo(MElementInfoOrigin origin, MPackageInfo _package,
this.typeInfo = typeInfo;
this.substitutionHead = substitutionHead;
this.defaultValue = defaultValue;
this.defaultValueNamespaceContext = defaultValueNamespaceContext;
}

public MElementInfoOrigin getOrigin() {
Expand Down Expand Up @@ -109,6 +114,11 @@ public String getDefaultValue() {
return defaultValue;
}

@Override
public NamespaceContext getDefaultValueNamespaceContext() {
return defaultValueNamespaceContext;
}

public String toString() {
return MessageFormat.format("ElementInfo [{0}: {1}]", getElementName(),
getTypeInfo());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jvnet.jaxb2_commons.xml.bind.model.concrete;

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;

import org.jvnet.jaxb2_commons.xml.bind.model.MClassInfo;
Expand All @@ -16,17 +17,20 @@ public class CMElementPropertyInfo<T, C extends T> extends CMPropertyInfo<T, C>
private final QName wrapperElementName;
private final boolean nillable;
private final String defaultValue;
private final NamespaceContext defaultValueNamespaceContext;

public CMElementPropertyInfo(MPropertyInfoOrigin origin,
MClassInfo<T, C> classInfo, String privateName, boolean collection,
boolean required, MTypeInfo<T, C> typeInfo, QName elementName,
QName wrapperElementName, boolean nillable, String defaultValue) {
QName wrapperElementName, boolean nillable, String defaultValue,
NamespaceContext defaultValueNamespaceContext) {
super(origin, classInfo, privateName, collection, required);
this.typeInfo = typeInfo;
this.elementName = elementName;
this.wrapperElementName = wrapperElementName;
this.nillable = nillable;
this.defaultValue = defaultValue;
this.defaultValueNamespaceContext = defaultValueNamespaceContext;
}

public MTypeInfo<T, C> getTypeInfo() {
Expand All @@ -51,6 +55,11 @@ public String getDefaultValue() {
return defaultValue;
}

@Override
public NamespaceContext getDefaultValueNamespaceContext() {
return defaultValueNamespaceContext;
}

public <V> V acceptPropertyInfoVisitor(MPropertyInfoVisitor<T, C, V> visitor) {
return visitor.visitElementPropertyInfo(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jvnet.jaxb2_commons.xml.bind.model.concrete;

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;

import org.jvnet.jaxb2_commons.xml.bind.model.MClassInfo;
Expand All @@ -19,12 +20,14 @@ public class CMElementRefPropertyInfo<T, C extends T> extends
private final boolean domAllowed;
private final boolean typedObjectAllowed;
private final String defaultValue;
private final NamespaceContext defaultValueNamespaceContext;

public CMElementRefPropertyInfo(MPropertyInfoOrigin origin,
MClassInfo<T, C> classInfo, String privateName, boolean collection,
boolean required, MTypeInfo<T, C> typeInfo, QName elementName,
QName wrapperElementName, boolean mixed, boolean domAllowed,
boolean typedObjectAllowed, String defaultValue) {
boolean typedObjectAllowed, String defaultValue,
NamespaceContext defaultValueNamespaceContext) {
super(origin, classInfo, privateName, collection, required);
this.typeInfo = typeInfo;
this.elementName = elementName;
Expand All @@ -33,6 +36,7 @@ public CMElementRefPropertyInfo(MPropertyInfoOrigin origin,
this.domAllowed = domAllowed;
this.typedObjectAllowed = typedObjectAllowed;
this.defaultValue = defaultValue;
this.defaultValueNamespaceContext = defaultValueNamespaceContext;
}

public MTypeInfo<T, C> getTypeInfo() {
Expand Down Expand Up @@ -69,6 +73,11 @@ public String getDefaultValue() {
return defaultValue;
}

@Override
public NamespaceContext getDefaultValueNamespaceContext() {
return defaultValueNamespaceContext;
}

public <V> V acceptPropertyInfoVisitor(MPropertyInfoVisitor<T, C, V> visitor) {
return visitor.visitElementRefPropertyInfo(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jvnet.jaxb2_commons.xml.bind.model.concrete;

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;

import org.jvnet.jaxb2_commons.lang.Validate;
Expand All @@ -17,14 +18,18 @@ public class CMElementTypeInfo<T, C extends T> implements

private final String defaultValue;

private final NamespaceContext defaultValueNamespaceContext;

public CMElementTypeInfo(QName elementName, MTypeInfo<T, C> typeInfo,
boolean nillable, String defaultValue) {
boolean nillable, String defaultValue,
NamespaceContext defaultValueNamespaceContext) {
Validate.notNull(elementName);
Validate.notNull(typeInfo);
this.elementName = elementName;
this.typeInfo = typeInfo;
this.nillable = nillable;
this.defaultValue = defaultValue;
this.defaultValueNamespaceContext = defaultValueNamespaceContext;
}

public QName getElementName() {
Expand All @@ -43,6 +48,11 @@ public boolean isNillable() {
public String getDefaultValue() {
return defaultValue;
}

@Override
public NamespaceContext getDefaultValueNamespaceContext() {
return defaultValueNamespaceContext;
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public MElementInfo<T, C> createElementInfo(MTypeInfo<T, C> scope,
QName substitutionHead) {
return new CMElementInfo<T, C>(getOrigin().createElementInfoOrigin(),
getPackageInfo(), getContainer(), getLocalName(),
getElementName(), scope, this, substitutionHead, null);
getElementName(), scope, this, substitutionHead, null, null);
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;

import javax.activation.MimeType;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;

import org.jvnet.jaxb2_commons.lang.Validate;
Expand Down Expand Up @@ -349,17 +350,20 @@ private MPropertyInfo<T, C> createPropertyInfo(

protected MPropertyInfo<T, C> createAttributePropertyInfo(
final MClassInfo<T, C> classInfo, final API propertyInfo) {

return new CMAttributePropertyInfo<T, C>(
createPropertyInfoOrigin((PI) propertyInfo), classInfo,
propertyInfo.getName(), getTypeInfo(propertyInfo),
propertyInfo.getXmlName(), propertyInfo.isRequired());
propertyInfo.getXmlName(), propertyInfo.isRequired(),
getDefaultValue(propertyInfo),
getDefaultValueNamespaceContext(propertyInfo));
}

protected MPropertyInfo<T, C> createValuePropertyInfo(
final MClassInfo<T, C> classInfo, final VPI propertyInfo) {
return new CMValuePropertyInfo<T, C>(
createPropertyInfoOrigin((PI) propertyInfo), classInfo,
propertyInfo.getName(), getTypeInfo(propertyInfo));
propertyInfo.getName(), getTypeInfo(propertyInfo), null, null);
}

protected MPropertyInfo<T, C> createElementPropertyInfo(
Expand All @@ -370,7 +374,8 @@ protected MPropertyInfo<T, C> createElementPropertyInfo(
ep.isCollection() && !ep.isValueList(), ep.isRequired(),
getTypeInfo(ep, typeRef), typeRef.getTagName(),
ep.getXmlName(), typeRef.isNillable(),
typeRef.getDefaultValue());
getDefaultValue(typeRef),
getDefaultValueNamespaceContext(typeRef));
}

protected MPropertyInfo<T, C> createElementsPropertyInfo(
Expand All @@ -380,8 +385,9 @@ protected MPropertyInfo<T, C> createElementsPropertyInfo(
types.size());
for (TypeRef<T, C> typeRef : types) {
typedElements.add(new CMElementTypeInfo<T, C>(typeRef.getTagName(),
getTypeInfo(ep, typeRef), typeRef.isNillable(), typeRef
.getDefaultValue()));
getTypeInfo(ep, typeRef), typeRef.isNillable(),
getDefaultValue(typeRef),
getDefaultValueNamespaceContext(typeRef)));
}
return new CMElementsPropertyInfo<T, C>(
createPropertyInfoOrigin((PI) ep), classInfo, ep.getName(),
Expand Down Expand Up @@ -409,7 +415,8 @@ protected MPropertyInfo<T, C> createElementRefPropertyInfo(
: rp.getWildcard().allowDom,
rp.getWildcard() == null ? true
: rp.getWildcard().allowTypedObject,
getDefaultValue(element));
getDefaultValue(element),
getDefaultValueNamespaceContext(element));
}

protected MPropertyInfo<T, C> createElementRefsPropertyInfo(
Expand All @@ -418,7 +425,8 @@ protected MPropertyInfo<T, C> createElementRefsPropertyInfo(
for (Element<T, C> element : rp.getElements()) {
typedElements.add(new CMElementTypeInfo<T, C>(element
.getElementName(), getTypeInfo(rp, element), true,
getDefaultValue(element)));
getDefaultValue(element),
getDefaultValueNamespaceContext(element)));
}
return new CMElementRefsPropertyInfo<T, C>(
createPropertyInfoOrigin((PI) rp), classInfo, rp.getName(),
Expand Down Expand Up @@ -470,7 +478,24 @@ private String getDefaultValue(Element<T, C> element) {
final List<? extends TypeRef<T, C>> types = property.getTypes();
if (types.size() == 1) {
final TypeRef<T, C> typeRef = types.get(0);
return typeRef.getDefaultValue();
return getDefaultValue(typeRef);
}
}
}
return null;
}

private NamespaceContext getDefaultValueNamespaceContext(
Element<T, C> element) {
if (element instanceof ElementInfo) {
final ElementInfo<T, C> elementInfo = (ElementInfo<T, C>) element;
final ElementPropertyInfo<T, C> property = elementInfo
.getProperty();
if (property != null) {
final List<? extends TypeRef<T, C>> types = property.getTypes();
if (types.size() == 1) {
final TypeRef<T, C> typeRef = types.get(0);
return getDefaultValueNamespaceContext(typeRef);
}
}
}
Expand Down Expand Up @@ -531,7 +556,8 @@ protected MElementInfo<T, C> createElementInfo(EI element) {
createElementInfoOrigin(element), getPackage(element),
getContainer(element), getLocalName(element),
element.getElementName(), scope, getTypeInfo(element),
substitutionHead, getDefaultValue(element));
substitutionHead, getDefaultValue(element),
getDefaultValueNamespaceContext(element));
return elementInfo;
}

Expand Down Expand Up @@ -587,4 +613,13 @@ protected MWildcardTypeInfoOrigin createWildcardTypeInfoOrigin(WTI info) {
*/
protected abstract Class<?> loadClass(T referencedType);

protected abstract String getDefaultValue(API propertyInfo);

protected abstract NamespaceContext getDefaultValueNamespaceContext(
API propertyInfo);

protected abstract String getDefaultValue(TypeRef<T, C> typeRef);

protected abstract NamespaceContext getDefaultValueNamespaceContext(
TypeRef<T, C> typeRef);
}
Loading

0 comments on commit c483ce9

Please sign in to comment.