use of org.apache.ws.commons.schema.XmlSchemaElement in project tdi-studio-se by Talend.
the class ComponentBuilder method collectAllXmlSchemaElement.
/**
* DOC gcui Comment method "collectAllElement".
*
* @return
*/
private void collectAllXmlSchemaElement() {
for (int i = 0; i < wsdlTypes.size(); i++) {
XmlSchema xmlSchema = (wsdlTypes.elementAt(i));
if (xmlSchema == null) {
continue;
}
XmlSchemaObjectTable elements = xmlSchema.getElements();
Iterator elementsItr = elements.getValues();
while (elementsItr.hasNext()) {
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) elementsItr.next();
allXmlSchemaElement.add(xmlSchemaElement);
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project tdi-studio-se by Talend.
the class ComponentBuilder method buildParameterFromCollection.
private void buildParameterFromCollection(XmlSchemaObjectCollection xmlSchemaObjectCollection, ParameterInfo parameter, int ioOrRecursion) {
// XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) xmlSchemaParticle;
// XmlSchemaObjectCollection xmlSchemaObjectCollection = xmlSchemaSequence.getItems();
int count = xmlSchemaObjectCollection.getCount();
for (int j = 0; j < count; j++) {
XmlSchemaObject xmlSchemaObject = xmlSchemaObjectCollection.getItem(j);
if (xmlSchemaObject instanceof XmlSchemaGroupBase) {
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaObject;
XmlSchemaObjectCollection items = xmlSchemaGroupBase.getItems();
if (items != null) {
buildParameterFromCollection(items, parameter, ioOrRecursion);
}
} else if (xmlSchemaObject instanceof XmlSchemaAny) {
ParameterInfo parameterSon = new ParameterInfo();
parameterSon.setName("_content_");
parameterSon.setParent(parameter);
parameter.getParameterInfos().add(parameterSon);
} else if (xmlSchemaObject instanceof XmlSchemaElement) {
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) xmlSchemaObject;
String elementName = xmlSchemaElement.getName();
ParameterInfo parameterSon = new ParameterInfo();
parameterSon.setName(elementName);
parameterSon.setParent(parameter);
if (((XmlSchemaElement) xmlSchemaObject).getQName() != null) {
parameterSon.setNameSpace(((XmlSchemaElement) xmlSchemaObject).getQName().getNamespaceURI());
}
Long min = xmlSchemaElement.getMinOccurs();
Long max = xmlSchemaElement.getMaxOccurs();
if (max - min > 1) {
parameterSon.setArraySize(-1);
parameterSon.setIndex("*");
}
parameter.getParameterInfos().add(parameterSon);
Boolean isHave = false;
if (!parametersName.isEmpty() && parameterSon.getName() != null) {
for (int p = 0; p < parametersName.size(); p++) {
if (parameterSon.getName().equals(parametersName.get(p))) {
isHave = true;
}
}
}
// }
if (xmlSchemaElement.getSchemaTypeName() != null) {
String elementTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
String elementTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
if (elementTypeName != null && elementTypeName.equals("anyType")) {
parameterSon.setName(xmlSchemaElement.getName() + ":anyType");
}
parameterSon.setType(elementTypeName);
parameterSon.setNameSpace(xmlSchemaElement.getQName().getNamespaceURI());
if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buileParameterFromTypes(elementTypeNamespace, elementTypeName, parameterSon, ioOrRecursion);
}
} else if (xmlSchemaElement.getSchemaType() != null) {
if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaComplexType) {
XmlSchemaComplexType xmlElementComplexType = (XmlSchemaComplexType) xmlSchemaElement.getSchemaType();
XmlSchemaParticle xmlSchemaParticle = xmlElementComplexType.getParticle();
if (xmlSchemaParticle instanceof XmlSchemaGroupBase) {
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaParticle;
XmlSchemaObjectCollection childCollection = xmlSchemaGroupBase.getItems();
if (childCollection != null && !isHave) {
buildParameterFromCollection(childCollection, parameterSon, ioOrRecursion);
}
} else if (xmlSchemaElement.getSchemaTypeName() != null) {
String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
if (paraTypeName != null && !isHave) {
parameter.setType(paraTypeName);
buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterSon, ioOrRecursion);
}
}
} else if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) xmlSchemaElement.getSchemaType();
String typeName = xmlSchemaSimpleType.getName();
if (typeName != null && typeName.equals("anyType")) {
ParameterInfo pSon = new ParameterInfo();
pSon.setName("anyType");
pSon.setParent(parameter);
parameter.getParameterInfos().add(pSon);
}
parameter.setType(typeName);
}
} else if (xmlSchemaElement.getRefName() != null) {
String elementTypeName = xmlSchemaElement.getRefName().getLocalPart();
if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buildParameterFromElements(elementTypeName, parameterSon, ioOrRecursion);
}
}
} else if (xmlSchemaObject instanceof XmlSchemaAttribute) {
XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute) xmlSchemaObject;
String elementName = xmlSchemaAttribute.getName();
ParameterInfo parameterSon = new ParameterInfo();
parameterSon.setName(elementName);
parameterSon.setParent(parameter);
parameter.getParameterInfos().add(parameterSon);
Boolean isHave = false;
if (!parametersName.isEmpty() && parameterSon.getName() != null) {
for (int p = 0; p < parametersName.size(); p++) {
if (parameterSon.getName().equals(parametersName.get(p))) {
isHave = true;
}
}
}
if (xmlSchemaAttribute.getSchemaTypeName() != null) {
String elementTypeName = xmlSchemaAttribute.getSchemaTypeName().getLocalPart();
String elementTypeNamespace = xmlSchemaAttribute.getSchemaTypeName().getNamespaceURI();
parameterSon.setType(elementTypeName);
if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buileParameterFromTypes(elementTypeNamespace, elementTypeName, parameterSon, ioOrRecursion);
}
} else if (xmlSchemaAttribute.getRefName() != null) {
String refName = xmlSchemaAttribute.getRefName().getLocalPart();
parameterSon.setType(refName);
if (!isHave) {
buildParameterFromElements(refName, parameterSon, ioOrRecursion);
}
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project tdi-studio-se by Talend.
the class AllTypeDialog method buildParameterFromElements.
private void buildParameterFromElements(String partElement, ParameterInfo parameterRoot) {
// XmlSchemaObjectTable elements = xmlSchema.getElements();
Iterator elementsItr = allXmlSchemaElement.iterator();
if (partElement != null) {
while (elementsItr.hasNext()) {
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) elementsItr.next();
if (partElement.equals(xmlSchemaElement.getName())) {
// parameter.setName(partName);
if (xmlSchemaElement.getSchemaType() != null) {
if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaComplexType) {
XmlSchemaComplexType xmlElementComplexType = (XmlSchemaComplexType) xmlSchemaElement.getSchemaType();
XmlSchemaParticle xmlSchemaParticle = xmlElementComplexType.getParticle();
if (xmlSchemaParticle instanceof XmlSchemaGroupBase) {
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaParticle;
XmlSchemaObjectCollection xmlSchemaObjectCollection = xmlSchemaGroupBase.getItems();
if (xmlSchemaObjectCollection != null) {
buildParameterFromCollection(xmlSchemaObjectCollection, parameterRoot);
}
} else if (xmlSchemaElement.getSchemaTypeName() != null) {
String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
if (paraTypeName != null) {
parameterRoot.setType(paraTypeName);
buileParameterFromTypes(paraTypeName, parameterRoot);
}
}
} else if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) xmlSchemaElement.getSchemaType();
String typeName = xmlSchemaSimpleType.getName();
if (typeName != null && typeName.equals("anyType")) {
ParameterInfo parameterSon = new ParameterInfo();
parameterSon.setName(xmlSchemaElement.getName() + "(anyType)");
parameterSon.setParent(parameterRoot);
parameterRoot.getParameterInfos().add(parameterSon);
}
parameterRoot.setType(typeName);
}
} else if (xmlSchemaElement.getSchemaTypeName() != null) {
String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
if (paraTypeName != null) {
parameterRoot.setType(paraTypeName);
buileParameterFromTypes(paraTypeName, parameterRoot);
}
}
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.
the class WSDLToCorbaBinding method addCorbaElements.
private void addCorbaElements(CorbaType corbaTypeImpl, XmlSchema xmlSchemaTypes) throws Exception {
Map<QName, XmlSchemaElement> elements = xmlSchemaTypes.getElements();
for (XmlSchemaElement el : elements.values()) {
QName elName = el.getQName();
XmlSchemaType schemaType = el.getSchemaType();
if (elName == null) {
elName = el.getRef().getTargetQName();
schemaType = helper.getSchemaType(elName);
}
boolean anonymous = false;
if (schemaType == null) {
anonymous = true;
} else {
anonymous = WSDLTypes.isAnonymous(schemaType.getName());
}
if (schemaType != null) {
XmlSchemaAnnotation annotation = null;
if (el.getAnnotation() != null) {
annotation = el.getAnnotation();
}
// this situation won't be handled. REVISIT.
if (annotation != null) {
XmlSchemaAppInfo appInfo = null;
for (XmlSchemaAnnotationItem ann : annotation.getItems()) {
if (ann instanceof XmlSchemaAppInfo) {
appInfo = (XmlSchemaAppInfo) ann;
break;
}
}
if (appInfo != null) {
NodeList nlist = appInfo.getMarkup();
Node node = nlist.item(0);
String info = node.getNodeValue();
info = info.trim();
String annotationBindingName = "";
if ("corba:binding=".equals(info.substring(0, 14))) {
annotationBindingName = info.substring(14);
}
if (bindingName.equals(annotationBindingName)) {
annotation = null;
}
}
}
corbaTypeImpl = helper.convertSchemaToCorbaType(schemaType, elName, schemaType, annotation, anonymous);
if (el.isNillable()) {
QName uname = helper.createQNameCorbaNamespace(corbaTypeImpl.getQName().getLocalPart() + "_nil");
boolean isQualified = corbaTypeImpl.isSetQualified() && corbaTypeImpl.isQualified();
corbaTypeImpl = helper.createNillableUnion(uname, helper.checkPrefix(elName), helper.checkPrefix(corbaTypeImpl.getQName()), isQualified);
}
if (corbaTypeImpl != null && !helper.isDuplicate(corbaTypeImpl)) {
typeMappingType.getStructOrExceptionOrUnion().add(corbaTypeImpl);
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project hale by halestudio.
the class XmlSchemaReader method loadSchema.
/**
* Load the feature types defined by the given schema
*
* @param schemaLocation the schema location
* @param xmlSchema the schema
* @param imports the imports/includes that were already loaded or where
* loading has been started
* @param progress the progress indicator
* @param mainSchema states if this is a main schema and therefore elements
* declared here should be flagged mappable
*/
protected void loadSchema(String schemaLocation, XmlSchema xmlSchema, Set<String> imports, ProgressIndicator progress, boolean mainSchema) {
String namespace = xmlSchema.getTargetNamespace();
if (namespace == null) {
namespace = XMLConstants.NULL_NS_URI;
}
// add namespace prefixes
NamespacePrefixList namespaces = xmlSchema.getNamespaceContext();
addPrefixes(namespaces, namespace, mainSchema);
// the schema items
XmlSchemaObjectCollection items = xmlSchema.getItems();
// go through all schema items
for (int i = 0; i < items.getCount(); i++) {
XmlSchemaObject item = items.getItem(i);
if (item instanceof XmlSchemaElement) {
// global element declaration
XmlSchemaElement element = (XmlSchemaElement) item;
// determine type
XmlTypeDefinition elementType = null;
if (element.getSchemaTypeName() != null) {
// reference to type
elementType = index.getOrCreateType(element.getSchemaTypeName());
} else if (element.getSchemaType() != null) {
// element has internal type definition, generate anonymous
// type name
QName typeName = new QName(element.getQName().getNamespaceURI(), // $NON-NLS-1$
element.getQName().getLocalPart() + "_AnonymousType");
// create type
elementType = createType(element.getSchemaType(), typeName, schemaLocation, namespace, mainSchema);
} else if (element.getQName() != null) {
// element with no type
elementType = index.getOrCreateType(XmlTypeUtil.NAME_ANY_TYPE);
}
if (elementType != null) {
// the element name
// XXX use element QName instead?
QName elementName = new QName(namespace, element.getName());
// the substitution group
QName subGroup = element.getSubstitutionGroup();
// TODO do we also need an index for substitutions?
// create schema element
XmlElement schemaElement = new XmlElement(elementName, elementType, subGroup);
// set metadata
setMetadata(schemaElement, element, schemaLocation);
// extend XmlElements constraint
XmlElements xmlElements = elementType.getConstraint(XmlElements.class);
xmlElements.addElement(schemaElement);
// set custom display name
elementType.setConstraint(new ElementName(xmlElements));
// set Mappable constraint (e.g. Mappable)
// for types with an associated element it can be determined
// on the spot if it is mappable
configureMappingRelevant(elementType, mainSchema);
// XXX needed? may result in conflicts when defining
// mappable types manually XXX the element is also marked
// with the Mappable constraint, to help with cases where
// multiple elements are defined for one
// schemaElement.setConstraint(MappableFlag.get(mainSchema));
// store element in index
index.getElements().put(elementName, schemaElement);
} else {
reporter.error(new IOMessageImpl(MessageFormat.format("No type for element {0} found.", element.getName()), null, element.getLineNumber(), element.getLinePosition()));
}
} else if (item instanceof XmlSchemaType) {
// complex or simple type
createType((XmlSchemaType) item, null, schemaLocation, namespace, mainSchema);
} else if (item instanceof XmlSchemaAttribute) {
// schema attribute that might be referenced somewhere
XmlSchemaAttribute att = (XmlSchemaAttribute) item;
if (att.getQName() != null) {
XmlTypeDefinition type = getAttributeType(att, null, schemaLocation);
if (type == null) {
// XXX if this occurs we might need a attribute
// referencing attribute
reporter.error(new IOMessageImpl("Could not determine attribute type", null, att.getLineNumber(), att.getLinePosition()));
} else {
XmlAttribute attribute = new XmlAttribute(att.getQName(), type);
index.getAttributes().put(attribute.getName(), attribute);
}
} else {
reporter.warn(new IOMessageImpl(MessageFormat.format("Attribute could not be processed: {0}", att.getName()), null, att.getLineNumber(), att.getLinePosition()));
}
} else if (item instanceof XmlSchemaAttributeGroup) {
// schema attribute group that might be referenced somewhere
XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup) item;
if (attributeGroup.getName() != null) {
String groupIdent = attributeGroup.getName().getNamespaceURI() + "/" + attributeGroup.getName().getLocalPart();
XmlAttributeGroup attGroup = new XmlAttributeGroup(groupIdent, true);
createAttributes(attributeGroup, attGroup, "", schemaLocation, namespace);
index.getAttributeGroups().put(attributeGroup.getName(), attGroup);
} else {
reporter.warn(new IOMessageImpl("Attribute group could not be processed", null, attributeGroup.getLineNumber(), attributeGroup.getLinePosition()));
}
} else if (item instanceof XmlSchemaGroup) {
// group that might be referenced somewhere
XmlSchemaGroup schemaGroup = (XmlSchemaGroup) item;
if (schemaGroup.getName() != null) {
String groupIdent = schemaGroup.getName().getNamespaceURI() + "/" + schemaGroup.getName().getLocalPart();
XmlGroup group = new XmlGroup(groupIdent, true);
createPropertiesFromParticle(group, schemaGroup.getParticle(), schemaLocation, namespace, false);
index.getGroups().put(schemaGroup.getName(), group);
} else {
reporter.warn(new IOMessageImpl("Group could not be processed", null, schemaGroup.getLineNumber(), schemaGroup.getLinePosition()));
}
} else if (item instanceof XmlSchemaImport || item instanceof XmlSchemaInclude) {
// ignore, is treated separately
} else if (item instanceof XmlSchemaNotation) {
// notations are ignored
} else {
reporter.error(new IOMessageImpl("Unrecognized global definition: " + item.getClass().getSimpleName(), null, item.getLineNumber(), item.getLinePosition()));
}
}
// Set of include locations
Set<String> includes = new HashSet<String>();
// handle imports
XmlSchemaObjectCollection externalItems = xmlSchema.getIncludes();
if (externalItems.getCount() > 0) {
// $NON-NLS-1$
_log.info("Loading includes and imports for schema at " + schemaLocation);
}
for (int i = 0; i < externalItems.getCount(); i++) {
try {
XmlSchemaExternal imp = (XmlSchemaExternal) externalItems.getItem(i);
XmlSchema importedSchema = imp.getSchema();
String location = importedSchema.getSourceURI();
if (!(imports.contains(location))) {
// only add schemas that
// were not already
// added
// place a marker in the map to
imports.add(location);
// prevent loading the location in
// the call to loadSchema
loadSchema(location, importedSchema, imports, progress, mainSchema && imp instanceof XmlSchemaInclude);
// is part of main schema if it's a main schema include
}
if (imp instanceof XmlSchemaInclude) {
includes.add(location);
}
} catch (Throwable e) {
reporter.error(new IOMessageImpl("Error adding imported schema from " + schemaLocation, // $NON-NLS-1$
e));
}
}
// $NON-NLS-1$
_log.info("Creating types for schema at " + schemaLocation);
progress.setCurrentTask(// $NON-NLS-1$
MessageFormat.format(Messages.getString("ApacheSchemaProvider.33"), namespace));
}
Aggregations