Java源码示例:org.apache.ws.commons.schema.XmlSchemaEnumerationFacet
示例1
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;
}
示例2
@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);
}
}
示例3
/**
* Create an XML schema enumeration facet.
*
* @param conditionValue the value to set
* @return an XML schema enumeration facet
*/
protected XmlSchemaEnumerationFacet createEnumerationFacet(
final String conditionValue) {
XmlSchemaEnumerationFacet xmlSchemaEnumerationFacet = new XmlSchemaEnumerationFacet();
xmlSchemaEnumerationFacet.setValue(conditionValue);
return xmlSchemaEnumerationFacet;
}
示例4
private boolean isEnumeration(XmlSchemaSimpleTypeRestriction restriction) {
if ((restriction == null) || (restriction.getFacets().isEmpty())
|| (restriction.getBaseTypeName() == null)) {
return false;
}
for (XmlSchemaFacet facet : restriction.getFacets()) {
if (facet instanceof XmlSchemaEnumerationFacet) {
return true;
}
}
return false;
}
示例5
/**
* Return true if a simple type is a straightforward XML Schema representation of an enumeration.
* If we discover schemas that are 'enum-like' with more complex structures, we might
* make this deal with them.
* @param type Simple type, possible an enumeration.
* @return true for an enumeration.
*/
public static boolean isEumeration(XmlSchemaSimpleType type) {
XmlSchemaSimpleTypeContent content = type.getContent();
if (!(content instanceof XmlSchemaSimpleTypeRestriction)) {
return false;
}
XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
List<XmlSchemaFacet> facets = restriction.getFacets();
for (XmlSchemaFacet facet : facets) {
if (!(facet instanceof XmlSchemaEnumerationFacet)) {
return false;
}
}
return true;
}
示例6
/**
* 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;
}
示例7
private static final EnumLiteral enumLiteralFromFacet(final XmlSchemaEnumerationFacet enumFacet,
final Xsd2UmlConfig context) {
final List<TaggedValue> annotation = annotations(enumFacet, context);
// We're assuming here that the whiteSpace facet for this enumeration
// type is "collapse".
// In general, this will not be true and we will have to compute it.
final String name = XmlTools.collapseWhitespace(enumFacet.getValue().toString());
return new EnumLiteral(name, annotation);
}
示例8
public void visit(AST enumNode) {
// <enum_type> ::= "enum" <identifier> "{" <enumerator> {"," <enumerator>}* "}"
// <enumerator> ::= <identifier>
AST enumNameNode = enumNode.getFirstChild();
Scope enumNameScope = new Scope(getScope(), enumNameNode);
// xmlschema:enum
XmlSchemaSimpleType enumSchemaSimpleType = new XmlSchemaSimpleType(schema, true);
enumSchemaSimpleType.setName(mapper.mapToQName(enumNameScope));
XmlSchemaSimpleTypeRestriction enumSchemaSimpleTypeRestriction = new XmlSchemaSimpleTypeRestriction();
enumSchemaSimpleTypeRestriction.setBaseTypeName(Constants.XSD_STRING);
//XmlSchemaSimpleTypeContent xmlSchemaSimpleTypeContent = enumSchemaSimpleTypeRestriction;
enumSchemaSimpleType.setContent(enumSchemaSimpleTypeRestriction);
// corba:enum
Enum corbaEnum = new Enum();
corbaEnum.setQName(new QName(typeMap.getTargetNamespace(), enumNameScope.toString()));
corbaEnum.setRepositoryID(enumNameScope.toIDLRepositoryID());
corbaEnum.setType(enumSchemaSimpleType.getQName());
AST node = enumNameNode.getNextSibling();
while (node != null) {
// xmlschema:enumeration
XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
enumeration.setValue(node.toString());
enumSchemaSimpleTypeRestriction.getFacets().add(enumeration);
// corba:enumerator
Enumerator enumerator = new Enumerator();
enumerator.setValue(node.toString());
corbaEnum.getEnumerator().add(enumerator);
node = node.getNextSibling();
}
// add corbaType
typeMap.getStructOrExceptionOrUnion().add(corbaEnum);
// REVISIT: are there assignments needed?
setSchemaType(enumSchemaSimpleType);
setCorbaType(corbaEnum);
}
示例9
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;
}