Examples of XSDElementDeclaration


Examples of org.eclipse.xsd.XSDElementDeclaration

        //element whose type is set as 'this type'.  Otherwise when setting the type for the element
        //there will be a duplicate prefix (like Q1 or Q2... ) that will be created
        prefix = addImports((XSDSchema)schemaMap.get(targetNamespace), elementSchemaType);
       
        //XmlSchemaElement element = new XmlSchemaElement();
        XSDElementDeclaration element = xsdFactory.createXSDElementDeclaration();
        element.setName(aProperty.getName());
        
        XSDParticle aParticle = xsdFactory.createXSDParticle();
        aParticle.setContent(element);
       
        ((XSDModelGroup)((XSDParticle)complexType.getContent()).getContent()).
        getContents().add(aParticle);
       
        element.updateElement();

        if ( aProperty.isMany() )
        {
            aParticle.setMaxOccurs(-1);
            aParticle.setMinOccurs(0);
           
        }
       
        if ( aProperty.isContainment() )
        {
            element.setTypeDefinition(typeTable.getXSDTypeDef(elementSchemaType.getNamespaceURI(),
                                                                elementSchemaType.getLocalPart()));
        }
        else
        {
            if ( !aProperty.getType().isDataType() )
            {
                QName qName = typeTable.getSimpleSchemaTypeName("URI");
                element.setTypeDefinition(typeTable.getXSDTypeDef(qName.getNamespaceURI(),
                                            qName.getLocalPart()));
            }
        }
       
        addAnnotations(element, aProperty);
        if ( !aProperty.isContainment() && !aProperty.getType().isDataType() )
        {
            String value = prefix + COLON + elementSchemaType.getLocalPart();
            element.getElement().setAttribute(PROPERTY_TYPE, value);
        }
        return elementSchemaType;
       
    }
View Full Code Here

Examples of org.eclipse.xsd.XSDElementDeclaration

   
    private void createGlobalElement(XSDSchema xmlSchema,
                                         XSDComplexTypeDefinition complexType,
                                         QName schemaElementName )
    {
        XSDElementDeclaration globalElement = xsdFactory.createXSDElementDeclaration();
        globalElement.setTargetNamespace(xmlSchema.getTargetNamespace());
        globalElement.setName(formGlobalElementName(complexType.getName()));
        globalElement.setTypeDefinition
            (typeTable.getXSDTypeDef(schemaElementName.getNamespaceURI(),
                                                    schemaElementName.getLocalPart()));
        xmlSchema.getContents().add(globalElement);
        xmlSchema.getElementDeclarations().add(globalElement);
    }
View Full Code Here

Examples of org.eclipse.xsd.XSDElementDeclaration

            if (meta != null) {
                //found it
                XSDSchema schema = schemaBuilder.build(meta, null);

                for (Iterator e = schema.getElementDeclarations().iterator(); e.hasNext();) {
                    XSDElementDeclaration element = (XSDElementDeclaration) e.next();

                    if (name.getLocalPart().equals(element.getName())) {
                        return new ElementHandlerImpl(element, parent, parser);
                    }
                }
            }
        } catch (IOException e) {
View Full Code Here

Examples of org.eclipse.xsd.XSDElementDeclaration

        QName newTypeName = guessValueType(property.getValue());
        XSDTypeDefinition type = (newTypeName != null) ? index.getTypeDefinition(newTypeName) : null;

        if (type != null) {
            //create a new particle based on the new type
            XSDElementDeclaration value = XSDFactory.eINSTANCE.createXSDElementDeclaration();
            value.setName("Value");
            value.setTypeDefinition(type);

            XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
            particle.setMinOccurs(1);
            particle.setMaxOccurs(1);
            particle.setContent(value);
View Full Code Here

Examples of org.eclipse.xsd.XSDElementDeclaration

            if ( filterAttributeType( attribute ) ) {
                continue;
            }
           
          
            XSDElementDeclaration element = factory.createXSDElementDeclaration();
            element.setName(attribute.getLocalName());
            element.setNillable(attribute.isNillable());

           
            Class binding = attribute.getType().getBinding();
            Name typeName = findTypeName(binding);

            if (typeName == null) {
                throw new NullPointerException("Could not find a type for property: "
                    + attribute.getName() + " of type: " + binding.getName());
            }

            XSDTypeDefinition type = index.getTypeDefinition( new QName( typeName.getNamespaceURI(), typeName.getLocalPart() ) );
            if ( type == null ) {
                throw new IllegalStateException( "Could not find type: " + typeName );
            }
            //XSDTypeDefinition type = schema.resolveTypeDefinition(typeName.getNamespaceURI(),
            //        typeName.getLocalPart());
            element.setTypeDefinition(type);

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

        XSDParticle particle = factory.createXSDParticle();
        particle.setContent(group);

        complexType.setContent(particle);

        schema.getContents().add(complexType);

        XSDElementDeclaration element = factory.createXSDElementDeclaration();
        element.setName(name);

        element.setSubstitutionGroupAffiliation(schema.resolveElementDeclaration(GML.NAMESPACE,
                "_Feature"));
        element.setTypeDefinition(complexType);

        schema.getContents().add(element);
        schema.updateElement();
    }
View Full Code Here

Examples of org.eclipse.xsd.XSDElementDeclaration

                    " Falling back on native feature type");
            }
            if ( schema != null ) {
                XSDTypeDefinition type = null;
                for ( Iterator e = schema.getElementDeclarations().iterator(); e.hasNext(); ) {
                    XSDElementDeclaration element = (XSDElementDeclaration) e.next();
                    if ( ft.getName().equals( element.getName() ) ) {
                        type = element.getTypeDefinition();
                        break;
                    }
                }
                if ( type == null ) {
                    for ( Iterator t = schema.getTypeDefinitions().iterator(); t.hasNext(); ) {
                        XSDTypeDefinition typedef = (XSDTypeDefinition) t.next();
                        if ( (ft.getName() + "_Type").equals( typedef.getName() ) ) {
                            type = typedef;
                            break;
                        }
                    }
                }
               
                if ( type != null ) {
                    List children = Schemas.getChildElementDeclarations(type,true);
                    for ( Iterator<AttributeTypeInfo> i = atts.iterator(); i.hasNext(); ) {
                        AttributeTypeInfo at = i.next();
                        boolean found = false;
                        for ( Iterator c = children.iterator(); c.hasNext(); ) {
                            XSDElementDeclaration ce = (XSDElementDeclaration) c.next();
                            if ( at.getName().equals( ce.getName() ) ) {
                                found = true;
                                if (ce.getContainer() instanceof XSDParticle) {
                                    XSDParticle part = (XSDParticle) ce.getContainer();
                                    at.setMinOccurs(part.getMinOccurs());
                                    at.setMaxOccurs(part.getMaxOccurs());
                                }
                                break;
                            }
View Full Code Here

Examples of org.eclipse.xsd.XSDElementDeclaration

                        }
                    }
                   
                    // check for element
                    if ( !hasElement && content instanceof XSDElementDeclaration ) {
                        XSDElementDeclaration element = (XSDElementDeclaration) content;
                        if ( name.equals( element.getName() ) &&
                            featureTypeMeta.getNamespace().getURI().equals( element.getTargetNamespace() ) ) {
                            hasElement = true;
                        }
                    }
                }
               
                if ( !hasElement ) {
                    //need to create an element declaration in the schema
                    XSDElementDeclaration element = factory.createXSDElementDeclaration();
                    element.setName( featureTypeMeta.getName() );
                    element.setTargetNamespace( featureTypeMeta.getNamespace().getURI() );
                    element.setSubstitutionGroupAffiliation(
                        schema.resolveElementDeclaration(gmlNamespace, substitutionGroup));
                   
                    //find the type of the element
                    List<XSDComplexTypeDefinition> candidates = new ArrayList<XSDComplexTypeDefinition>();
                    for ( Iterator t = ftSchema.getTypeDefinitions().iterator(); t.hasNext(); ) {
                        XSDTypeDefinition type = (XSDTypeDefinition) t.next();
                        if ( type instanceof XSDComplexTypeDefinition ) {
                            XSDTypeDefinition base = type.getBaseType();
                            while(base != null ) {
                                if ( baseType.equals(base.getName())
                                    && gmlNamespace.equals( base.getTargetNamespace() ) ) {
                                   
                                    candidates.add( (XSDComplexTypeDefinition) type );
                                    break;
                                }  
                                if ( base.equals( base.getBaseType() ) ) {
                                    break;
                                }
                                base = base.getBaseType();
                            }
                        }
                    }
                   
                    if ( candidates.size() != 1 ) {
                        throw new IllegalStateException("Could not determine feature type for " +
                        "generated element. Must specify explicitly in schema.xsd.");
                    }
                   
                    element.setTypeDefinition( candidates.get(0));
                    schema.getContents().add(element);
                }

                schema.getContents().addAll(contents);
                schema.updateElement();
View Full Code Here

Examples of org.eclipse.xsd.XSDElementDeclaration

        if (!findTypeInSchema(featureTypeMeta, schema, factory)) {
            // build the type manually
            XSDComplexTypeDefinition xsdComplexType = buildComplexSchemaContent(featureTypeMeta
                    .getFeatureType(), schema, factory);

            XSDElementDeclaration element = factory.createXSDElementDeclaration();
            element.setName(featureTypeMeta.getName());

            element.setSubstitutionGroupAffiliation(schema.resolveElementDeclaration(gmlNamespace,
                    substitutionGroup));
            element.setTypeDefinition(xsdComplexType);

            schema.getContents().add(element);

            schema.updateElement();
        }
View Full Code Here

Examples of org.eclipse.xsd.XSDElementDeclaration

                if ( filterAttributeType( attribute ) ) {
                    continue;
                }

                XSDElementDeclaration element = factory.createXSDElementDeclaration();
                element.setName(attribute.getLocalName());
                element.setNillable(attribute.isNillable());

                Name typeName = attribute.getType().getName();
                // skip if it's XS.AnyType. It's not added to XS.Profile, because
                // a lot of types extend XS.AnyType causing it to be the returned
                // binding.. I could make it so that it checks against all profiles
                // but would that slow things down? At the moment, it returns the
                // first matching one, so it doesn't go through all profiles.
                if (!(typeName.getLocalPart().equals(XS.ANYTYPE.getLocalPart()) && typeName
                        .getNamespaceURI().equals(XS.NAMESPACE))) {
                    if (attribute.getType() instanceof ComplexType) {
                        // If non-simple complex property not in schema, recurse.
                        // Note that abstract types will of course not be resolved; these must be
                        // configured at global level, so they can be found by the
                        // encoder.
                        if (schema.resolveTypeDefinition(typeName.getNamespaceURI(), typeName
                                .getLocalPart()) == null) {
                            buildComplexSchemaContent((ComplexType) attribute.getType(), schema,
                                    factory);
                        }
                    } else {
                        Class binding = attribute.getType().getBinding();
                        typeName = findTypeName(binding);
                        if (typeName == null) {
                            throw new NullPointerException("Could not find a type for property: "
                                    + attribute.getName() + " of type: " + binding.getName());

                        }
                    }
                }

                XSDTypeDefinition type = schema.resolveTypeDefinition(typeName.getNamespaceURI(),
                        typeName.getLocalPart());
                element.setTypeDefinition(type);

                XSDParticle particle = factory.createXSDParticle();
                particle.setMinOccurs(attribute.getMinOccurs());
                particle.setMaxOccurs(attribute.getMaxOccurs());
                particle.setContent(element);
View Full Code Here

Examples of org.eclipse.xsd.XSDElementDeclaration

    static XSDParticle particle(XSDSchema schema, String elementName,
            String typeNS, String typeName, boolean nillable, int minOccurs,
            int maxOccurs) {
        XSDFactory factory = XSDFactory.eINSTANCE;
        XSDElementDeclaration element = factory.createXSDElementDeclaration();
        element.setName(elementName);
        element.setNillable(nillable);

        XSDTypeDefinition type = schema.resolveTypeDefinition(typeNS, typeName);
        element.setTypeDefinition(type);

        XSDParticle particle = factory.createXSDParticle();
        particle.setMinOccurs(minOccurs);
        particle.setMaxOccurs(maxOccurs);
        particle.setContent(element);
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.