Examples of XSDParticle


Examples of org.eclipse.xsd.XSDParticle

        // use a queue to simulate the recursion
        LinkedList queue = new LinkedList();
        queue.addLast(cType.getContent());

        while (!queue.isEmpty()) {
            XSDParticle particle = (XSDParticle) queue.removeFirst();

            // analyze type of particle content
            int pType = XSDUtil.nodeType(particle.getElement());

            if (pType == XSDConstants.ANY_ELEMENT) {
                visitor.visit(particle);
            } else {
                // model group
                XSDModelGroup grp = null;

                switch (pType) {
                case XSDConstants.GROUP_ELEMENT:

                    XSDModelGroupDefinition grpDef = (XSDModelGroupDefinition) particle
                            .getContent();

                    if (grpDef.isModelGroupDefinitionReference()) {
                        grpDef = grpDef.getResolvedModelGroupDefinition();
                    }

                    grp = grpDef.getModelGroup();

                    break;

                case XSDConstants.CHOICE_ELEMENT:
                case XSDConstants.ALL_ELEMENT:
                case XSDConstants.SEQUENCE_ELEMENT:
                    grp = (XSDModelGroup) particle.getContent();

                    break;
                }

                if (grp != null) {
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

        boolean includeParents) {
        List particles = getChildElementParticles(type, includeParents);
        List elements = new ArrayList();

        for (Iterator p = particles.iterator(); p.hasNext();) {
            XSDParticle particle = (XSDParticle) p.next();
            XSDElementDeclaration decl = (XSDElementDeclaration) particle.getContent();

            if (decl.isElementDeclarationReference()) {
                decl = decl.getResolvedElementDeclaration();
            }
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

        //use a queue to simulate the recursion
        LinkedList queue = new LinkedList();
        queue.addLast(cType.getContent());

        while (!queue.isEmpty()) {
            XSDParticle particle = (XSDParticle) queue.removeFirst();

            //analyze type of particle content
            int pType = XSDUtil.nodeType(particle.getElement());

            if (pType == XSDConstants.ELEMENT_ELEMENT) {
                visitor.visit(particle);
            } else {
                //model group
                XSDModelGroup grp = null;

                switch (pType) {
                case XSDConstants.GROUP_ELEMENT:

                    XSDModelGroupDefinition grpDef = (XSDModelGroupDefinition) particle.getContent();

                    if (grpDef.isModelGroupDefinitionReference()) {
                        grpDef = grpDef.getResolvedModelGroupDefinition();
                    }

                    grp = grpDef.getModelGroup();

                    break;

                case XSDConstants.CHOICE_ELEMENT:
                case XSDConstants.ALL_ELEMENT:
                case XSDConstants.SEQUENCE_ELEMENT:
                    grp = (XSDModelGroup) particle.getContent();

                    break;
                }

                if (grp != null) {
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

                    }
                   
                    //get the anonymous element, and look it up in the container type
                    if (type.getContainer() instanceof XSDElementDeclaration) {
                        XSDElementDeclaration anonymous = (XSDElementDeclaration) type.getContainer();
                        XSDParticle particle = Schemas.getChildElementParticle(container,
                                anonymous.getName(), true);

                        if (particle != null) {
                            bindingName = new QName(base.getTargetNamespace(),
                                    base.getName() + "_" + anonymous.getName());
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

                    if (propertyExtractor.canHandle(entry.object)) {
                        List extracted = propertyExtractor.properties(entry.object, entry.element);
O:
                        for (Iterator e = extracted.iterator(); e.hasNext();) {
                            Object[] tuple = (Object[]) e.next();
                            XSDParticle particle = (XSDParticle) tuple[0];
                            XSDElementDeclaration child = (XSDElementDeclaration) particle
                                .getContent();

                            //check for a comment
                            if ((child != null)
                                    && (COMMENT.getNamespaceURI().equals(child.getTargetNamespace()))
                                    && COMMENT.getLocalPart().equals(child.getName())) {
                                comment(child.getElement());

                                continue;
                            }

                            if (child.isElementDeclarationReference()) {
                                child = child.getResolvedElementDeclaration();
                            }

                            //do not encode the element if the parent has already
                            // been encoded by the parent
                            String ns = child.getTargetNamespace();
                            String local = child.getName();

                            for (int i = 0; i < entry.encoding.getChildNodes().getLength(); i++) {
                                Node node = entry.encoding.getChildNodes().item(i);

                                if (node instanceof Element) {
                                    if (ns != null) {
                                        if (ns.equals(node.getNamespaceURI())
                                                && local.equals(node.getLocalName())) {
                                            continue O;
                                        }
                                    } else {
                                        if (local.equals(node.getLocalName())) {
                                            continue O;
                                        }
                                    }
                                }
                            }

                            Object obj = tuple[1];

                            // if the value is null, can we skip it? Or do we have to go out
                            // with an non empty element with xs:nil?
                            if (obj == null) {
                                if (particle.getMinOccurs() == 0) {
                                    // just skip it
                                    continue;
                                } else if(!child.isNillable()){
                                    // log an error and skip the element, but we're encoding
                                    // something invalid
                                    logger.fine("Property " + ns + ":" + local
                                        + " not found but minoccurs > 0 ");
                                    //skip this regardless
                                    continue;
                                }
                                // minOccurs > 0 && nillable -> we'll encode an empty element with xs:nil
                            }

                            //figure out the maximum number of occurences
                            int maxOccurs = 1;

                            if (particle.isSetMaxOccurs()) {
                                maxOccurs = particle.getMaxOccurs();
                            } else {
                                //look the containing group
                                if (particle.eContainer() instanceof XSDModelGroup) {
                                    XSDModelGroup group = (XSDModelGroup) particle.eContainer();

                                    if (group.eContainer() instanceof XSDParticle) {
                                        XSDParticle cParticle = (XSDParticle) group.eContainer();

                                        if (cParticle.isSetMaxOccurs()) {
                                            maxOccurs = cParticle.getMaxOccurs();
                                        }
                                    }
                                }
                            }
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

      //add any anonymous types foudn with type definitions
      for ( Iterator t = types.iterator(); t.hasNext(); ) {
        XSDTypeDefinition type = (XSDTypeDefinition) t.next();
        List particles = Schemas.getChildElementParticles( type, false );
        for ( Iterator p = particles.iterator(); p.hasNext(); ) {
          XSDParticle particle = (XSDParticle) p.next();
          XSDElementDeclaration element = (XSDElementDeclaration) particle.getContent();
         
          //ignore element references, caught in teh above loop
          if ( element.isElementDeclarationReference() )
            continue;
         
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

    // now build child types
    ArrayList properties = new ArrayList();
    if (followComplexTypes) {
      List children = Schemas.getChildElementParticles(xsdType, false);
      for (Iterator itr = children.iterator(); itr.hasNext();) {
          XSDParticle particle = (XSDParticle) itr.next();
        XSDElementDeclaration element = (XSDElementDeclaration) particle.getContent();
        if (element.isElementDeclarationReference()) {
            element = element.getResolvedElementDeclaration();
        }
       
        XSDTypeDefinition childType = element.getTypeDefinition();
        if (childType == null) {
            childType = findGlobalElementXSDType(element);
        }
       
        AttributeType gtType = null;
        if (childType != null ) {
                gtType = createType(childType, depth+1);
        }
        else {
            //set to xs:anyType
            gtType = xsAnyType();
        }
            assert gtType != null;
           
            int minOccurs = particle.getMinOccurs();
            int maxOccurs = particle.getMaxOccurs();
            if (maxOccurs == -1) {
                maxOccurs = Integer.MAX_VALUE;
            }
            boolean isNillable = element.isNillable();
           
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

                XSDTypeDefinition attributeDefinition = xsd.resolveTypeDefinition(name
                        .getNamespaceURI(), name.getLocalPart());
                attribute.setTypeDefinition(attributeDefinition);

                XSDParticle particle = factory.createXSDParticle();
                particle.setMinOccurs(attributeDescriptor.getMinOccurs());
                particle.setMaxOccurs(attributeDescriptor.getMaxOccurs());
                particle.setContent(attribute);
                attributes.getContents().add(particle);
            }
        }

        // set up fatureType with attributes
        XSDParticle contents = factory.createXSDParticle();
        contents.setContent(attributes);

        definition.setContent(contents);
        xsd.getContents().add(definition);

        return definition;
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

        XSDElementDeclaration element = factory.createXSDElementDeclaration();
        element.setName(att.getName().getLocalPart());
        element.setTargetNamespace(att.getName().getNamespaceURI());
        element.setTypeDefinition(xsdType);
       
        XSDParticle particle = factory.createXSDParticle();
        particle.setContent(element);
        return particle;
    }
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

                    if (descriptor.getUserData() != null) {
                        Object propertyElement = descriptor.getUserData().get(
                                XSDElementDeclaration.class);
                        if (propertyElement != null
                                && propertyElement instanceof XSDElementDeclaration) {
                            XSDParticle substitutedChildParticle = XSDFactory.eINSTANCE
                                    .createXSDParticle();
                            substitutedChildParticle.setMaxOccurs(descriptor.getMaxOccurs());
                            substitutedChildParticle.setMinOccurs(descriptor.getMinOccurs());
                            XSDElementDeclaration wrapper = XSDFactory.eINSTANCE
                                    .createXSDElementDeclaration();
                            wrapper
                                    .setResolvedElementDeclaration((XSDElementDeclaration) propertyElement);
                            substitutedChildParticle.setContent(wrapper);
                            properties.add(new Object[] { substitutedChildParticle, complex });
                        }
                    }
                }
            }
            return properties;
        }
        if (object instanceof ComplexAttribute) {
            ComplexAttribute complex = (ComplexAttribute) object;
            for (XSDParticle childParticle : (List<XSDParticle>) Schemas.getChildElementParticles(
                    element.getTypeDefinition(), true)) {
                XSDElementDeclaration childElement = (XSDElementDeclaration) childParticle
                        .getContent();
                if (childElement.isElementDeclarationReference()) {
                    childElement = childElement.getResolvedElementDeclaration();
                }
                for (XSDElementDeclaration e : (List<XSDElementDeclaration>) childElement
                        .getSubstitutionGroup()) {
                    Name name = new NameImpl(e.getTargetNamespace(), e.getName());
                    Collection<Property> nameProperties = complex.getProperties(name);
                    if (!nameProperties.isEmpty()) {
                        // Particle creation stolen from BindingPropertyExtractor.
                        // I do not know why a wrapper is required; monkey see, monkey do.
                        // Without the wrapper, get an NPE in BindingPropertyExtractor.
                        XSDParticle substitutedChildParticle = XSDFactory.eINSTANCE
                                .createXSDParticle();
                        substitutedChildParticle.setMaxOccurs(childParticle.getMaxOccurs());
                        substitutedChildParticle.setMinOccurs(childParticle.getMinOccurs());
                        XSDElementDeclaration wrapper = XSDFactory.eINSTANCE
                                .createXSDElementDeclaration();
                        wrapper.setResolvedElementDeclaration(e);
                        substitutedChildParticle.setContent(wrapper);
                        for (Property property : nameProperties) {
                            /*
                             * Note : Returning simple feature value is not necessary as it has been
                             * taken care in the 1st For Loop of BindingPropertyExtractor.java -
                             * List properties(Object, XSDElementDeclaration) method
                             */
                            if (property instanceof ComplexAttribute) {
                                properties.add(new Object[] { substitutedChildParticle, property });
                            } else if (property instanceof GeometryAttribute) {
                                Object attType = complex.getType().getUserData()
                                        .get(XSDTypeDefinition.class);
                                boolean duplicate = false;
                                // handle substitution group for geometries too, but make sure
                                // it's not already handled in BindingPropertyExtractor
                                // otherwise it would be encoded as xlink:href as the id has already
                                // been seen
                                if (attType != null && attType instanceof XSDTypeDefinition) {
                                    XSDTypeDefinition attTypeDef = (XSDTypeDefinition) attType;
                                    for (XSDParticle attChild : (List<XSDParticle>) Schemas
                                            .getChildElementParticles(attTypeDef, true)) {
                                        XSDElementDeclaration childEl = (XSDElementDeclaration) attChild
                                                .getContent();
                                        if (childEl.isElementDeclarationReference()) {
                                            childEl = childEl.getResolvedElementDeclaration();
                                        }
                                        if (childEl.equals(e)) {
                                            duplicate = true;
                                            break;
                                        }
                                    }
                                }
                                if (!duplicate) {
                                    properties.add(new Object[] { substitutedChildParticle,
                                            property.getValue() });
                                }
                            }
                        }
                    }
                }
            }
        }

        List<XSDParticle> anyElementParticles = new ArrayList<XSDParticle>(Schemas
                .getAnyElementParticles(element.getTypeDefinition()));
        if (anyElementParticles.size() > 0) {
            Collection complexAtts = null;
            if (object instanceof Collection) {
                // collection of features
                complexAtts = (Collection) object;
            } else if (object instanceof ComplexAttribute) {
                // get collection of features from this attribute
                complexAtts = ((ComplexAttribute) object).getProperties();
            }

            // If child elements can't be retrieved from
            // Schemas.getChildElementParticles(element.getTypeDefinition(), true)),
            // properties list is empty. In this case, add all the complex
            // attributes in the object to the properties list.
            if (properties.isEmpty()) {
                for (Object complex : complexAtts) {
                    // only process complex attributes
                    if (complex instanceof ComplexAttribute) {
                        ComplexAttribute newComplexAtt = (ComplexAttribute) complex;
                        PropertyDescriptor descriptor = newComplexAtt.getDescriptor();
                        if (descriptor.getUserData() != null) {
                            Object propertyElement = descriptor.getUserData().get(
                                    XSDElementDeclaration.class);
                            if (propertyElement != null
                                    && propertyElement instanceof XSDElementDeclaration) {
                                XSDParticle substitutedChildParticle = XSDFactory.eINSTANCE
                                        .createXSDParticle();
                                substitutedChildParticle.setMaxOccurs(descriptor.getMaxOccurs());
                                substitutedChildParticle.setMinOccurs(descriptor.getMinOccurs());
                                XSDElementDeclaration wrapper = XSDFactory.eINSTANCE
                                        .createXSDElementDeclaration();
                                wrapper
                                        .setResolvedElementDeclaration((XSDElementDeclaration) propertyElement);
                                substitutedChildParticle.setContent(wrapper);
                                properties.add(new Object[] { substitutedChildParticle,
                                        newComplexAtt });
                            }
                        }
                    }
                }
            }

            /*
             * properties list is not empty.
             *
             * It's possible <any> and <element> co-exist in the same type. For example,
             *
             * <sequence>
             *     <any/>
             *     <element name="..." type="...">
             * </sequence>
             *
             * In this case, only add <any> complex attributes to the properties list. The following
             * code is not covered in unit test, as app-schema, doesn't support <any> as a
             * targetAttribute in a mapping file.
             */
            else {
                List<XSDParticle> elementParticles = new ArrayList<XSDParticle>(Schemas
                        .getChildElementParticles(element.getTypeDefinition(), false));
                for (Object complex : complexAtts) {
                    if (complex instanceof ComplexAttribute) {
                        ComplexAttribute newComplexAtt = (ComplexAttribute) complex;
                        PropertyDescriptor descriptor = ((Attribute) complex).getDescriptor();
                        if (descriptor.getUserData() != null) {
                            Object propertyElement = descriptor.getUserData().get(
                                    XSDElementDeclaration.class);
                            if (propertyElement != null
                                    && propertyElement instanceof XSDElementDeclaration) {
                                XSDParticle substitutedChildParticle = XSDFactory.eINSTANCE
                                        .createXSDParticle();
                                substitutedChildParticle.setMaxOccurs(descriptor.getMaxOccurs());
                                substitutedChildParticle.setMinOccurs(descriptor.getMinOccurs());
                                XSDElementDeclaration wrapper = XSDFactory.eINSTANCE
                                        .createXSDElementDeclaration();
                                wrapper
                                        .setResolvedElementDeclaration((XSDElementDeclaration) propertyElement);
                                substitutedChildParticle.setContent(wrapper);
                                boolean propertyExist = false;
                                for (XSDParticle childParticle : elementParticles) {
                                    XSDElementDeclaration childElement = (XSDElementDeclaration) childParticle
                                            .getContent();
                                    if (childElement.isElementDeclarationReference()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.