use of com.sun.xml.xsom.XSFacet in project atlasmap by atlasmap.
the class SchemaWriter method restrictionSimpleType.
public void restrictionSimpleType(XSRestrictionSimpleType type) {
if (type.getBaseType() == null) {
// don't print anySimpleType
if (!type.getName().equals("anySimpleType"))
throw new InternalError();
if (!Const.schemaNamespace.equals(type.getTargetNamespace()))
throw new InternalError();
return;
}
XSSimpleType baseType = type.getSimpleBaseType();
println(MessageFormat.format("<restriction{0}>", baseType.isLocal() ? "" : " base=\"{" + baseType.getTargetNamespace() + '}' + baseType.getName() + '\"'));
indent++;
if (baseType.isLocal())
simpleType(baseType);
Iterator itr = type.iterateDeclaredFacets();
while (itr.hasNext()) facet((XSFacet) itr.next());
indent--;
println("</restriction>");
}
use of com.sun.xml.xsom.XSFacet in project atlasmap by atlasmap.
the class XmlSchemaInspector method printElement.
private void printElement(XSElementDecl element, XmlComplexType parentXmlComplexType, CollectionType collectionType, Set<String> cachedComplexType) throws Exception {
String parentPath = parentXmlComplexType.getPath();
String elementName = getNameNS(element);
String typeName = getNameNS(element.getType());
XSType elementType = element.getType();
if (elementType == null) {
return;
}
if (elementType.isComplexType()) {
XmlComplexType complexType = getXmlComplexType();
String path = parentPath + "/" + elementName + getCollectionPathSuffix(collectionType);
complexType.setName(elementName);
complexType.setPath(path);
complexType.setCollectionType(collectionType);
parentXmlComplexType.getXmlFields().getXmlField().add(complexType);
if (typeName != null && !typeName.isEmpty() && cachedComplexType.contains(typeName)) {
complexType.setStatus(FieldStatus.CACHED);
} else if (typeName != null) {
cachedComplexType.add(typeName);
}
if (complexType.getStatus() != FieldStatus.CACHED) {
printComplexType(element.getType().asComplexType(), complexType, cachedComplexType);
if (LOG.isTraceEnabled()) {
LOG.trace("Element: {}/{}", parentPath, getNameNS(element));
}
}
} else if (elementType.asSimpleType() != null) {
if (LOG.isTraceEnabled()) {
LOG.trace("Element: {}/{}", parentPath, getNameNS(element));
}
XSRestrictionSimpleType restrictionType = elementType.asSimpleType().asRestriction();
List<XSFacet> enumerations = restrictionType != null ? restrictionType.getFacets("enumeration") : null;
if (enumerations != null && !enumerations.isEmpty()) {
XmlComplexType complexType = getXmlComplexType();
String path = parentPath + "/" + elementName + getCollectionPathSuffix(collectionType);
complexType.setName(elementName);
complexType.setPath(path);
complexType.setCollectionType(collectionType);
complexType.setEnumeration(true);
parentXmlComplexType.getXmlFields().getXmlField().add(complexType);
XmlEnumFields enums = new XmlEnumFields();
complexType.setXmlEnumFields(enums);
for (XSFacet enumFacet : enumerations) {
XmlEnumField f = new XmlEnumField();
f.setName(enumFacet.getValue().toString());
enums.getXmlEnumField().add(f);
}
return;
}
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
xmlField.setName(elementName);
xmlField.setPath(parentPath + "/" + elementName + getCollectionPathSuffix(collectionType));
xmlField.setCollectionType(collectionType);
parentXmlComplexType.getXmlFields().getXmlField().add(xmlField);
if (element.getDefaultValue() != null) {
xmlField.setValue(element.getDefaultValue());
} else if (element.getFixedValue() != null) {
xmlField.setValue(element.getFixedValue());
}
XSRestrictionSimpleType typeRestriction = element.getType().asSimpleType().asRestriction();
if (typeRestriction != null) {
xmlField.setFieldType(XS_TYPE_TO_FIELD_TYPE_MAP.get(typeRestriction.getBaseType().getName()));
mapRestrictions(xmlField, typeRestriction);
}
printSimpleType(element.getType().asSimpleType(), xmlField);
}
}
use of com.sun.xml.xsom.XSFacet in project BIMserver by opensourceBIM.
the class XSDSchemaReader method createSimpleType.
private void createSimpleType(XSSimpleType simpleType) {
if (simpleType instanceof RestrictionSimpleTypeImpl) {
RestrictionSimpleTypeImpl restrictionSimpleTypeImpl = (RestrictionSimpleTypeImpl) simpleType;
String typeName = restrictionSimpleTypeImpl.getBaseType().getName();
if (typeName.equals("string")) {
EEnum eEnum = ecoreFactory.createEEnum();
eEnum.setName(simpleType.getName());
ePackage.getEClassifiers().add(eEnum);
int i = 0;
for (XSFacet facet : restrictionSimpleTypeImpl.getDeclaredFacets()) {
EEnumLiteral eEnumLiteral = ecoreFactory.createEEnumLiteral();
eEnumLiteral.setValue(i++);
eEnum.getELiterals().add(eEnumLiteral);
eEnumLiteral.setName(facet.getValue().toString().toUpperCase());
}
} else if (typeName.equals("double")) {
EClass eClass = ecoreFactory.createEClass();
eClass.setName(simpleType.getName());
ePackage.getEClassifiers().add(eClass);
} else if (typeName.equals("normalizedString")) {
EClass eClass = ecoreFactory.createEClass();
eClass.setName(simpleType.getName());
ePackage.getEClassifiers().add(eClass);
} else if (typeName.equals("boolean")) {
EClass eClass = ecoreFactory.createEClass();
eClass.setName(simpleType.getName());
ePackage.getEClassifiers().add(eClass);
} else if (typeName.equals("long")) {
EClass eClass = ecoreFactory.createEClass();
eClass.setName(simpleType.getName());
ePackage.getEClassifiers().add(eClass);
} else {
EClass eClass = ecoreFactory.createEClass();
eClass.setName(simpleType.getName());
ePackage.getEClassifiers().add(eClass);
}
} else {
System.out.println(simpleType.getName());
}
}
Aggregations