Java源码示例:org.apache.ws.commons.schema.XmlSchemaType
示例1
protected void checkForElement(ServiceInfo serviceInfo, MessagePartInfo mpi) {
SchemaInfo si = getOrCreateSchema(serviceInfo, mpi.getElementQName().getNamespaceURI(),
getQualifyWrapperSchema());
XmlSchemaElement e = si.getSchema().getElementByName(mpi.getElementQName().getLocalPart());
if (e != null) {
mpi.setXmlSchema(e);
return;
}
XmlSchema schema = si.getSchema();
si.setElement(null); //cached element is now invalid
XmlSchemaElement el = new XmlSchemaElement(schema, true);
el.setName(mpi.getElementQName().getLocalPart());
el.setNillable(true);
XmlSchemaType tp = (XmlSchemaType)mpi.getXmlSchema();
if (tp == null) {
throw new ServiceConstructionException(new Message("INTRACTABLE_PART", LOG,
mpi.getName(),
mpi.getMessageInfo().getName()));
}
el.setSchemaTypeName(tp.getQName());
mpi.setXmlSchema(el);
}
示例2
/**
* Determines whether the schema has already received (cross) imports for the schemaType
*
* @param schema
* @param schemaType
* @return false if cross imports for schemaType must still be added to schema
*/
private boolean crossImportsAdded(XmlSchema schema, XmlSchemaType schemaType) {
boolean result = true;
if (schemaType != null) {
Set<XmlSchemaType> xmlTypesCheckedForCrossImports;
if (!xmlTypesCheckedForCrossImportsPerSchema.containsKey(schema)) {
xmlTypesCheckedForCrossImports = new HashSet<>();
xmlTypesCheckedForCrossImportsPerSchema.put(schema, xmlTypesCheckedForCrossImports);
} else {
xmlTypesCheckedForCrossImports = xmlTypesCheckedForCrossImportsPerSchema.get(schema);
}
if (!xmlTypesCheckedForCrossImports.contains(schemaType)) {
// cross imports for this schemaType have not yet been added
xmlTypesCheckedForCrossImports.add(schemaType);
result = false;
}
}
return result;
}
示例3
private Anonarray generateCorbaAnonarray(String name, Long size,
CorbaType type, XmlSchemaType stype, Scope fQName) {
Anonarray anonarray = new Anonarray();
anonarray.setQName(new QName(typeMap.getTargetNamespace(), name));
anonarray.setBound(size);
anonarray.setType(stype.getQName());
//REVISIT, if we add qualification option, then change below.
anonarray.setElemname(new QName("", ELEMENT_NAME));
if (type != null) {
anonarray.setElemtype(type.getQName());
} else {
ArrayDeferredAction anonarrayAction =
new ArrayDeferredAction(anonarray);
wsdlVisitor.getDeferredActions().add(fQName, anonarrayAction);
}
return anonarray;
}
示例4
private CorbaType generateCorbaSequence(CorbaType ctype,
XmlSchemaType schemaType,
Scope scopedName,
long bound,
Scope fullyQualifiedName) {
//create the corba sequence
Sequence corbaSeq = new Sequence();
if (bound == -1) {
bound = 0;
}
corbaSeq.setBound(bound);
corbaSeq.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
corbaSeq.setType(schemaType.getQName());
//REVISIT, if we add qualification then change the below.
corbaSeq.setElemname(new QName("", ELEMENT_NAME));
if (ctype != null) {
corbaSeq.setElemtype(ctype.getQName());
} else {
SequenceDeferredAction seqAction =
new SequenceDeferredAction(corbaSeq);
wsdlVisitor.getDeferredActions().add(fullyQualifiedName, seqAction);
}
corbaSeq.setRepositoryID(scopedName.toIDLRepositoryID());
return corbaSeq;
}
示例5
private NeutralSchema parse(XmlSchemaType type, String name, XmlSchema schema) {
NeutralSchema prior = partialSchemas.get(type);
if (prior != null) {
// we already have a schema of this type
NeutralSchema nSchema = getSchemaFactory().copySchema(prior);
return nSchema;
}
if (type instanceof XmlSchemaComplexType) {
NeutralSchema complexSchema = getSchemaFactory().createSchema(name);
partialSchemas.put(type, complexSchema); // avoid infinite recursion in self-referential
// schemas
return parseComplexType((XmlSchemaComplexType) type, complexSchema, schema);
} else if (type instanceof XmlSchemaSimpleType) {
return parseSimpleType((XmlSchemaSimpleType) type, schema, name);
} else {
throw new RuntimeException("Unsupported schema type: " + type.getClass().getCanonicalName());
}
}
示例6
private XmlSchemaElement createXmlSchemaElement(AST memberNode,
XmlSchemaType schemaType,
Scope fqName) {
// xmlschema:member
XmlSchemaElement member = new XmlSchemaElement(schema, false);
String memberName = memberNode.toString();
member.setName(memberName);
member.setSchemaType(schemaType);
if (schemaType != null) {
member.setSchemaTypeName(schemaType.getQName());
if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
member.setNillable(true);
}
} else {
wsdlVisitor.getDeferredActions().
add(fqName, new StructDeferredAction(member));
}
return member;
}
示例7
private void addCrossImportsType(XmlSchema schema, XmlSchemaType schemaType) {
// the base type might cross schemas.
if (schemaType instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = (XmlSchemaComplexType)schemaType;
XmlSchemaUtils.addImportIfNeeded(schema, complexType.getBaseSchemaTypeName());
addCrossImports(schema, complexType.getContentModel());
addCrossImportsAttributeList(schema, complexType.getAttributes());
// could it be a choice or something else?
if (complexType.getParticle() instanceof XmlSchemaChoice) {
XmlSchemaChoice choice = (XmlSchemaChoice)complexType.getParticle();
addCrossImports(schema, choice);
} else if (complexType.getParticle() instanceof XmlSchemaAll) {
XmlSchemaAll all = (XmlSchemaAll)complexType.getParticle();
addCrossImports(schema, all);
} else if (complexType.getParticle() instanceof XmlSchemaSequence) {
XmlSchemaSequence sequence = (XmlSchemaSequence)complexType.getParticle();
addCrossImports(schema, sequence);
}
}
}
示例8
private static CorbaType getCorbaSchemaType(XmlSchema xmlSchema,
TypeMappingType typeMap,
XmlSchemaType stype,
Scope scopedName) {
CorbaType ctype = null;
if (stype.getQName().equals(Constants.XSD_STRING)) {
ctype = new CorbaType();
ctype.setName(CorbaConstants.NT_CORBA_STRING.getLocalPart());
ctype.setQName(CorbaConstants.NT_CORBA_STRING);
ctype.setType(Constants.XSD_STRING);
} else {
QName qname = stype.getQName();
ctype = findCorbaTypeForSchemaType(typeMap, qname, scopedName);
}
return ctype;
}
示例9
private void processForwardUnionActions(Scope unionScope) {
if (wsdlVisitor.getDeferredActions() != null) {
DeferredActionCollection deferredActions = wsdlVisitor.getDeferredActions();
List<DeferredAction> list = deferredActions.getActions(unionScope);
if ((list != null) && !list.isEmpty()) {
XmlSchemaType stype = getSchemaType();
CorbaType ctype = getCorbaType();
Iterator<DeferredAction> iterator = list.iterator();
while (iterator.hasNext()) {
SchemaDeferredAction action = (SchemaDeferredAction)iterator.next();
action.execute(stype, ctype);
}
iterator = list.iterator();
while (iterator.hasNext()) {
iterator.next();
iterator.remove();
}
}
}
}
示例10
private void addType(QName typeQName, XmlSchemaType type) {
// skip built in xml schema types
if (XML_SCHEMA_NS.equals(typeQName.getNamespaceURI())) {
return;
}
XmlTypeInfo typeInfo = createXmlTypeInfo(typeQName, type);
xmlTypes.put(typeQName, typeInfo);
if (type instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
// process elements nested inside of this element
List<XmlSchemaElement> elements = getNestedElements(complexType);
for (XmlSchemaElement element : elements) {
addNestedElement(element, typeInfo);
}
}
}
示例11
private XmlSchemaElement addElement(XmlSchemaSequence schemaSequence,
XmlSchemaType schemaType,
Scope fqName,
String name) {
XmlSchemaElement element = new XmlSchemaElement(schema, false);
element.setName(name);
if (schemaType != null) {
element.setSchemaTypeName(schemaType.getQName());
if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
element.setNillable(true);
}
} else {
wsdlVisitor.getDeferredActions().
add(fqName, new OperationDeferredAction(element));
}
schemaSequence.getItems().add(element);
return element;
}
示例12
private void visitOpTypeSpec(AST node, XmlSchemaSequence outputWrappingSequence) {
if (node.getType() == IDLTokenTypes.LITERAL_void) {
// nothing to do here, move along
return;
}
ParamTypeSpecVisitor visitor = new ParamTypeSpecVisitor(getScope(),
definition,
schema,
wsdlVisitor);
visitor.visit(node);
XmlSchemaType schemaType = visitor.getSchemaType();
CorbaTypeImpl corbaType = visitor.getCorbaType();
Scope fqName = visitor.getFullyQualifiedName();
addElement(outputWrappingSequence, schemaType, fqName, RETURN_PARAMETER);
addCorbaReturn(corbaType, fqName, RETURN_PARAMETER);
}
示例13
public void visit(AST fixedNode) {
// <fixed_pt_const_type> ::= "fixed"
XmlSchemaType stype = null;
CorbaType ctype = null;
QName corbaTypeQName = CorbaConstants.NE_CORBA_FIXED;
if (corbaTypeQName != null) {
QName schemaTypeQName = Constants.XSD_DECIMAL;
if (schemaTypeQName != null) {
stype = schemas.getTypeByQName(schemaTypeQName);
if (stype != null) {
ctype = new CorbaType();
ctype.setQName(corbaTypeQName);
ctype.setType(stype.getQName());
ctype.setName(stype.getQName().getLocalPart());
}
}
}
schemaType = stype;
corbaType = ctype;
}
示例14
private void generateAlias(AST identifierNode,
XmlSchemaType schemaType,
CorbaType corbaType,
Scope fqName) {
Scope scopedName = new Scope(getScope(), identifierNode);
// corba:alias
Alias alias = new Alias();
alias.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
if (corbaType != null) {
alias.setBasetype(corbaType.getQName());
// if (schemaType == null) might not be correct here
} else if (schemaType == null) {
wsdlVisitor.getDeferredActions().
add(fqName, new TypedefDeferredAction(alias));
scopedNames.add(scopedName);
}
alias.setRepositoryID(scopedName.toIDLRepositoryID());
// add corba:alias
setCorbaType(alias);
}
示例15
private void generateStringAlias(AST typeDeclaratorNode,
AST identifierNode,
XmlSchemaType schemaType,
CorbaType corbaType,
Scope fqName) {
Scope typedefScope = new Scope(getScope(), identifierNode);
Alias corbaString = new Alias();
if (typeDeclaratorNode.getType() == IDLTokenTypes.LITERAL_string) {
corbaString.setBasetype(CorbaConstants.NT_CORBA_STRING);
} else if (typeDeclaratorNode.getType() == IDLTokenTypes.LITERAL_wstring) {
corbaString.setBasetype(CorbaConstants.NT_CORBA_WSTRING);
} else {
// should never get here
throw new RuntimeException("[TypedefVisitor] Attempted to visit an invalid node: "
+ typeDeclaratorNode.toString());
}
Scope newScope = new Scope(typedefScope.getParent(), identifierNode);
corbaString.setQName(new QName(typeMap.getTargetNamespace(), newScope.toString()));
corbaString.setType(Constants.XSD_STRING);
corbaString.setRepositoryID(newScope.toIDLRepositoryID());
typeMap.getStructOrExceptionOrUnion().add(corbaString);
}
示例16
private static QName getSchemaTypeName(WSDLToCorbaBinding wsdlToCorbaBinding, XmlSchemaType schemaType,
XmlSchemaAnnotation annotation, QName typeName, boolean nill)
throws Exception {
QName idltype = null;
CorbaType corbaTypeImpl = null;
corbaTypeImpl = wsdlToCorbaBinding.getHelper().convertSchemaToCorbaType(schemaType, typeName, null,
annotation, false);
if (corbaTypeImpl == null) {
throw new Exception("Couldn't convert schema type to corba type : " + typeName);
}
if (nill) {
QName qname = corbaTypeImpl.getQName();
idltype = wsdlToCorbaBinding.getHelper().createQNameCorbaNamespace(qname.getLocalPart()
+ "_nil");
} else {
idltype = corbaTypeImpl.getQName();
}
return idltype;
}
示例17
public XmlSchemaType getSchemaType(QName name) throws Exception {
XmlSchemaType type = null;
for (XmlSchema xmlSchema : xmlSchemaList.getXmlSchemas()) {
String nspace = name.getNamespaceURI();
if (nspace == null) {
nspace = xmlSchema.getTargetNamespace();
}
//QName tname = createQName(nspace, name.getLocalPart(), "xsd");
QName tname = createQName(nspace, name.getLocalPart(), "");
type = findSchemaType(tname);
if (type != null) {
break;
}
}
return type;
}
示例18
private CorbaType processElementType(XmlSchemaElement stype, QName defaultName, String uri)
throws Exception {
String name = null;
QName schemaTypeName = null;
XmlSchemaType schemaType = stype.getSchemaType();
if (stype.getQName() == null) {
if (stype.getRef().getTargetQName() == null) {
schemaTypeName = defaultName;
} else {
name = stype.getRef().getTargetQName().getLocalPart();
schemaType = findSchemaType(stype.getRef().getTargetQName());
}
} else {
name = stype.getQName().getLocalPart();
}
if (schemaTypeName == null) {
schemaTypeName = createQNameTargetNamespace(name);
}
CorbaType result = convertSchemaToCorbaType(schemaType, schemaTypeName,
schemaType, null, false);
result.setQualified(getElementQualification(stype, uri));
return result;
}
示例19
private XmlSchemaType findTypeInSchema(XmlSchema xmlSchema, QName typeName) {
XmlSchemaType schemaType = null;
if (xmlSchema.getElementByName(typeName) != null) {
XmlSchemaElement schemaElement = xmlSchema.getElementByName(typeName);
schemaType = schemaElement.getSchemaType();
} else if (xmlSchema.getTypeByName(typeName) != null) {
schemaType = xmlSchema.getTypeByName(typeName);
}
if (schemaType != null) {
return schemaType;
}
for (XmlSchemaExternal extSchema : xmlSchema.getExternals()) {
if (!(extSchema instanceof XmlSchemaImport)) {
schemaType = findTypeInSchema(extSchema.getSchema(), typeName);
if (schemaType != null) {
return schemaType;
}
}
}
return null;
}
示例20
private void buildXmlTypeInfos() {
for (XmlSchema schema : xmlSchemaCollection.getXmlSchemas()) {
// Global Elements
for (Iterator iterator = schema.getElements().getValues(); iterator.hasNext(); ) {
XmlSchemaElement globalElement = (XmlSchemaElement) iterator.next();
addGlobalElement(globalElement);
}
// Global Types
for (Iterator iterator = schema.getSchemaTypes().getValues(); iterator.hasNext(); ) {
XmlSchemaType globalType = (XmlSchemaType) iterator.next();
addType(globalType.getQName(), globalType);
}
}
}
示例21
private XmlSchemaType getSourceTypeByQName(QName typeName) throws ParserException {
final XmlSchemaType sourceType = sourceSchemas.getTypeByQName(typeName);
if (sourceType == null) {
throw new ParserException("Missing type in source schemas: " + typeName);
}
return sourceType;
}
示例22
private <T extends XmlSchemaType> void handleTypeNameAndType(final QName typeName, final T type,
final Consumer<QName> setTypeName,
final Consumer<T> setType) throws ParserException {
// set name if set
setTargetTypeQName(typeName, setTypeName);
// set type if set
if (type != null) {
setType.accept(createXmlSchemaObjectBase(type));
}
}
示例23
private void addOneSchemaCrossImports(XmlSchema schema) {
/*
* We need to visit all the top-level items.
*/
for (XmlSchemaElement element : schema.getElements().values()) {
addElementCrossImportsElement(schema, element);
}
for (XmlSchemaAttribute attribute : schema.getAttributes().values()) {
XmlSchemaUtils.addImportIfNeeded(schema, attribute.getRef().getTargetQName());
XmlSchemaUtils.addImportIfNeeded(schema, attribute.getSchemaTypeName());
}
for (XmlSchemaType type : schema.getSchemaTypes().values()) {
addCrossImportsType(schema, type);
}
}
示例24
private boolean validatePartType(String namespace, String name, boolean isElement) {
boolean partvalid = false;
if (namespace.equals(WSDLConstants.NS_SCHEMA_XSD)) {
if (isElement) {
XmlSchemaElement schemaEle =
schemaCollection.getElementByQName(new QName(WSDLConstants.NS_SCHEMA_XSD, name));
partvalid = schemaEle != null ? true : false;
} else {
if ("anyType".equals(name)) {
return true;
}
XmlSchemaType schemaType =
schemaCollection.getTypeByQName(new QName(WSDLConstants.NS_SCHEMA_XSD, name));
partvalid = schemaType != null ? true : false;
}
} else {
if (isElement) {
if (schemaCollection.getElementByQName(new QName(namespace, name)) != null) {
partvalid = true;
}
} else {
if (schemaCollection.getTypeByQName(new QName(namespace, name)) != null) {
partvalid = true;
}
}
}
return partvalid;
}
示例25
public void execute(XmlSchemaType stype, CorbaTypeImpl ctype) {
if (member != null) {
member.setIdltype(ctype.getQName());
}
if (element != null) {
element.setSchemaType(stype);
element.setSchemaTypeName(stype.getQName());
if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
element.setNillable(true);
}
}
}
示例26
public void execute(XmlSchemaType stype, CorbaTypeImpl ctype) {
if (array != null) {
array.setElemtype(ctype.getQName());
}
if (anonarray != null) {
anonarray.setElemtype(ctype.getQName());
}
if (element != null) {
element.setSchemaTypeName(stype.getQName());
if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
element.setNillable(true);
}
}
}
示例27
public String getDefaultValueForSimpleType(XmlSchemaType type) {
String val = DEFAULT_VALUE_FOR_SIMPLE_TYPE.get(type.getName());
if (val == null) { // ints and such return the appropriate 0.
return "''";
}
return val;
}
示例28
private XmlSchemaComplexType generateSchemaArray(Scope scopedName, Long size,
XmlSchemaType type, Scope fQName) {
XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, true);
complexType.setName(mapper.mapToQName(scopedName));
XmlSchemaSequence sequence = new XmlSchemaSequence();
XmlSchemaElement element = new XmlSchemaElement(schema, false);
element.setMinOccurs(size);
element.setMaxOccurs(size);
element.setName(ELEMENT_NAME);
if (type != null) {
element.setSchemaTypeName(type.getQName());
if (type.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
element.setNillable(true);
}
} else {
ArrayDeferredAction arrayAction =
new ArrayDeferredAction(element);
wsdlVisitor.getDeferredActions().add(fQName, arrayAction);
}
sequence.getItems().add(element);
complexType.setParticle(sequence);
return complexType;
}
示例29
private String getElementObjectName(ParticleInfo element) {
XmlSchemaType type = element.getType();
if (!element.isEmpty()) {
if (type instanceof XmlSchemaComplexType) {
return nameManager.getJavascriptName(element.getControllingName());
}
return "type " + type.getQName(); // could it be anonymous?
}
return "empty element?";
}
示例30
private void parseDocumentation(NeutralSchema neutralSchema, XmlSchemaType schemaType) {
XmlSchemaObjectCollection annotations = schemaType.getAnnotation().getItems();
for (int annotationIdx = 0; annotationIdx < annotations.getCount(); ++annotationIdx) {
XmlSchemaObject annotation = annotations.getItem(annotationIdx);
if (annotation instanceof XmlSchemaDocumentation) {
XmlSchemaDocumentation docs = (XmlSchemaDocumentation) annotation;
neutralSchema.addAnnotation(new Documentation(docs.getMarkup()));
}
}
}