use of org.apache.ws.commons.schema.XmlSchemaElement in project ddf by codice.
the class TestGenericFeatureConverter method buildSchemaElement.
private XmlSchemaElement buildSchemaElement(String elementName, XmlSchema schema, QName typeName) {
XmlSchemaElement element = new XmlSchemaElement(schema, true);
element.setSchemaType(new XmlSchemaSimpleType(schema, false));
element.setSchemaTypeName(typeName);
element.setName(elementName);
return element;
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project tdi-studio-se by Talend.
the class AllTypeDialog method buildParameterFromCollection.
private void buildParameterFromCollection(XmlSchemaObjectCollection xmlSchemaObjectCollection, ParameterInfo parameter) {
// 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);
}
} 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);
Long min = xmlSchemaElement.getMinOccurs();
Long max = xmlSchemaElement.getMaxOccurs();
if (max - min > 1) {
parameterSon.setArraySize(-1);
parameterSon.setIndex("*");
}
parameter.getParameterInfos().add(parameterSon);
if (xmlSchemaElement.getSchemaTypeName() != null) {
String elementTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
if (elementTypeName != null && elementTypeName.equals("anyType")) {
parameterSon.setName(xmlSchemaElement.getName() + ":anyType");
}
parameterSon.setType(elementTypeName);
if (!WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buileParameterFromTypes(elementTypeName, parameterSon);
}
} 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) {
buildParameterFromCollection(childCollection, parameterSon);
}
} else if (xmlSchemaElement.getSchemaTypeName() != null) {
String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
if (paraTypeName != null) {
parameter.setType(paraTypeName);
buileParameterFromTypes(paraTypeName, parameterSon);
}
}
} 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(xmlSchemaElement.getName() + "(anyType)");
pSon.setParent(parameter);
parameter.getParameterInfos().add(pSon);
}
parameter.setType(typeName);
}
} else if (xmlSchemaElement.getRefName() != null) {
String elementTypeName = xmlSchemaElement.getRefName().getLocalPart();
if (!WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buildParameterFromElements(elementTypeName, parameterSon);
}
}
} 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);
if (xmlSchemaAttribute.getSchemaTypeName() != null) {
String elementTypeName = xmlSchemaAttribute.getSchemaTypeName().getLocalPart();
parameterSon.setType(elementTypeName);
if (!WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buileParameterFromTypes(elementTypeName, parameterSon);
}
} else if (xmlSchemaAttribute.getRefName() != null) {
String refName = xmlSchemaAttribute.getRefName().getLocalPart();
parameterSon.setType(refName);
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project tdi-studio-se by Talend.
the class ComponentBuilder method buildParameterFromElements.
private void buildParameterFromElements(String partElement, ParameterInfo parameterRoot, int ioOrRecursion) {
// XmlSchemaObjectTable elements = xmlSchema.getElements();
if (ioOrRecursion < 3) {
parametersName.clear();
parametersName.add(parameterRoot.getName());
} else if (ioOrRecursion == 3) {
parametersName.add(parameterRoot.getName());
}
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, ioOrRecursion);
}
} else if (xmlSchemaElement.getSchemaTypeName() != null) {
String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
if (paraTypeName != null) {
parameterRoot.setType(paraTypeName);
buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterRoot, ioOrRecursion);
}
}
} 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("anyType");
parameterSon.setParent(parameterRoot);
parameterRoot.getParameterInfos().add(parameterSon);
}
parameterRoot.setType(typeName);
}
} else if (xmlSchemaElement.getSchemaTypeName() != null) {
String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
if (paraTypeName != null) {
parameterRoot.setType(paraTypeName);
buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterRoot, ioOrRecursion);
}
}
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaElement in project tdi-studio-se by Talend.
the class ComponentBuilder method buildParameterFromCollection2.
private void buildParameterFromCollection2(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);
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();
parameterSon.setType(elementTypeName);
if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
buileParameterFromTypes2(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();
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 ComponentBuilderTest method testBuildParameterFromTypes.
@Test
public void testBuildParameterFromTypes() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, WSDLException {
ParameterInfo parameter = new ParameterInfo();
String name = "parameter";
String nameSpace = "http://parameter";
parameter.setName(name);
parameter.setNameSpace(nameSpace);
ComponentBuilder cb = new ComponentBuilder();
Field field = cb.getClass().getDeclaredField("allXmlSchemaType");
field.setAccessible(true);
List<XmlSchemaType> allXmlSchemaType = (List<XmlSchemaType>) field.get(cb);
XmlSchema first = new XmlSchema();
first.setId("first");
XmlSchemaSimpleType xsst = new XmlSchemaSimpleType(first);
xsst.setId("first");
xsst.setName("first");
xsst.setSourceURI("http://first");
XmlSchema two = new XmlSchema();
two.setId("two");
two.setTargetNamespace(nameSpace);
String nameSpaceTwo = "http://parameter";
XmlSchemaComplexType xsc = new XmlSchemaComplexType(two);
XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
xmlSchemaSequence.setId("sequence");
XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
xmlSchemaElement.setSourceURI(nameSpaceTwo);
xmlSchemaElement.setQName(new QName(nameSpaceTwo, "parameter"));
xmlSchemaElement.setName(name);
xmlSchemaSequence.getItems().add(xmlSchemaElement);
xsc.setParticle(xmlSchemaSequence);
xsc.setId("two");
xsc.setName("parameter");
XmlSchemaComplexContent contentModel = new XmlSchemaComplexContent();
XmlSchemaComplexContentExtension xmlSchemaContent = new XmlSchemaComplexContentExtension();
xmlSchemaContent.setId("two");
xmlSchemaContent.setBaseTypeName(new QName(nameSpace, "two"));
xmlSchemaContent.setSourceURI(nameSpaceTwo);
contentModel.setSourceURI(nameSpace);
contentModel.setContent(xmlSchemaContent);
xsc.setContentModel(contentModel);
allXmlSchemaType.add(xsst);
allXmlSchemaType.add(xsc);
Method m = cb.getClass().getDeclaredMethod("buileParameterFromTypes", new Class[] { String.class, String.class, ParameterInfo.class, int.class });
m.setAccessible(true);
m.invoke(cb, nameSpace, name, parameter, 5);
ParameterInfo parameterInfo = parameter.getParameterInfos().get(0);
Assert.assertNotNull(parameterInfo);
Assert.assertEquals(nameSpace, parameterInfo.getNameSpace());
}
Aggregations