use of org.apache.ws.commons.schema.XmlSchemaEnumerationFacet in project hale by halestudio.
the class XmlTypeUtil method configureSimpleTypeRestriction.
/**
* Configure a type definition for a simple type based on a simple type
* restriction.
*
* @param type the type definition
* @param restriction the simple type restriction
* @param index the XML index for resolving type definitions
* @param reporter the report
*/
private static void configureSimpleTypeRestriction(XmlTypeDefinition type, XmlSchemaSimpleTypeRestriction restriction, XmlIndex index, IOReporter reporter) {
QName baseTypeName = restriction.getBaseTypeName();
XmlTypeDefinition baseTypeDef;
if (baseTypeName != null) {
// resolve super type
baseTypeDef = index.getOrCreateType(baseTypeName);
} else if (restriction.getBaseType() != null) {
// simple schema type
XmlSchemaSimpleType simpleType = restriction.getBaseType();
// create an anonymous type
QName anonymousName = new QName(type.getName().getNamespaceURI() + "/" + type.getName().getLocalPart(), // $NON-NLS-1$
"AnonymousSuperType");
baseTypeDef = new AnonymousXmlType(anonymousName);
XmlTypeUtil.configureSimpleType(type, simpleType, index, reporter);
// no schema location available at this point
final String schemaLoc = null;
// set metadata
XmlSchemaReader.setMetadata(type, simpleType, schemaLoc, index);
} else {
reporter.error(new IOMessageImpl("Simple type restriction without base type, skipping type configuration.", null, restriction.getLineNumber(), restriction.getLinePosition()));
return;
}
// set super type
type.setSuperType(baseTypeDef);
// mark as restriction
type.setConstraint(RestrictionFlag.ENABLED);
// assign no binding, inherit from super type
// The following code expects schema to be valid.
List<Validator> validators = new LinkedList<Validator>();
// patterns and enumerations in one step are ORed together!
List<String> values = new LinkedList<String>();
List<Validator> patternValidators = new LinkedList<Validator>();
// TODO different handling for date/time/g.../duration in
// (min|max)(In|Ex)clusive
// XXX only for date, time, duration, dateTime, gMonthDay, gYearMonth?
// no also for some cases of gYear, gMonth, gDay (they can have a
// timezone!)
// but only need to handle cases where isDecimal() is false...
XmlSchemaObjectCollection facets = restriction.getFacets();
for (int i = 0; i < facets.getCount(); i++) {
XmlSchemaFacet facet = (XmlSchemaFacet) facets.getItem(i);
if (facet instanceof XmlSchemaEnumerationFacet) {
values.add(facet.getValue().toString());
} else if (facet instanceof XmlSchemaFractionDigitsFacet) {
validators.add(new DigitCountValidator(DigitCountValidator.Type.FRACTIONDIGITS, Integer.parseInt(facet.getValue().toString())));
} else if (facet instanceof XmlSchemaLengthFacet) {
validators.add(new LengthValidator(LengthValidator.Type.EXACT, Integer.parseInt(facet.getValue().toString())));
} else if (facet instanceof XmlSchemaMaxExclusiveFacet) {
if (// number or date?
isDecimal(facet.getValue().toString()))
validators.add(new NumberValidator(NumberValidator.Type.MAXEXCLUSIVE, new BigDecimal(facet.getValue().toString())));
else
reporter.warn(new IOMessageImpl("(min|max)(In|Ex)clusive not supported for non-number types", null, facet.getLineNumber(), facet.getLinePosition()));
} else if (facet instanceof XmlSchemaMaxInclusiveFacet) {
if (// number or date?
isDecimal(facet.getValue().toString()))
validators.add(new NumberValidator(NumberValidator.Type.MAXINCLUSIVE, new BigDecimal(facet.getValue().toString())));
else
reporter.warn(new IOMessageImpl("(min|max)(In|Ex)clusive not supported for non-number types", null, facet.getLineNumber(), facet.getLinePosition()));
} else if (facet instanceof XmlSchemaMaxLengthFacet) {
validators.add(new LengthValidator(LengthValidator.Type.MAXIMUM, Integer.parseInt(facet.getValue().toString())));
} else if (facet instanceof XmlSchemaMinLengthFacet) {
validators.add(new LengthValidator(LengthValidator.Type.MINIMUM, Integer.parseInt(facet.getValue().toString())));
} else if (facet instanceof XmlSchemaMinExclusiveFacet) {
if (// number or date?
isDecimal(facet.getValue().toString()))
validators.add(new NumberValidator(NumberValidator.Type.MINEXCLUSIVE, new BigDecimal(facet.getValue().toString())));
else
reporter.warn(new IOMessageImpl("(min|max)(In|Ex)clusive not supported for non-number types", null, facet.getLineNumber(), facet.getLinePosition()));
} else if (facet instanceof XmlSchemaMinInclusiveFacet) {
if (// number or date?
isDecimal(facet.getValue().toString()))
validators.add(new NumberValidator(NumberValidator.Type.MININCLUSIVE, new BigDecimal(facet.getValue().toString())));
else
reporter.warn(new IOMessageImpl("(min|max)(In|Ex)clusive not supported for non-number types", null, facet.getLineNumber(), facet.getLinePosition()));
} else if (facet instanceof XmlSchemaPatternFacet) {
patternValidators.add(new PatternValidator(facet.getValue().toString()));
} else if (facet instanceof XmlSchemaTotalDigitsFacet) {
validators.add(new DigitCountValidator(DigitCountValidator.Type.TOTALDIGITS, Integer.parseInt(facet.getValue().toString())));
} else if (facet instanceof XmlSchemaWhiteSpaceFacet) {
reporter.info(new IOMessageImpl("White space facet not supported", null, facet.getLineNumber(), facet.getLinePosition()));
// Nothing to validate according to w3.
// Values should be processed according to rule?
} else {
reporter.error(new IOMessageImpl("Unrecognized facet: " + facet.getClass().getSimpleName(), null, facet.getLineNumber(), facet.getLinePosition()));
}
}
if (!patternValidators.isEmpty())
validators.add(new OrValidator(patternValidators));
if (!values.isEmpty()) {
// set enumeration constraint
// no check of which values are okay, they must be validated
// somewhere else.
// XXX conversion to be done?
type.setConstraint(new Enumeration<String>(values, false));
validators.add(new EnumerationValidator(values));
}
if (!validators.isEmpty())
type.setConstraint(new ValidationConstraint(new AndValidator(validators), type));
}
use of org.apache.ws.commons.schema.XmlSchemaEnumerationFacet in project cxf by apache.
the class XmlSchemaUtils method enumeratorValues.
/**
* Retrieve the string values for an enumeration.
* @param type
*/
public static List<String> enumeratorValues(XmlSchemaSimpleType type) {
XmlSchemaSimpleTypeContent content = type.getContent();
XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
List<XmlSchemaFacet> facets = restriction.getFacets();
List<String> values = new ArrayList<>();
for (XmlSchemaFacet facet : facets) {
XmlSchemaEnumerationFacet enumFacet = (XmlSchemaEnumerationFacet) facet;
values.add(enumFacet.getValue().toString());
}
return values;
}
use of org.apache.ws.commons.schema.XmlSchemaEnumerationFacet in project cxf by apache.
the class WSDLToCorbaHelper method createCorbaEnum.
private Enum createCorbaEnum(XmlSchemaSimpleTypeRestriction restrictionType, QName name, QName schematypeName) {
Enum corbaEnum = new Enum();
corbaEnum.setType(schematypeName);
corbaEnum.setName(name.getLocalPart());
corbaEnum.setQName(name);
corbaEnum.setRepositoryID(REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION);
for (XmlSchemaFacet f : restrictionType.getFacets()) {
XmlSchemaEnumerationFacet val = (XmlSchemaEnumerationFacet) f;
Enumerator enumerator = new Enumerator();
enumerator.setValue(val.getValue().toString());
corbaEnum.getEnumerator().add(enumerator);
}
return corbaEnum;
}
use of org.apache.ws.commons.schema.XmlSchemaEnumerationFacet in project tomee by apache.
the class CommonsSchemaInfoBuilder method createXmlTypeInfo.
public static XmlTypeInfo createXmlTypeInfo(QName qname, XmlSchemaType type) {
if (qname == null)
throw new NullPointerException("qname is null");
if (type == null)
throw new NullPointerException("type is null");
XmlTypeInfo typeInfo = new XmlTypeInfo();
typeInfo.qname = qname;
typeInfo.anonymous = qname.getLocalPart().indexOf('>') >= 0;
if (type instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
XmlSchemaSimpleTypeContent content = simpleType.getContent();
if (content instanceof XmlSchemaSimpleTypeList) {
XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList) content;
typeInfo.simpleBaseType = list.getItemType().getQName();
// this is a list
typeInfo.listType = true;
} else if (content instanceof XmlSchemaSimpleTypeRestriction) {
XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
typeInfo.simpleBaseType = restriction.getBaseTypeName();
// is this an enumeration?
for (Iterator iterator = restriction.getFacets().getIterator(); iterator.hasNext(); ) {
if (iterator.next() instanceof XmlSchemaEnumerationFacet) {
typeInfo.enumType = true;
break;
}
}
}
} else if (type instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
// SOAP array component type
typeInfo.arrayComponentType = extractSoapArrayComponentType(complexType);
// process attributes (skip soap arrays which have non-mappable attributes)
if (!isSoapArray(complexType)) {
XmlSchemaObjectCollection attributes = complexType.getAttributes();
for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
Object item = iterator.next();
if (item instanceof XmlSchemaAttribute) {
XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
Object old = typeInfo.attributes.put(attribute.getQName().getLocalPart(), attribute.getSchemaTypeName());
if (old != null) {
throw new IllegalArgumentException("Complain to your expert group member, spec does not support attributes with the same local name and differing namespaces: original: " + old + ", duplicate local name: " + attribute);
}
}
}
}
} else {
LOG.warn("Unknown schema type class " + typeInfo.getClass().getName());
}
return typeInfo;
}
use of org.apache.ws.commons.schema.XmlSchemaEnumerationFacet in project cxf by apache.
the class EnumType method writeSchema.
@Override
public void writeSchema(XmlSchema root) {
XmlSchemaSimpleType simple = new XmlSchemaSimpleType(root, true);
simple.setName(getSchemaType().getLocalPart());
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
restriction.setBaseTypeName(Constants.XSD_STRING);
simple.setContent(restriction);
Object[] constants = getTypeClass().getEnumConstants();
List<XmlSchemaFacet> facets = restriction.getFacets();
for (Object constant : constants) {
XmlSchemaEnumerationFacet f = new XmlSchemaEnumerationFacet();
f.setValue(getValue(constant));
facets.add(f);
}
}
Aggregations