use of org.apache.ws.commons.schema.XmlSchemaAny in project convertigo by convertigo.
the class XmlSchemaWalker method walkChoice.
protected void walkChoice(XmlSchema xmlSchema, XmlSchemaChoice obj) {
walkAnnotated(xmlSchema, obj);
XmlSchemaObjectCollection children = obj.getItems();
for (int i = 0; i < children.getCount(); i++) {
XmlSchemaObject child = children.getItem(i);
if (child instanceof XmlSchemaElement) {
walkElement(xmlSchema, (XmlSchemaElement) child);
} else if (child instanceof XmlSchemaGroupRef) {
walkGroupRef(xmlSchema, (XmlSchemaGroupRef) child);
} else if (child instanceof XmlSchemaChoice) {
walkChoice(xmlSchema, (XmlSchemaChoice) child);
} else if (child instanceof XmlSchemaSequence) {
walkSequence(xmlSchema, (XmlSchemaSequence) child);
} else if (child instanceof XmlSchemaAny) {
walkAny(xmlSchema, (XmlSchemaAny) child);
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaAny in project convertigo by convertigo.
the class JsonSchemaUtils method getOasSchema.
protected static JSONObject getOasSchema(XmlSchemaCollection xmlSchemaCollection, XmlSchema xmlSchema, String oasDirUrl, boolean isOas2) {
final NamespaceMap nsMap = (NamespaceMap) xmlSchemaCollection.getNamespaceContext();
final JSONObject jsonSchema = new JSONObject();
try {
String prefix = nsMap.getPrefix(xmlSchema.getTargetNamespace());
jsonSchema.put("id", oasDirUrl + prefix + ".jsonschema#");
jsonSchema.put("ns", xmlSchema.getTargetNamespace());
jsonSchema.put("definitions", new JSONObject());
new XmlSchemaWalker(false, false) {
final Map<String, JSONObject> refs = new HashMap<String, JSONObject>(50);
final JSONObject definitions = jsonSchema.getJSONObject("definitions");
JSONObject parent = definitions;
JSONObject root = null;
private boolean isGlobal(JSONObject jParent) {
if (jParent != null) {
return jParent.equals(definitions);
}
return false;
}
private JSONObject getRefObject(String ref) throws JSONException {
JSONObject refObject = refs.get(ref);
if (refObject != null) {
if (!refObject.has("value") && !refObject.equals(root)) {
handle(refObject);
}
if (refObject.has("value")) {
JSONObject value = refObject.getJSONObject("value");
if (value.has("type") && !value.getString("type").equals("object")) {
JSONObject ob = new JSONObject();
copyOKeys(value, ob);
return ob;
}
}
}
return new JSONObject().put("$ref", ref);
}
private String normalize(String key) {
return key.replaceAll("[^a-zA-Z0-9]", "x");
}
private void addGlobalObject(JSONObject jParent, JSONObject jElement, String key) throws JSONException {
if (jParent != null) {
jParent.put(normalize(key), jElement);
refs.put(jElement.getString("objKey"), jElement);
}
}
private String toOasType(String baseType) {
String oasType = baseType;
switch(baseType) {
case "NMTOKEN":
case "token":
case "IDREF":
case "ID":
oasType = "string";
break;
case "dateTime":
oasType = "string";
break;
case "decimal":
oasType = "number";
break;
case "byte":
case "int":
case "short":
case "nonNegativeInteger":
case "positiveInteger":
oasType = "integer";
break;
}
return oasType;
}
private String getDefinitionRef(QName rname) {
if (rname != null) {
String local = rname.getLocalPart();
String ns = rname.getNamespaceURI();
return oasDirUrl + nsMap.getPrefix(ns) + ".jsonschema#/definitions/" + normalize(local);
}
return null;
}
private void addChild(JSONObject jParent, JSONObject jElement) throws JSONException {
if (!jParent.has("children")) {
jParent.put("children", new JSONArray());
}
jParent.getJSONArray("children").put(jElement);
}
private void handleElement(JSONObject jsonOb, JSONObject jsonChild, long minItems, long maxItems) throws JSONException {
if (!jsonOb.has("type")) {
jsonOb.put("type", "object");
}
if (!jsonOb.has("required")) {
jsonOb.put("required", new JSONArray());
}
if (!jsonOb.has("properties")) {
jsonOb.put("properties", new JSONObject());
}
JSONArray required = jsonOb.getJSONArray("required");
JSONObject properties = jsonOb.getJSONObject("properties");
String propertyName = jsonChild.getString("name");
long minOccurs = jsonChild.has("minOccurs") ? jsonChild.getLong("minOccurs") : 0;
long maxOccurs = jsonChild.has("maxOccurs") ? jsonChild.getLong("maxOccurs") : minOccurs;
boolean isRequired = Math.min(minOccurs, minItems) > 0;
boolean isArray = maxOccurs > 1 || maxItems > 1;
JSONObject property = new JSONObject();
// fill required
if (isRequired) {
if (required.join(",").indexOf(propertyName) == -1) {
required.put(propertyName);
}
} else if (!isArray) {
property.put("nullable", true);
}
// fill properties
if (isArray) {
property.put("type", "array");
property.put("minItems", Math.min(minOccurs, minItems));
property.put("maxItems", Math.max(maxOccurs, maxItems));
property.put("items", new JSONObject());
}
JSONObject prop = isArray ? property.getJSONObject("items") : property;
if (jsonChild.has("value")) {
JSONObject value = jsonChild.getJSONObject("value");
@SuppressWarnings("unchecked") Iterator<String> it = value.keys();
while (it.hasNext()) {
String pkey = it.next();
if (!pkey.isEmpty()) {
prop.put(pkey, value.get(pkey));
}
}
} else if (jsonChild.has("children")) {
JSONArray children = jsonChild.getJSONArray("children");
for (int i = 0; i < children.length(); i++) {
JSONObject child = children.getJSONObject(i);
if (!child.has("objType")) {
@SuppressWarnings("unchecked") Iterator<String> it = child.keys();
while (it.hasNext()) {
String pkey = it.next();
if (!pkey.isEmpty()) {
prop.put(pkey, child.get(pkey));
}
}
}
}
}
if (!isRequired && prop.has("$ref")) {
JSONArray allOf = new JSONArray().put(new JSONObject().put("$ref", prop.remove("$ref")));
prop.put("nullable", true).put("allOf", allOf);
}
properties.put(propertyName, property);
// handle children
if (jsonChild.has("children")) {
JSONArray children = jsonChild.getJSONArray("children");
for (int i = 0; i < children.length(); i++) {
JSONObject child = children.getJSONObject(i);
if (child.has("objType")) {
handleChild(prop.has("type") || prop.has("$ref") ? jsonOb : prop, child);
}
}
}
}
private void handleAttribute(JSONObject jsonOb, JSONObject jsonChild, long minItems, long maxItems) throws JSONException {
if (!jsonOb.has("required")) {
jsonOb.put("required", new JSONArray());
}
if (!jsonOb.has("properties")) {
jsonOb.put("properties", new JSONObject());
}
JSONObject attrObject = null;
if (jsonOb.getJSONObject("properties").has("attr")) {
attrObject = jsonOb.getJSONObject("properties").getJSONObject("attr");
} else {
attrObject = new JSONObject().put("type", "object").put("required", new JSONArray()).put("properties", new JSONObject());
jsonOb.getJSONObject("properties").put("attr", attrObject);
}
JSONArray required = attrObject.getJSONArray("required");
JSONObject properties = attrObject.getJSONObject("properties");
String attrName = jsonChild.getString("name");
long minOccurs = jsonChild.has("minOccurs") ? jsonChild.getLong("minOccurs") : 0;
long maxOccurs = jsonChild.has("maxOccurs") ? jsonChild.getLong("maxOccurs") : minOccurs;
boolean isRequired = minOccurs > 0;
boolean isArray = maxOccurs > 1;
// fill required
if (isRequired) {
if (required.join(",").indexOf(attrName) == -1) {
required.put(attrName);
// if attribute is required then attr object is required also
if (jsonOb.getJSONArray("required").join(",").indexOf("attr") == -1) {
jsonOb.getJSONArray("required").put("attr");
}
}
}
// fill properties
JSONObject attribute = new JSONObject();
if (isArray) {
attribute.put("type", "array");
attribute.put("minItems", minOccurs);
attribute.put("maxItems", maxOccurs);
attribute.put("items", new JSONObject());
}
JSONObject attr = isArray ? attribute.getJSONObject("items") : attribute;
if (jsonChild.has("value")) {
JSONObject value = jsonChild.getJSONObject("value");
copyOKeys(value, attr);
} else if (jsonChild.has("children")) {
JSONArray children = jsonChild.getJSONArray("children");
for (int i = 0; i < children.length(); i++) {
JSONObject child = children.getJSONObject(i);
if (!child.has("objType")) {
copyOKeys(child, attr);
}
}
}
properties.put(attrName, attribute);
// handle children
if (jsonChild.has("children")) {
JSONArray children = jsonChild.getJSONArray("children");
for (int i = 0; i < children.length(); i++) {
JSONObject child = children.getJSONObject(i);
if (child.has("objType")) {
handleChild(attr, child);
}
}
}
}
private void handleChoice(JSONObject jsonOb, JSONObject jsonChild, long minItems, long maxItems) throws JSONException {
// note: oneOf with complex inline model is baddly supported: minTems forced to 0L
long minOccurs = jsonChild.has("minOccurs") ? jsonChild.getLong("minOccurs") : 0;
long maxOccurs = jsonChild.has("maxOccurs") ? jsonChild.getLong("maxOccurs") : minOccurs;
// handle children
if (jsonChild.has("children")) {
JSONArray children = jsonChild.getJSONArray("children");
for (int i = 0; i < children.length(); i++) {
JSONObject child = children.getJSONObject(i);
// minTems forced to 0L
handleChild(jsonOb, child, 0L, Math.max(maxOccurs, maxItems));
}
}
}
private void handleUnion(JSONObject jsonOb, JSONObject jsonChild, long minItems, long maxItems) throws JSONException {
if (jsonChild.has("children")) {
JSONArray children = jsonChild.getJSONArray("children");
for (int i = 0; i < children.length(); i++) {
JSONObject child = children.getJSONObject(i);
handleChild(jsonOb, child, minItems, maxItems);
}
}
}
private void handleExtension(JSONObject jsonOb, JSONObject jsonChild, long minItems, long maxItems) throws JSONException {
boolean hasAllOf = jsonOb.has("allOf");
if (!hasAllOf) {
jsonOb.put("allOf", new JSONArray());
}
JSONArray allOf = jsonOb.getJSONArray("allOf");
// handle children
if (jsonChild.has("children")) {
JSONArray children = jsonChild.getJSONArray("children");
for (int i = 0; i < children.length(); i++) {
JSONObject child = children.getJSONObject(i);
JSONObject ob = new JSONObject();
handleChild(ob, child);
merge(ob);
allOf.put(ob);
}
}
merge(jsonOb);
}
private void handleSequence(JSONObject jsonOb, JSONObject jsonChild, long minItems, long maxItems) throws JSONException {
long minOccurs = jsonChild.has("minOccurs") ? jsonChild.getLong("minOccurs") : 0;
long maxOccurs = jsonChild.has("maxOccurs") ? jsonChild.getLong("maxOccurs") : minOccurs;
boolean hasAllOf = jsonOb.has("allOf");
if (!hasAllOf) {
jsonOb.put("allOf", new JSONArray());
}
JSONArray allOf = jsonOb.getJSONArray("allOf");
// handle children
if (jsonChild.has("children")) {
JSONArray children = jsonChild.getJSONArray("children");
for (int i = 0; i < children.length(); i++) {
JSONObject child = children.getJSONObject(i);
JSONObject ob = new JSONObject();
handleChild(ob, child, Math.min(minOccurs, minItems), Math.max(maxOccurs, maxItems));
merge(ob);
allOf.put(ob);
}
merge(jsonOb);
}
}
private void merge(JSONObject jsonOb) throws JSONException {
if (jsonOb.has("allOf")) {
JSONArray allOf = jsonOb.getJSONArray("allOf");
int len = allOf.length();
if (len > 0) {
JSONObject merge = new JSONObject().put("type", "object").put("required", new JSONArray()).put("properties", new JSONObject());
List<JSONObject> merged = new ArrayList<JSONObject>();
List<JSONObject> others = new ArrayList<JSONObject>();
for (int i = 0; i < len; i++) {
JSONObject ob = allOf.getJSONObject(i);
if (ob.has("description") && ob.length() == 1) {
merge.put("description", ob.getString("description"));
merged.add(ob);
}
if (ob.has("properties")) {
copyOKeys(ob.getJSONObject("properties"), merge.getJSONObject("properties"));
}
if (ob.has("required")) {
copyAKeys(ob.getJSONArray("required"), merge.getJSONArray("required"));
}
if (!ob.has("properties") && !ob.has("required")) {
others.add(ob);
} else {
merged.add(ob);
}
}
for (JSONObject ob : merged) {
allOf.remove(ob);
}
if (merged.size() > 0) {
allOf.put(merge);
}
// merge in parent
if (allOf.length() == 1) {
JSONObject ob = allOf.getJSONObject(0);
if (jsonOb.has("properties")) {
if (ob.has("description") && ob.length() == 1) {
jsonOb.put("description", ob.getString("description"));
}
if (ob.has("properties")) {
copyOKeys(ob.getJSONObject("properties"), jsonOb.getJSONObject("properties"));
}
if (ob.has("required")) {
copyAKeys(ob.getJSONArray("required"), jsonOb.getJSONArray("required"));
}
jsonOb.remove("allOf");
} else {
copyOKeys(ob, jsonOb);
jsonOb.remove("allOf");
}
} else {
;
}
}
}
}
private void handleChild(JSONObject jsonOb, JSONObject jsonChild) throws JSONException {
handleChild(jsonOb, jsonChild, 1L, 1L);
}
private void handleChild(JSONObject jsonOb, JSONObject jsonChild, long minItems, long maxItems) throws JSONException {
if (jsonChild.has("objType")) {
String objType = jsonChild.getString("objType");
switch(objType) {
case "elementType":
handleElement(jsonOb, jsonChild, minItems, maxItems);
break;
case "attributeType":
handleAttribute(jsonOb, jsonChild, minItems, maxItems);
break;
case "choiceType":
handleChoice(jsonOb, jsonChild, minItems, maxItems);
break;
case "sequenceType":
handleSequence(jsonOb, jsonChild, minItems, maxItems);
break;
case "simpleUnionType":
handleUnion(jsonOb, jsonChild, minItems, maxItems);
break;
case "complexContentExtensionType":
handleExtension(jsonOb, jsonChild, minItems, maxItems);
break;
case "allType":
case "groupType":
case "complexType":
case "simpleRestrictionType":
case "simpleType":
if (jsonChild.has("children")) {
JSONArray children = jsonChild.getJSONArray("children");
for (int i = 0; i < children.length(); i++) {
handleChild(jsonOb, (JSONObject) children.get(i), minItems, maxItems);
}
} else {
System.out.println("ObjType: " + objType + " has no children");
}
break;
default:
System.out.println("Unhandled objType: " + objType);
break;
}
} else {
copyOKeys(jsonChild, jsonOb);
}
// remove pattern for integer (not supported)
if (jsonOb.has("type") && jsonOb.has("pattern")) {
if (!jsonOb.getString("type").equals("string")) {
jsonOb.remove("pattern");
}
}
}
private void copyOKeys(JSONObject from, JSONObject to) throws JSONException {
@SuppressWarnings("unchecked") Iterator<String> it = from.keys();
while (it.hasNext()) {
String pkey = it.next();
if (!pkey.isEmpty()) {
to.put(pkey, from.get(pkey));
}
}
}
private void copyAKeys(JSONArray from, JSONArray to) throws JSONException {
for (int i = 0; i < from.length(); i++) {
to.put(from.get(i));
}
}
private void handleRefs(Object ob) {
try {
if (ob instanceof JSONObject) {
JSONObject jsonOb = (JSONObject) ob;
if (jsonOb.has("$ref")) {
String ref = jsonOb.getString("$ref");
JSONObject refObject = getRefObject(ref);
if (!refObject.has("$ref")) {
jsonOb.remove("$ref");
copyOKeys(refObject, jsonOb);
}
}
@SuppressWarnings("unchecked") Iterator<String> it = jsonOb.keys();
while (it.hasNext()) {
String pkey = it.next();
handleRefs(jsonOb.get(pkey));
}
if (jsonOb.has("allOf")) {
merge(jsonOb);
}
} else if (ob instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) ob;
for (int i = 0; i < jsonArray.length(); i++) {
handleRefs(jsonArray.get(i));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
private void handle(JSONObject jParent) {
try {
if (jParent != null) {
if (!jParent.has("value")) {
JSONObject value = new JSONObject();
jParent.put("value", value);
JSONObject jsonOb = jParent.getJSONObject("value");
if (jParent.has("children")) {
JSONArray children = jParent.getJSONArray("children");
int len = children.length();
for (int i = 0; i < len; i++) {
handleChild(jsonOb, (JSONObject) children.get(i));
merge(jsonOb);
}
} else {
//
}
}
}
} catch (Exception e) {
e.printStackTrace();
Engine.logEngine.warn("(JSonSchemaUtils) Unexpected exception while generating jsonchema models", e);
}
}
@Override
protected void walkChoice(XmlSchema xmlSchema, XmlSchemaChoice obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
JSONObject jElement = new JSONObject();
try {
jElement.put("objType", "choiceType").put("minOccurs", obj.getMinOccurs()).put("maxOccurs", obj.getMaxOccurs());
addChild(jParent, jElement);
parent = jElement;
} catch (JSONException e) {
e.printStackTrace();
}
super.walkChoice(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkGroup(XmlSchema xmlSchema, XmlSchemaGroup obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName qname = obj.getName();
JSONObject jElement = new JSONObject();
try {
if (isGlobal(jParent)) {
if (qname != null) {
jElement.put("objType", "groupType");
String id = jsonSchema.getString("id");
jElement.put("objKey", id + "/definitions/" + normalize(qname.getLocalPart()));
jElement.put("QName", new JSONObject().put("localPart", qname.getLocalPart()).put("namespaceURI", qname.getNamespaceURI()));
addGlobalObject(jParent, jElement, qname.getLocalPart());
parent = jElement;
root = jElement;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkGroup(xmlSchema, obj);
if (isGlobal(jParent)) {
// handle(jElement);
}
parent = jParent;
root = jRoot;
}
@Override
protected void walkGroupRef(XmlSchema xmlSchema, XmlSchemaGroupRef obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName refName = obj.getRefName();
long minOccurs = obj.getMinOccurs();
long maxOccurs = obj.getMaxOccurs();
JSONObject jElement = new JSONObject();
try {
if (refName != null) {
String ref = getDefinitionRef(refName);
if (ref != null) {
JSONObject jRef = null;
if (maxOccurs > 1) {
if (ref.indexOf("xsd.jsonschema") != -1) {
jRef = new JSONObject().put("type", "array").put("items", new JSONObject().put("type", toOasType(refName.getLocalPart()))).put("minItems", minOccurs);
} else {
JSONObject refObject = getRefObject(ref);
jRef = new JSONObject().put("type", "array").put("items", refObject).put("minItems", minOccurs);
}
} else {
if (ref.indexOf("xsd.jsonschema") != -1) {
jRef = new JSONObject().put("type", toOasType(refName.getLocalPart()));
if (minOccurs == 0) {
jRef.put("nullable", "true");
}
} else {
JSONObject refObject = getRefObject(ref);
if (minOccurs == 0) {
jRef = new JSONObject().put("nullable", "true").put("allOf", new JSONArray().put(refObject));
} else {
jRef = refObject;
}
}
}
jElement.put("objType", "groupType").put("minOccurs", minOccurs).put("maxOccurs", maxOccurs).put("name", refName.getLocalPart());
addChild(jElement, jRef);
addChild(jParent, jElement);
parent = jElement;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkGroupRef(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkAll(XmlSchema xmlSchema, XmlSchemaAll obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
JSONObject jElement = new JSONObject();
try {
jElement.put("objType", "allType").put("minOccurs", obj.getMinOccurs()).put("maxOccurs", obj.getMaxOccurs());
addChild(jParent, jElement);
parent = jElement;
} catch (JSONException e) {
e.printStackTrace();
}
super.walkAll(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkSequence(XmlSchema xmlSchema, XmlSchemaSequence obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
JSONObject jElement = new JSONObject();
try {
jElement.put("objType", "sequenceType").put("minOccurs", obj.getMinOccurs()).put("maxOccurs", obj.getMaxOccurs());
addChild(jParent, jElement);
parent = jElement;
} catch (JSONException e) {
e.printStackTrace();
}
super.walkSequence(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkElement(XmlSchema xmlSchema, XmlSchemaElement obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
String name = obj.getName();
QName qname = obj.getQName();
QName refName = obj.getRefName();
QName typeName = obj.getSchemaTypeName();
XmlSchemaType xmlSchemaType = obj.getSchemaType();
long minOccurs = obj.getMinOccurs();
long maxOccurs = obj.getMaxOccurs();
JSONObject jElement = new JSONObject();
try {
if (isGlobal(jParent)) {
jElement.put("objType", "elementType");
} else {
jElement.put("objType", "elementType").put("minOccurs", minOccurs).put("maxOccurs", maxOccurs);
}
if (refName == null && typeName == null) {
// pass though
} else {
QName rname = refName != null ? refName : (typeName != null ? typeName : (xmlSchemaType != null ? xmlSchemaType.getQName() : new QName("")));
String ref = getDefinitionRef(rname);
if (ref != null) {
if (name.isEmpty()) {
name = rname.getLocalPart();
}
if (ref.indexOf("xsd.jsonschema") != -1) {
addChild(jElement, new JSONObject().put("type", toOasType(rname.getLocalPart())));
} else {
JSONObject refObject = getRefObject(ref);
addChild(jElement, refObject);
}
}
}
jElement.put("name", name);
if (isGlobal(jParent)) {
if (qname != null) {
String id = jsonSchema.getString("id");
jElement.put("objKey", id + "/definitions/" + normalize(qname.getLocalPart()));
jElement.put("QName", new JSONObject().put("localPart", qname.getLocalPart()).put("namespaceURI", qname.getNamespaceURI()));
}
addGlobalObject(jParent, jElement, name);
parent = jElement;
root = jElement;
} else {
addChild(jParent, jElement);
parent = jElement;
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkElement(xmlSchema, obj);
if (isGlobal(jParent)) {
// handle(jElement);
}
parent = jParent;
root = jRoot;
}
@Override
protected void walkAny(XmlSchema xmlSchema, XmlSchemaAny obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
JSONObject jElement = new JSONObject();
try {
JSONObject value = new JSONObject().put("type", "string").put("description", "any element");
jElement.put("objType", "elementType").put("minOccurs", 1).put("maxOccurs", 1).put("name", "any").put("value", value);
jParent.put("additionalProperties", true);
addChild(jParent, jElement);
parent = jElement;
} catch (JSONException e) {
e.printStackTrace();
}
super.walkAny(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkAnyAttribute(XmlSchema xmlSchema, XmlSchemaAnyAttribute obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
JSONObject jElement = new JSONObject();
try {
JSONObject value = new JSONObject().put("type", "string").put("xml", new JSONObject().put("attribute", true)).put("description", "any attribute");
jElement.put("objType", "attributeType").put("minOccurs", 0).put("name", "any").put("value", value);
addChild(jParent, jElement);
parent = jElement;
} catch (JSONException e) {
e.printStackTrace();
}
super.walkAnyAttribute(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkAppInfo(XmlSchema xmlSchema, XmlSchemaAppInfo item) {
JSONObject jParent = parent;
JSONObject jRoot = root;
try {
String description = "";
NodeList nodeList = item.getMarkup();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.TEXT_NODE) {
description += node.getNodeValue();
}
}
if (!description.isEmpty()) {
addChild(jParent, new JSONObject().put("title", description));
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkAppInfo(xmlSchema, item);
parent = jParent;
root = jRoot;
}
@Override
protected void walkDocumentation(XmlSchema xmlSchema, XmlSchemaDocumentation item) {
JSONObject jParent = parent;
JSONObject jRoot = root;
try {
String description = "";
NodeList nodeList = item.getMarkup();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.TEXT_NODE) {
description += node.getNodeValue();
}
}
if (!description.isEmpty()) {
addChild(jParent, new JSONObject().put("description", description));
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkDocumentation(xmlSchema, item);
parent = jParent;
root = jRoot;
}
@Override
protected void walkAttribute(XmlSchema xmlSchema, XmlSchemaAttribute obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
String name = obj.getName();
QName qname = obj.getQName();
QName refName = obj.getRefName();
QName typeName = obj.getSchemaTypeName();
XmlSchemaSimpleType xmlSchemaSimpleType = obj.getSchemaType();
boolean isRequired = obj.getUse().equals(XmlSchemaUtils.attributeUseRequired);
JSONObject jElement = new JSONObject();
try {
jElement.put("objType", "attributeType").put("minOccurs", isRequired ? 1 : 0);
if (refName == null && typeName == null) {
// pass through
} else {
QName rname = refName != null ? refName : (typeName != null ? typeName : (xmlSchemaSimpleType != null ? xmlSchemaSimpleType.getQName() : new QName("")));
String ref = getDefinitionRef(rname);
if (ref != null) {
if (name.isEmpty()) {
name = rname.getLocalPart();
}
JSONObject value = new JSONObject();
if (ref.indexOf("xsd.jsonschema") != -1) {
value.put("type", toOasType(rname.getLocalPart()));
value.put("xml", new JSONObject().put("attribute", true));
} else {
JSONObject refObject = getRefObject(ref);
copyOKeys(refObject, value);
value.put("xml", new JSONObject().put("attribute", true));
}
addChild(jElement, value);
}
}
jElement.put("name", name);
if (isGlobal(jParent)) {
if (qname != null) {
String id = jsonSchema.getString("id");
jElement.put("objKey", id + "/definitions/" + normalize(qname.getLocalPart()));
jElement.put("QName", new JSONObject().put("localPart", qname.getLocalPart()).put("namespaceURI", qname.getNamespaceURI()));
}
addGlobalObject(jParent, jElement, name);
parent = jElement;
root = jElement;
} else {
addChild(jParent, jElement);
parent = jElement;
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkAttribute(xmlSchema, obj);
if (isGlobal(jParent)) {
// handle(jElement);
}
parent = jParent;
root = jRoot;
}
@Override
protected void walkAttributeGroup(XmlSchema xmlSchema, XmlSchemaAttributeGroup obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName qname = obj.getName();
JSONObject jElement = new JSONObject();
try {
if (isGlobal(jParent)) {
if (qname != null) {
jElement.put("objType", "attributeGroupType");
String id = jsonSchema.getString("id");
jElement.put("objKey", id + "/definitions/" + normalize(qname.getLocalPart()));
jElement.put("QName", new JSONObject().put("localPart", qname.getLocalPart()).put("namespaceURI", qname.getNamespaceURI()));
addGlobalObject(jParent, jElement, qname.getLocalPart());
parent = jElement;
root = jElement;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkAttributeGroup(xmlSchema, obj);
if (isGlobal(jParent)) {
// handle(jElement);
}
parent = jParent;
root = jRoot;
}
@Override
protected void walkAttributeGroupRef(XmlSchema xmlSchema, XmlSchemaAttributeGroupRef obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName refName = obj.getRefName();
JSONObject jElement = new JSONObject();
try {
if (refName != null) {
String ref = getDefinitionRef(refName);
if (ref != null) {
jElement.put("objType", "attributeGroupType").put("name", refName.getLocalPart());
addChild(jElement, new JSONObject().put("$ref", ref));
addChild(jParent, jElement);
parent = jElement;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkAttributeGroupRef(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkSimpleContent(XmlSchema xmlSchema, XmlSchemaSimpleContent obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName qname = null;
XmlSchemaContent xmlSchemaContent = obj.getContent();
if (xmlSchemaContent instanceof XmlSchemaSimpleContentRestriction) {
qname = ((XmlSchemaSimpleContentRestriction) xmlSchemaContent).getBaseTypeName();
} else if (xmlSchemaContent instanceof XmlSchemaSimpleContentExtension) {
qname = ((XmlSchemaSimpleContentExtension) xmlSchemaContent).getBaseTypeName();
}
JSONObject jElement = new JSONObject();
try {
if (qname != null) {
String ref = getDefinitionRef(qname);
if (ref != null) {
if (ref.indexOf("xsd.jsonschema") != -1) {
jElement.put("objType", "elementType").put("minOccurs", 1).put("maxOccurs", 1).put("name", "text").put("value", new JSONObject().put("type", toOasType(qname.getLocalPart())));
} else {
JSONObject refObject = getRefObject(ref);
jElement.put("objType", "elementType").put("minOccurs", 1).put("maxOccurs", 1).put("name", "text").put("value", refObject);
}
addChild(jParent, jElement);
parent = jElement;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkSimpleContent(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkSimpleType(XmlSchema xmlSchema, XmlSchemaSimpleType obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName qname = obj.getQName();
QName bname = obj.getBaseSchemaTypeName();
JSONObject jElement = new JSONObject();
try {
jElement.put("objType", "simpleType");
if (bname != null) {
String ref = getDefinitionRef(bname);
if (ref != null) {
if (ref.indexOf("xsd.jsonschema") != -1) {
jElement.put("value", new JSONObject().put("type", toOasType(bname.getLocalPart())));
} else {
JSONObject refObject = getRefObject(ref);
jElement.put("value", refObject);
}
}
}
if (isGlobal(jParent)) {
if (qname != null) {
String id = jsonSchema.getString("id");
jElement.put("objKey", id + "/definitions/" + normalize(qname.getLocalPart()));
jElement.put("QName", new JSONObject().put("localPart", qname.getLocalPart()).put("namespaceURI", qname.getNamespaceURI()));
}
addGlobalObject(jParent, jElement, obj.getName());
parent = jElement;
root = jElement;
} else {
addChild(jParent, jElement);
parent = jElement;
}
} catch (JSONException e1) {
e1.printStackTrace();
}
super.walkSimpleType(xmlSchema, obj);
if (isGlobal(jParent)) {
// handle(jElement);
}
parent = jParent;
root = jRoot;
}
@Override
protected void walkSimpleTypeRestriction(XmlSchema xmlSchema, XmlSchemaSimpleTypeRestriction obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName qname = obj.getBaseTypeName();
JSONObject jElement = new JSONObject();
try {
if (qname != null) {
String ref = getDefinitionRef(qname);
if (ref != null) {
jElement.put("objType", "simpleRestrictionType");
if (ref.indexOf("xsd.jsonschema") != -1) {
addChild(jElement, new JSONObject().put("type", toOasType(qname.getLocalPart())));
} else {
JSONObject refObject = getRefObject(ref);
addChild(jElement, refObject);
}
addChild(jParent, jElement);
parent = jElement;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkSimpleTypeRestriction(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkSimpleTypeUnion(XmlSchema xmlSchema, XmlSchemaSimpleTypeUnion obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
JSONObject jElement = new JSONObject();
try {
jElement.put("objType", "simpleUnionType");
QName[] members = obj.getMemberTypesQNames();
if (members != null) {
for (QName qname : members) {
String ref = getDefinitionRef(qname);
if (ref.indexOf("xsd.jsonschema") != -1) {
addChild(jElement, new JSONObject().put("type", toOasType(qname.getLocalPart())));
} else {
parent = jElement;
walkByTypeName(xmlSchema, qname);
}
}
} else {
parent = jElement;
super.walkSimpleTypeUnion(xmlSchema, obj);
}
addChild(jParent, jElement);
} catch (JSONException e) {
e.printStackTrace();
}
parent = jParent;
root = jRoot;
}
@Override
protected void walkFacets(XmlSchema xmlSchema, XmlSchemaObjectCollection facets) {
JSONObject jParent = parent;
JSONObject jRoot = root;
JSONArray array = new JSONArray();
boolean arrayWithDuplicates = false;
for (int i = 0; i < facets.getCount(); i++) {
XmlSchemaFacet facet = (XmlSchemaFacet) facets.getItem(i);
Object value = facet.getValue();
try {
JSONObject jFacet = new JSONObject();
if (facet instanceof XmlSchemaEnumerationFacet) {
if ("".equals(value)) {
jFacet.put("minLength", 0);
array.put(value);
array.put(JSONObject.NULL);
} else {
if (array.join(",").toLowerCase().indexOf(String.valueOf(value).toLowerCase()) != -1) {
arrayWithDuplicates = true;
}
array.put(value);
}
if (i < facets.getCount() - 1) {
continue;
}
} else if (facet instanceof XmlSchemaPatternFacet) {
jFacet.put("pattern", value);
} else if (facet instanceof XmlSchemaLengthFacet) {
jFacet.put("length", Integer.valueOf(value.toString(), 10));
} else if (facet instanceof XmlSchemaMinLengthFacet) {
jFacet.put("minLength", Integer.valueOf(value.toString(), 10));
} else if (facet instanceof XmlSchemaMaxLengthFacet) {
jFacet.put("maxLength", Integer.valueOf(value.toString(), 10));
} else if (facet instanceof XmlSchemaMaxExclusiveFacet) {
jFacet.put("maximum", Integer.valueOf(value.toString(), 10)).put("exclusiveMaximum", true);
} else if (facet instanceof XmlSchemaMaxInclusiveFacet) {
jFacet.put("maximum", Integer.valueOf(value.toString(), 10)).put("exclusiveMaximum", false);
} else if (facet instanceof XmlSchemaMinExclusiveFacet) {
jFacet.put("minimum", Integer.valueOf(value.toString(), 10)).put("exclusiveMinimum", true);
} else if (facet instanceof XmlSchemaMinInclusiveFacet) {
jFacet.put("minimum", Integer.valueOf(value.toString(), 10)).put("exclusiveMinimum", false);
} else if (facet instanceof XmlSchemaTotalDigitsFacet) {
jFacet.put("maxLength", Integer.valueOf(value.toString(), 10));
}
if (facet instanceof XmlSchemaEnumerationFacet) {
if (array.length() > 0) {
jFacet.put("nullable", true);
if (facets.getCount() > 1) {
if (arrayWithDuplicates) {
jFacet.put("pattern", array.join("|"));
} else {
jFacet.put("enum", array);
}
}
}
}
if (jFacet.length() > 0) {
addChild(jParent, jFacet);
}
parent = jFacet;
} catch (JSONException e) {
e.printStackTrace();
}
}
parent = jParent;
root = jRoot;
}
@Override
protected void walkSimpleTypeList(XmlSchema xmlSchema, XmlSchemaSimpleTypeList obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName qname = obj.getItemTypeName();
JSONObject jElement = new JSONObject();
try {
if (qname != null) {
String ref = getDefinitionRef(qname);
if (ref != null) {
JSONObject value = new JSONObject();
if (ref.indexOf("xsd.jsonschema") != -1) {
value.put("type", "array").put("items", new JSONObject().put("type", toOasType(qname.getLocalPart())));
} else {
JSONObject refObject = getRefObject(ref);
value.put("type", "array").put("items", refObject);
}
jElement.put("objType", "simpleListType").put("value", value);
addChild(jParent, jElement);
parent = jElement;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkSimpleTypeList(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkComplexContentExtension(XmlSchema xmlSchema, XmlSchemaComplexContentExtension obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName baseTypeName = obj.getBaseTypeName();
JSONObject jElement = new JSONObject();
try {
if (baseTypeName != null) {
String ref = getDefinitionRef(baseTypeName);
if (ref != null) {
jElement.put("objType", "complexContentExtensionType");
addChild(jElement, new JSONObject().put("$ref", ref));
addChild(jParent, jElement);
parent = jElement;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkComplexContentExtension(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkComplexContentRestriction(XmlSchema xmlSchema, XmlSchemaComplexContentRestriction obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName baseTypeName = obj.getBaseTypeName();
JSONObject jElement = new JSONObject();
try {
if (baseTypeName != null) {
String ref = getDefinitionRef(baseTypeName);
if (ref != null) {
jElement.put("objType", "complexContentRestrictionType");
addChild(jElement, new JSONObject().put("$ref", ref));
addChild(jParent, jElement);
parent = jElement;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkComplexContentRestriction(xmlSchema, obj);
parent = jParent;
root = jRoot;
}
@Override
protected void walkComplexType(XmlSchema xmlSchema, XmlSchemaComplexType obj) {
JSONObject jParent = parent;
JSONObject jRoot = root;
QName qname = obj.getQName();
JSONObject jElement = new JSONObject();
try {
jElement.put("objType", "complexType");
if (obj.isMixed()) {
JSONObject jText = new JSONObject();
jText.put("objType", "elementType").put("name", "text").put("minOccurs", 0).put("maxOccurs", 1).put("value", new JSONObject().put("description", "the mixed content string").put("type", "string"));
addChild(jElement, jText);
}
if (isGlobal(jParent)) {
if (qname != null) {
String id = jsonSchema.getString("id");
jElement.put("objKey", id + "/definitions/" + normalize(qname.getLocalPart()));
jElement.put("QName", new JSONObject().put("localPart", qname.getLocalPart()).put("namespaceURI", qname.getNamespaceURI()));
}
addGlobalObject(jParent, jElement, obj.getName());
parent = jElement;
root = jElement;
} else {
addChild(jParent, jElement);
parent = jElement;
}
} catch (JSONException e) {
e.printStackTrace();
}
super.walkComplexType(xmlSchema, obj);
if (isGlobal(jParent)) {
// handle(jElement);
}
parent = jParent;
root = jRoot;
}
@Override
protected void walk(XmlSchema xmlSchema) {
XmlSchemaObjectCollection items = xmlSchema.getItems();
for (Iterator<XmlSchemaObject> i = GenericUtils.cast(items.getIterator()); i.hasNext(); ) {
XmlSchemaObject obj = i.next();
if (obj instanceof XmlSchemaInclude) {
walkInclude(xmlSchema, (XmlSchemaInclude) obj);
} else if (obj instanceof XmlSchemaImport) {
walkImport(xmlSchema, (XmlSchemaImport) obj);
}
}
// walk simple types first
for (Iterator<XmlSchemaType> i = GenericUtils.cast(xmlSchema.getSchemaTypes().getValues()); i.hasNext(); ) {
XmlSchemaObject obj = i.next();
if (obj instanceof XmlSchemaSimpleType) {
walk(xmlSchema, obj);
}
}
// walk others
for (Iterator<XmlSchemaType> i = GenericUtils.cast(xmlSchema.getSchemaTypes().getValues()); i.hasNext(); ) {
XmlSchemaObject obj = i.next();
if (!(obj instanceof XmlSchemaSimpleType)) {
walk(xmlSchema, obj);
}
}
for (Iterator<XmlSchemaObject> i = GenericUtils.cast(items.getIterator()); i.hasNext(); ) {
XmlSchemaObject obj = i.next();
if (!(obj instanceof XmlSchemaInclude || obj instanceof XmlSchemaImport || obj instanceof XmlSchemaType)) {
walk(xmlSchema, obj);
}
}
List<String> toRemove = new ArrayList<String>();
@SuppressWarnings("unchecked") Iterator<String> it = definitions.keys();
while (it.hasNext()) {
String pkey = it.next();
try {
JSONObject jsonOb = definitions.getJSONObject(pkey);
handle(jsonOb);
JSONObject value = jsonOb.getJSONObject("value");
if (value.has("properties") || value.has("allOf") || value.has("$ref")) {
jsonOb.put("type", "object");
handleRefs(value);
}
copyOKeys(value, jsonOb);
if (jsonOb.has("type")) {
if (!jsonOb.getString("type").equals("object")) {
toRemove.add(pkey);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
for (String pkey : toRemove) {
definitions.remove(pkey);
}
boolean debug = false;
if (!debug) {
try {
@SuppressWarnings("unchecked") Iterator<String> ita = definitions.keys();
while (ita.hasNext()) {
JSONObject jsonOb = definitions.getJSONObject(ita.next());
jsonOb.remove("objKey");
jsonOb.remove("objType");
jsonOb.remove("QName");
jsonOb.remove("children");
jsonOb.remove("name");
jsonOb.remove("maxOccurs");
jsonOb.remove("minOccurs");
jsonOb.remove("value");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
refs.clear();
}
}.walk(xmlSchema);
} catch (Exception e) {
e.printStackTrace();
}
return jsonSchema;
}
use of org.apache.ws.commons.schema.XmlSchemaAny in project axis-axis2-java-core by apache.
the class SchemaUnwrapperExtension method processXMLSchemaSequence.
private void processXMLSchemaSequence(XmlSchemaParticle schemaParticle, AxisMessage message, List partNameList, String qnameSuffix) throws CodeGenerationException {
if (schemaParticle instanceof XmlSchemaSequence) {
// get the name of the operation name and namespace,
// part name and hang them somewhere ? The ideal place
// would be the property bag in the codegen config!
QName opName = message.getAxisOperation().getName();
XmlSchemaSequence sequence = (XmlSchemaSequence) schemaParticle;
List<XmlSchemaSequenceMember> items = sequence.getItems();
// if this is an empty sequence, return
if (items.isEmpty()) {
return;
}
for (XmlSchemaSequenceMember item : items) {
// traverse through them
if (item instanceof XmlSchemaElement) {
// add the element name to the part name list
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) item;
XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
String partName = null;
if (xmlSchemaElement.getRef().getTargetQName() != null) {
partName = xmlSchemaElement.getRef().getTargetQName().getLocalPart();
} else {
partName = xmlSchemaElement.getName();
}
// part names are not unique across messages. Hence
// we need some way of making the part name a unique
// one (due to the fact that the type mapper
// is a global list of types).
// The seemingly best way to do that is to
// specify a namespace for the part QName reference which
// is stored in the list. This part qname is
// temporary and should not be used with it's
// namespace URI (which happened to be the operation name)
// with _input attached to it
partNameList.add(WSDLUtil.getPartQName(opName.getLocalPart(), qnameSuffix, partName));
// if the particle contains anything other than
// a XMLSchemaElement then we are not in a position
// to unwrap it
} else if (item instanceof XmlSchemaAny) {
// if this is an instance of xs:any, then there is no part name for it. Using ANY_ELEMENT_FIELD_NAME
// for it for now
// we have to handle both maxoccurs 1 and maxoccurs > 1 situation
XmlSchemaAny xmlSchemaAny = (XmlSchemaAny) item;
partNameList.add(WSDLUtil.getPartQName(opName.getLocalPart(), qnameSuffix, Constants.ANY_ELEMENT_FIELD_NAME));
} else {
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat", "unknown type", "Element"));
}
}
// we do not know how to deal with other particles
// such as xs:all or xs:choice. Usually occurs when
// passed with the user built WSDL where the style
// is document.
} else if (schemaParticle instanceof XmlSchemaChoice) {
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat", "choice", "sequence"));
} else if (schemaParticle instanceof XmlSchemaAll) {
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat", "all", "sequence"));
} else {
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat", "unknown", "sequence"));
}
}
use of org.apache.ws.commons.schema.XmlSchemaAny in project axis-axis2-java-core by apache.
the class DefaultSchemaGenerator method generateSchemaTypeForDocument.
/**
* Generate schema type for document.
*
* @param sequence
* the sequence
* @param parameterName
* the parameter name
*/
protected QName generateSchemaTypeForDocument(XmlSchemaSequence sequence, String parameterName) {
XmlSchema xmlSchema = getXmlSchema(targetNamespace);
QName entryName = new QName(targetNamespace, "document");
XmlSchemaType schemaType = xmlSchema.getTypeByName(entryName);
if (schemaType == null) {
XmlSchemaComplexType entryType = new XmlSchemaComplexType(xmlSchema, false);
XmlSchemaSequence entrySequence = new XmlSchemaSequence();
XmlSchemaAny any = new XmlSchemaAny();
entrySequence.getItems().add(any);
entryType.setParticle(entrySequence);
entryType.setName(entryName.getLocalPart());
xmlSchema.getItems().add(entryType);
xmlSchema.getSchemaTypes().put(entryName, entryType);
schemaType = entryType;
}
XmlSchemaElement entryElement = new XmlSchemaElement(xmlSchema, false);
entryElement.setName(parameterName);
entryElement.setSchemaTypeName(schemaType.getQName());
entryElement.setMinOccurs(0);
entryElement.setNillable(true);
if (sequence != null) {
sequence.getItems().add(entryElement);
}
return schemaType.getQName();
}
use of org.apache.ws.commons.schema.XmlSchemaAny 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);
}
}
}
}
}
Aggregations