Examples of XSDParticle


Examples of org.eclipse.xsd.XSDParticle

      @SuppressWarnings("unused")
      CtField ctField = launcher.getFactory().Field().create(ctClass, modifiers, ctTypeRef, "myField");
      scanner.visitCtPackage(ctPackage);     
     
      XSDComplexTypeDefinition complexType = scanner.typeXSDComplexTypeMap.get(ctClass);
      XSDParticle parentParticle = (XSDParticle)complexType.getContent();
      XSDModelGroup parentModelGroup = (XSDModelGroup)parentParticle.getContent();
      XSDParticle localElementParticle = (XSDParticle)parentModelGroup.getContents().get(0);
      XSDElementDeclaration elementdecl = (XSDElementDeclaration)localElementParticle.getContent();
      assertTrue(elementdecl.getName().equals("myField"));
      assertTrue(elementdecl.getTargetNamespace().equals(ctPackage.getQualifiedName()));     
    }catch(Exception e){
      System.err.println("Exception: " + e.getMessage());
      assertTrue(false);
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

                if (children == null) {
                    children = new ListOrderedMap();

                    for (Iterator i = Schemas.getChildElementParticles(parent.getType(), true)
                                             .iterator(); i.hasNext();) {
                        XSDParticle particle = (XSDParticle) i.next();
                        XSDElementDeclaration child = (XSDElementDeclaration) particle.getContent();

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

Examples of org.eclipse.xsd.XSDParticle

        return children;
    }

    public XSDElementDeclaration getChildElement(XSDElementDeclaration parent, QName childName) {
        OrderedMap children = (OrderedMap) children(parent);
        XSDParticle particle = (XSDParticle) children.get(childName);

        if (particle != null) {
            XSDElementDeclaration child = (XSDElementDeclaration) particle.getContent();

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

            return child;
        }

        if ("*".equals(childName.getNamespaceURI())) {
            //do a check just on local name
            ArrayList matches = new ArrayList();

            for (Iterator e = children.entrySet().iterator(); e.hasNext();) {
                Map.Entry entry = (Map.Entry) e.next();
                QName name = (QName) entry.getKey();

                if (name.getLocalPart().equals(childName.getLocalPart())) {
                    matches.add(entry.getValue());
                }
            }

            if (matches.size() == 1) {
                particle = (XSDParticle) matches.get(0);

                XSDElementDeclaration child = (XSDElementDeclaration) particle.getContent();

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

View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

        // build the feaure type by walking through the elements of the
        // actual xml schema type
        List children = Schemas.getChildElementParticles(element.getType(), true);

        for (Iterator itr = children.iterator(); itr.hasNext();) {
            XSDParticle particle = (XSDParticle) itr.next();
            XSDElementDeclaration property = (XSDElementDeclaration) particle.getContent();

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

            final ArrayList bindings = new ArrayList();
            BindingWalker.Visitor visitor = new BindingWalker.Visitor() {
                    public void visit(Binding binding) {
                        bindings.add(binding);
                    }
                };

            bwFactory.walk(property, visitor);

            if (bindings.isEmpty()) {
                // could not find a binding, use the defaults
                LOGGER.warning( "Could not find binding for " + property.getQName() + ", using XSAnyTypeBinding." );
                bindings.add( new XSAnyTypeBinding() );
            }

            // get hte last binding in the chain to execute
            Binding last = ((Binding) bindings.get(bindings.size() - 1));
            Class theClass = last.getType();

            if (theClass == null) {
                throw new RuntimeException("binding declares null type: " + last.getTarget());
            }

            // get the attribute properties
            int min = particle.getMinOccurs();
            int max = particle.getMaxOccurs();

            //check for uninitialized values
            if (min == -1) {
                min = 0;
            }
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

                    ElementInstance parentElement = (ElementInstance) parent.getComponent();
                    List childParticles = index.getChildElementParticles(parentElement
                            .getElementDeclaration());

                    if (childParticles.size() == 1) {
                        XSDParticle particle = (XSDParticle) childParticles.iterator().next();
                        XSDElementDeclaration child = (XSDElementDeclaration) particle.getContent();

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

Examples of org.eclipse.xsd.XSDParticle

        List particles = Schemas.getChildElementParticles(type, true);
        List properties = new ArrayList();

    O:  for (int i = 0; i < particles.size(); i++) {
            XSDParticle particle = (XSDParticle) particles.get(i);
            XSDElementDeclaration attribute = (XSDElementDeclaration) particle.getContent();

            if (attribute.isElementDeclarationReference()) {
                attribute = attribute.getResolvedElementDeclaration();
            }
           
            if (gml.qName("boundedBy")
                    .equals(new QName(attribute.getTargetNamespace(), attribute.getName()))) {
                BoundingBox bounds = getBoundedBy(feature, configuration);
                if (bounds != null) {
                    properties.add(new Object[] { particle, bounds });
                }
            } else if (featureType instanceof SimpleFeatureType) {
                // first simple feature hack, if the schema "overrides" gml attributes like
                // name and description, ignore the gml version
                boolean skip = false;
                if (gml.getNamespaceURI().equals(attribute.getTargetNamespace())) {
                    for (int j = i+1; j < particles.size(); j++) {
                        XSDParticle particle2 = (XSDParticle) particles.get(j);
                        XSDElementDeclaration attribute2 = (XSDElementDeclaration) particle2.getContent();
                        if (attribute2.isElementDeclarationReference()) {
                            attribute2 = attribute2.getResolvedElementDeclaration();
                        }
                        if (attribute2.getName().equals(attribute.getName())) {
                            skip = true;
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

                //TODO: do a proper mapping
                element.setTypeDefinition(schemaIndex.getTypeDefinition(XS.STRING));
            }
           

            XSDParticle particle = f.createXSDParticle();
            particle.setMinOccurs(attribute.getMinOccurs());
            particle.setMaxOccurs(attribute.getMaxOccurs());
            particle.setContent(element);
            particle.setElement( dom.createElementNS( XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "element" ) );
           
            group.getContents().add(particle);
        }

        XSDParticle particle = f.createXSDParticle();
        particle.setContent(group);
        particle.setElement( dom.createElementNS( XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "sequence") );
        type.setContent(particle);
        return type;
    }
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

        //first get all the properties that can be infered from teh schema
        List children = encoder.getSchemaIndex().getChildElementParticles(element);

O:
        for (Iterator itr = children.iterator(); itr.hasNext();) {
            XSDParticle particle = (XSDParticle) itr.next();
            XSDElementDeclaration child = (XSDElementDeclaration) particle.getContent();

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

            //get the object(s) for this element
            GetPropertyExecutor executor = new GetPropertyExecutor(object, child);

            BindingVisitorDispatch.walk(object, encoder.getBindingWalker(), element, executor,
                    context);

            if (executor.getChildObject() != null) {
                properties.add(new Object[] { particle, executor.getChildObject() });
            }
        }

        //second, get the properties which cannot be infereed from the schema
        GetPropertiesExecutor executor = new GetPropertiesExecutor(object,element);

        BindingVisitorDispatch.walk(object, encoder.getBindingWalker(), element, executor, context);

        if (!executor.getProperties().isEmpty()) {
            //group into a map of name, list
            MultiHashMap map = new MultiHashMap();

            for (Iterator p = executor.getProperties().iterator(); p.hasNext();) {
                Object[] property = (Object[]) p.next();
                map.put(property[0], property[1]);
            }

            //turn each map entry into a particle
            HashMap particles = new HashMap();

            for (Iterator e = map.entrySet().iterator(); e.hasNext();) {
                Map.Entry entry = (Map.Entry) e.next();
               
                //key could be a name or a particle
                if ( entry.getKey() instanceof XSDParticle ) {
                    XSDParticle particle = (XSDParticle) entry.getKey();
                    particles.put( Schemas.getParticleName( particle), particle );
                    continue;
                }
               
                QName name = (QName) entry.getKey();
                Collection values = (Collection) entry.getValue();

                //check for comment
                if (Encoder.COMMENT.equals(name)) {
                    //create a dom element which text nodes for the comments
                    Element comment = encoder.getDocument()
                                             .createElement(Encoder.COMMENT.getLocalPart());

                    for (Iterator v = values.iterator(); v.hasNext();) {
                        comment.appendChild(encoder.getDocument().createTextNode(v.next().toString()));
                    }

                    XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();

                    XSDElementDeclaration elementDecl = XSDFactory.eINSTANCE
                        .createXSDElementDeclaration();
                    elementDecl.setTargetNamespace(Encoder.COMMENT.getNamespaceURI());
                    elementDecl.setName(Encoder.COMMENT.getLocalPart());
                    elementDecl.setElement(comment);

                    particle.setContent(elementDecl);
                    particles.put(name, particle);

                    continue;
                }

                //find hte element
                XSDElementDeclaration elementDecl = encoder.getSchemaIndex()
                                                           .getElementDeclaration(name);

                if (elementDecl == null) {
                    //look for the element declaration as a particle of the containing type
                    XSDParticle particle =
                        Schemas.getChildElementParticle(element.getType(), name.getLocalPart(), true);
                    if (particle != null) {
                        particles.put(name, particle);
                        continue;
                    }
                }

                if (elementDecl == null) {
                    //TODO: resolving like this will return an element no
                    // matter what, modifying the underlying schema, this might
                    // be dangerous. What we shold do is force the schema to
                    // resolve all of it simports when the encoder starts
                    elementDecl = encoder.getSchema()
                                         .resolveElementDeclaration(name.getNamespaceURI(),
                            name.getLocalPart());
                }

                //look for a particle in the containing type which is either
                // a) a base type of the element
                // b) in the same subsittuion group
                // if found use the particle to dervice multiplicity
                XSDParticle reference = null;
                for ( Iterator p = Schemas.getChildElementParticles(element.getType(), true).iterator(); p.hasNext(); ) {
                    XSDParticle particle = (XSDParticle) p.next();
                    XSDElementDeclaration el = (XSDElementDeclaration) particle.getContent();
                    if ( el.isElementDeclarationReference() ) {
                        el = el.getResolvedElementDeclaration();
                    }
                   
                    if ( Schemas.isBaseType(elementDecl, el) ) {
                        reference = particle;
                        break;
                    }
                }
               
                //wrap the property in a particle
                XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
                XSDElementDeclaration wrapper = XSDFactory.eINSTANCE.createXSDElementDeclaration();
                wrapper.setResolvedElementDeclaration( elementDecl );
                particle.setContent(wrapper);
                //particle.setContent(elementDecl);

                //if there is a reference, derive multiplicity
                if ( reference != null ) {
                    particle.setMaxOccurs( reference.getMaxOccurs() );
                }
                else {
                    //dervice from collection
                    if ( values.size() > 1) {
                        //make a multi property
                        particle.setMaxOccurs(-1);
                    } else {
                        //single property
                        particle.setMaxOccurs(1);
                    }   
                }
               
                particles.put(name, particle);
            }

            //process the particles in order in which we got the properties
            for (Iterator p = executor.getProperties().iterator(); p.hasNext();) {
                Object[] property = (Object[]) p.next();
                Collection values = (Collection) map.get( property[0] );
               
                QName name;
                if ( property[0instanceof XSDParticle ) {
                    name = Schemas.getParticleName( (XSDParticle) property[0] );
                }
                else {
                    name = (QName) property[0];
                }

                XSDParticle particle = (XSDParticle) particles.get(name);

                if (particle == null) {
                    continue; //already processed, must be a multi property
                }
               
                if (values.size() > 1) {
                    //add as is, the encoder will unwrap
                    properties.add(new Object[] { particle, values });
                } else {
                    //unwrap it
                    properties.add(new Object[] { particle, values.iterator().next() });
                }

                //done with this particle
                particles.remove(name);
            }
        }
       
        //return properties;       
        if (properties.size()<=1){
            return properties;
        }
       
        /*
         feature properties in the "properties" list may not be in the same order as they appear in the schema,
         because in the above implementation, simple attributes and complex attributes are processed separately.
         
         to maintain the feature properties order, sort the properties to their original order as in "children" list              
        */
        if (object instanceof ComplexAttributeImpl && propertiesSortable(properties, children)) {
            List sortedProperties = new ArrayList();
           
            //sort properties according to their XSDParticle order in "children"
            for (int i = 0; i<children.size(); i++) {
                XSDParticle particle = (XSDParticle) children.get(i);
                XSDElementDeclaration child = (XSDElementDeclaration) particle.getContent();
                if (child.getResolvedElementDeclaration() != null) {
                    child = child.getResolvedElementDeclaration();
                }

                for (Iterator itr = properties.iterator(); itr.hasNext();) {
                    Object[] prop = (Object[]) itr.next();
                    XSDParticle part = (XSDParticle) prop[0];
                    XSDElementDeclaration partContent = (XSDElementDeclaration) part.getContent();
                    if (partContent.getResolvedElementDeclaration() != null) {
                        partContent = partContent.getResolvedElementDeclaration();
                    }
                    if (child.getName().equals(partContent.getName())
                            && ((child.getTargetNamespace() != null && partContent
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

            return false;
        }

        for (Iterator itr = properties.iterator(); itr.hasNext();) {
            Object[] prop = (Object[]) itr.next();
            XSDParticle part = (XSDParticle) prop[0];
            XSDElementDeclaration partContent = (XSDElementDeclaration) part.getContent();
            if (partContent.getResolvedElementDeclaration() != null) {
                partContent = partContent.getResolvedElementDeclaration();
            }
            boolean notFound = true;
            for (int i = 0; i < children.size(); i++) {
                XSDParticle particle = (XSDParticle) children.get(i);
                XSDElementDeclaration child = (XSDElementDeclaration) particle.getContent();
                if (child.getResolvedElementDeclaration() != null) {
                    child = child.getResolvedElementDeclaration();
                }
                if (child.getName().equals(partContent.getName()) &&
                        (child.getTargetNamespace()==null? partContent.getTargetNamespace()==null :
View Full Code Here

Examples of org.eclipse.xsd.XSDParticle

    public static final XSDParticle getChildElementParticle(XSDTypeDefinition type, String name,
        boolean includeParents) {
        List particles = getChildElementParticles(type, includeParents);

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

            if (element.isElementDeclarationReference()) {
                element.getResolvedElementDeclaration();
            }
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.