Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void parseSchemaElement(Element schemaElement, Definition definition, String targetNamespace) throws WSDLException{
- SchemaType type = new SchemaType();
- NamedNodeMap attributes = schemaElement.getAttributes();
- String nameA = getAttributeValue(attributes,"name");
- String typeA = getAttributeValue(attributes,"type");
- String refA = getAttributeValue(attributes, "ref");
- String description = getElementDescription(schemaElement);
- QName currentElementQName = new QName(schemaElement.getNamespaceURI(),schemaElement.getLocalName());
- boolean finished = false;
- if(SchemaConstants.Q_ELEMS_MAIN.contains(currentElementQName)){
- if(unusedType == null){
- type.setName(nameA);
- type.setNamespace(targetNamespace);
- type.setDescription(description);
- }else{
- type = unusedType;
- unusedType = null;
- }
- if(match(schemaElement, SchemaConstants.Q_ELEM_ELEM, AbstractElement.class)){
- if(!refA.isEmpty()){
- type.referenced = removeNamespaceFromString(refA);
- }else{
- if(!typeA.isEmpty()){
- type.simpleType = removeNamespaceFromString(typeA);
- finished = true;
- }else{
- Element child = util.getFirstChildElement(schemaElement);
- if(child==null || util.match(child, SchemaConstants.Q_ELEM_COMP, AbstractElement.class)||util.match(child, SchemaConstants.Q_ELEM_SIMP, AbstractElement.class)){
- unusedType = type;
- parseSchemaElement(child, definition, targetNamespace);
- }else{
- throw new WSDLException(WSDLException.PARSER_ERROR, "Элемент не содержит ни внешнего, ни внутреннего указания ("+child.getLocalName()+"в пространстве имён"+child.getNamespaceURI()+")");
- }
- }
- }
- }else{
- if(util.match(schemaElement, SchemaConstants.Q_ELEM_SIMP, AbstractElement.class)){
- //simpleType
- Element restriction = util.getFirstChildElement(schemaElement);
- if(util.match(restriction, SchemaConstants.Q_ELEM_RESTRICTION, AbstractElement.class)){
- String baseA = removeNamespaceFromString(getAttributeValue(restriction.getAttributes(),"base"));
- if(!baseA.isEmpty()){
- type.setSimpleType(baseA);
- Element simpleTypeChild = util.getFirstChildElement(restriction);
- while(simpleTypeChild != null){
- NamedNodeMap childAttributes = simpleTypeChild.getAttributes();
- String value = getAttributeValue(childAttributes,"value");
- if(util.match(simpleTypeChild, SchemaConstants.Q_ELEM_ENUMERATION, AbstractElement.class)){
- if(type.enumeration == null){
- type.enumeration = new java.util.HashMap();
- }
- type.enumeration.put(value,getElementDescription(simpleTypeChild));
- }else if(util.match(simpleTypeChild, SchemaConstants.Q_ELEM_LENGTH, AbstractElement.class)){
- type.length = value;
- }else if(util.match(simpleTypeChild, SchemaConstants.Q_ELEM_PATTERN, AbstractElement.class)){
- type.pattern = value;
- }else{
- throw new WSDLException(WSDLException.PARSER_ERROR,"Недокументированный элемент "+simpleTypeChild.getLocalName()+" внутри элемента simpleType.");
- }
- simpleTypeChild = util.getNextSiblingElement(simpleTypeChild);
- }
- finished = true;
- }else{
- throw new WSDLException(WSDLException.PARSER_ERROR, "Отсутсвует обязательный аттрибут base у элемента <simpleType>.");
- }
- }else{
- //not a restriction
- throw new WSDLException(WSDLException.PARSER_ERROR,"После элемента simpleType ожидался элемент restriction");
- }
- }else{
- //complexType
- description = getElementDescription(schemaElement);
- if(type.getDescription().isEmpty()){
- type.setDescription(description);
- }
- Element complexTypeChild = util.getFirstChildElement(schemaElement);
- if(SchemaConstants.Q_COMPLEX_CHILD.contains(new QName(complexTypeChild.getNamespaceURI(), complexTypeChild.getLocalName()))){
- Element subChild = util.getFirstChildElement(complexTypeChild);
- while(subChild!=null){
- if(util.match(subChild, SchemaConstants.Q_ELEM_ELEM, AbstractElement.class)){
- NamedNodeMap subChildAttributes = subChild.getAttributes();
- String name = getAttributeValue(subChildAttributes, "name");
- if(name.isEmpty()){
- name = getAttributeValue(subChildAttributes,"ref");
- }
- name = removeNamespaceFromString(name);
- if(util.match(complexTypeChild, SchemaConstants.Q_ELEM_CHOICE, AbstractElement.class)){
- if(type.choice == null){
- type.choice = new ArrayList();
- }
- type.choice.add(name);
- }else{
- if(type.relatedTypes == null){
- type.relatedTypes = new ArrayList();
- }
- type.relatedTypes.add(name);
- }
- parseSchemaElement(subChild,definition,targetNamespace);
- }else if(util.match(subChild, SchemaConstants.Q_ELEM_CHOICE, AbstractElement.class)){
- }else{
- throw new WSDLException(WSDLException.OTHER_ERROR,"Разбор данного элемента не предусмотрен.(\""+subChild.getLocalName()+"\" пространства имён \""+subChild.getNamespaceURI()+"\").");
- }
- subChild = util.getNextSiblingElement(subChild);
- }
- finished = true;
- }else if(SchemaConstants.Q_CONTENT_ELEMENTS.contains(new QName(complexTypeChild.getNamespaceURI(), complexTypeChild.getLocalName()))){
- }else{
- throw new WSDLException(WSDLException.PARSER_ERROR,"Внутри элемента complexType содержится элемент, которому не соответсвующий схеме: "+complexTypeChild.getLocalName());
- }
- }
- }
- }else{
- throw new WSDLException(WSDLException.PARSER_ERROR, "Неопознанный элемент описания");
- }
- if(finished){
- definition.schemaTypes.put(type.getName(), type);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement