Package org.jibx.schema

Examples of org.jibx.schema.SchemaHolder


     * @param namemap map from qualified name to holder for defining schema (only for predefined schemas)
     * @param holder schema making the reference
     */
    private void addSchemaReference(QName qname, Map namemap, SchemaHolder holder) {
        if (qname != null && !IComponent.SCHEMA_NAMESPACE.equals(qname.getUri())) {
            SchemaHolder target = (SchemaHolder)namemap.get(qname);
            if (target == null) {
                target = (SchemaHolder)m_uriSchemaMap.get(qname.getUri());
            }
            holder.addReference(target);
        }
View Full Code Here


            def.setPortTypeDocumentation(nodes);
        }
       
        // find or create the schema element and namespace
        String sns = service.getNamespace();
        SchemaHolder holder = m_schemaGenerator.findSchema(sns);
        SchemaElement schema = holder.getSchema();
       
        // process messages and operations used by service
        ArrayList ops = service.getOperations();
        Map fltmap = new HashMap();
        Set imports = new InsertionOrderedSet();
        Map typemap = new HashMap(ptypemap);
        for (int i = 0; i < ops.size(); i++) {
           
            // get information for operation
            OperationCustom odef = (OperationCustom)ops.get(i);
            String oname = odef.getOperationName();
            Operation op = new Operation(oname);
            op.setDocumentation(odef.getDocumentation());
            op.setSoapAction(odef.getSoapAction());
           
            // generate input message information
            Message rqmsg = new Message(odef.getRequestMessageName(), wns);
            op.addInputMessage(rqmsg);
            def.addMessage(rqmsg);
            QName rqelem = null;
            if (m_generationParameters.isDocLit()) {
               
                // check if input parameter defined for method
                ArrayList parms = odef.getParameters();
                if (parms.size() > 0) {
                   
                    // check for existing element definition matching the parameter type
                    ValueCustom parm = (ValueCustom)parms.get(0);
                    rqelem = (QName)classelems.get(parm.getWorkingType());
                    if (rqelem == null) {
                       
                        // create new element for parameter
                        ElementElement pelem = buildValueElement(parm, ptypemap, typeschemas, holder);
                        schema.getTopLevelChildren().add(pelem);
                        rqelem = pelem.getQName();
                       
                    } else {
                       
                        // import and use existing element definition
                        imports.add(elemschemas.get(rqelem));
                        addSchemaReference(rqelem, elemschemas, holder);
                       
                    }
                }
               
            } else {
               
                // construct a sequence for wrapped method parameters
                SequenceElement seq = new SequenceElement();
                ArrayList parms = odef.getParameters();
                for (int j = 0; j < parms.size(); j++) {
                    ValueCustom parm = (ValueCustom)parms.get(j);
                    String type = parm.getWorkingType();
                    ElementElement pelem;
                    if (!typemap.containsKey(type)) {
                       
                        // add predefined mapping type to known types and require schema import
                        QName tname = (QName)classtypes.get(type);
                        if (tname != null) {
                            typemap.put(type, tname);
                            imports.add(typeschemas.get(tname));
                        }
                       
                    }
                    pelem = buildValueElement(parm, ptypemap, typeschemas, holder);
                    seq.getParticleList().add(pelem);
                }
               
                // add corresponding schema definition to schema
                ComplexTypeElement tdef = new ComplexTypeElement();
                tdef.setContentDefinition(seq);
                ElementElement elem = new ElementElement();
                String wname = odef.getRequestWrapperName();
                elem.setName(wname);
                elem.setTypeDefinition(tdef);
                schema.getTopLevelChildren().add(elem);
                rqelem = new QName(sns, wname);
               
            }
           
            // add part definition to message (if present)
            if (rqelem != null) {
                MessagePart part = new MessagePart("part", rqelem);
                rqmsg.getParts().add(part);
                def.addNamespace(rqelem.getUri());
            }
           
            // generate output message information
            Message rsmsg = new Message(odef.getResponseMessageName(), wns);
            op.addOutputMessage(rsmsg);
            def.addMessage(rsmsg);
            ValueCustom rtrn = odef.getReturn();
            QName rselem = null;
            if (m_generationParameters.isDocLit()) {
               
                // check if return value defined for method
                if (!"void".equals(rtrn.getWorkingType())) {
                   
                    // check for existing element definition matching the return type
                    rselem = (QName)classelems.get(rtrn.getWorkingType());
                    if (rselem == null) {
                       
                        // create new element for return
                        ElementElement relem = buildValueElement(rtrn, ptypemap, typeschemas, holder);
                        schema.getTopLevelChildren().add(relem);
                        rselem = relem.getQName();
                       
                    } else {
                       
                        // import and use existing element definition
                        imports.add(elemschemas.get(rselem));
                        addSchemaReference(rqelem, elemschemas, holder);
                       
                    }
                }
               
            } else {
               
                // add corresponding schema definition to schema
                SequenceElement seq = new SequenceElement();
                if (!"void".equals(rtrn.getWorkingType())) {
                    ElementElement relem = buildValueElement(rtrn, ptypemap, typeschemas, holder);
                    seq.getParticleList().add(relem);
                }
                ComplexTypeElement tdef = new ComplexTypeElement();
                tdef.setContentDefinition(seq);
                ElementElement elem = new ElementElement();
                String wname = odef.getResponseWrapperName();
                elem.setName(wname);
                elem.setTypeDefinition(tdef);
                schema.getTopLevelChildren().add(elem);
                rselem = new QName(sns, wname);
               
            }
           
            // add part definition to message (if present)
            if (rselem != null) {
                MessagePart part = new MessagePart("part", rselem);
                rsmsg.getParts().add(part);
                def.addNamespace(rselem.getUri());
            }
           
            // process fault message(s) for operation
            ArrayList thrws = odef.getThrows();
            WsdlCustom wsdlcustom = m_generationParameters.getWsdlCustom();
            for (int j = 0; j < thrws.size(); j++) {
                ThrowsCustom thrw = (ThrowsCustom)thrws.get(j);
                String type = thrw.getType();
                Message fmsg = (Message)fltmap.get(type);
                if (fmsg == null) {
                   
                    // first time for this throwable, create the message
                    FaultCustom fault = wsdlcustom.forceFaultCustomization(type);
                    QName fqname = new QName(sns, fault.getElementName());
                    MessagePart part = new MessagePart("fault", fqname);
                    fmsg = new Message(fault.getFaultName(), wns);
                    fmsg.getParts().add(part);
                    def.addMessage(fmsg);
                    def.addNamespace(sns);
                   
                    // make sure the corresponding mapping exists
                    BindingMappingDetail detail = m_bindingGenerator.getMappingDetail(fault.getDataType());
                    if (detail == null) {
                        throw new IllegalStateException("No mapping found for type " + type);
                    }
                   
                    // record that the fault has been defined
                    fltmap.put(type, fmsg);
                }
               
                // add fault to operation definition
                op.addFaultMessage(fmsg);
            }
           
            // add operation to list of definitions
            def.addOperation(op);
           
        }
       
        // include embedded schema for message definitions only if needed
        if (holder.getReferences().size() > 0 || schema.getChildCount() > 0) {
            def.getSchemas().add(schema);
        }
        return def;
    }
View Full Code Here

            }
           
            // build and record the schemas
            List schemas = m_schemaGenerator.buildSchemas(bindings);
            for (Iterator iter = schemas.iterator(); iter.hasNext();) {
                SchemaHolder holder = (SchemaHolder)iter.next();
                m_uriSchemaMap.put(holder.getNamespace(), holder);
            }
        }
       
        // build the WSDL for each service
        ArrayList wsdls = new ArrayList();
View Full Code Here

            final Set exists = new HashSet();
            TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
            for (Iterator iter = resolves.iterator(); iter.hasNext();) {
                SchemaElement schema = vctx.getSchemaById(((ISchemaResolver)iter.next()).getId());
                exists.add(schema);
                final SchemaHolder holder = new SchemaHolder(schema);
                SchemaVisitor visitor = new SchemaVisitor() {
                   
                    public boolean visit(SchemaBase node) {
                        return false;
                    }
View Full Code Here

     *
     * @param uri namespace URI (<code>null</code> if no namespace)
     * @return schema holder
     */
    public SchemaHolder findSchema(String uri) {
        SchemaHolder hold = (SchemaHolder)m_uriSchemas.get(uri);
        if (hold == null) {
            hold = new SchemaHolder(uri);
            m_uriSchemas.put(uri, hold);
            String sname;
            if (uri == null) {
                sname = (String)m_uriNames.get("");
                if (sname == null) {
                    sname = "nonamespace.xsd";
                }
            } else {
                sname = (String)m_uriNames.get(uri);
                if (sname == null) {
                    sname = uri.substring(uri.lastIndexOf('/') + 1) + ".xsd";
                }
            }
            hold.setFileName(sname);
        }
        return hold;
    }
View Full Code Here

     * @param hold schema holder
     */
    private void checkDependency(QName qname, SchemaHolder hold) {
        if (isDifferentSchema(qname, hold)) {
            String uri = qname.getUri();
            SchemaHolder tohold = findSchema(uri);
            hold.addReference(tohold);
            hold.getPrefix(uri);
        }
    }
View Full Code Here

        // start by generating group/attributeGroup schema components
        MappingElementBase mapping = detail.getMapping();
        if (detail.isGroup()) {
            // TODO: extend base type for group/attributeGroup?
            QName qname = detail.getOtherName();
            SchemaHolder hold = findSchema(qname.getUri());
            if (detail.hasChild()) {
                GroupElement group = new GroupElement();
                group.setName(qname.getName());
                group.setDefinition(buildCompositor(mapping, 0, false, hold));
                addDocumentation(info, group);
                hold.getSchema().getTopLevelChildren().add(group);
            }
            if (detail.hasAttribute()) {
                AttributeGroupElement attgrp = new AttributeGroupElement();
                attgrp.setName(qname.getName());
                fillAttributes(mapping, 0, attgrp.getAttributeList(), hold);
                addDocumentation(info, attgrp);
                hold.getSchema().getTopLevelChildren().add(attgrp);
            }
        }
       
        // next generate the complex type definition
        if (detail.isType()) {
           
            // set up the basic definition structure
            QName qname = detail.getTypeName();
            SchemaHolder hold = findSchema(qname.getUri());
            ComplexTypeElement type = buildComplexType(detail, hold);
            type.setName(qname.getName());
            addDocumentation(info, type);
            hold.getSchema().getTopLevelChildren().add(type);
        }
       
        // finish by generating element definition
        if (detail.isElement()) {
            QName qname = detail.getOtherName();
            SchemaHolder hold = findSchema(qname.getUri());
            ElementElement elem = new ElementElement();
            elem.setName(qname.getName());
            setSubstitutionGroup(detail.getSubstitution(), elem, hold);
            if (detail.isType()) {
                setElementType(detail.getTypeName(), elem, hold);
            } else {
               
                // check for just an element wrapper around type reference
                MappingElementBase ext = detail.getExtensionBase();
                if (ext != null && !detail.hasAttribute() && mapping.getContentComponents().size() == 1) {
                    setElementType(ext.getTypeQName(), elem, hold);
                } else {
                   
                    // add documentation to element which is not also a type
                    addDocumentation(info, elem);
                    elem.setTypeDefinition(buildComplexType(detail, hold));
                }
            }
            hold.getSchema().getTopLevelChildren().add(elem);
        }
    }
View Full Code Here

            EnumDetail detail = (EnumDetail)iter.next();
            if (detail.isGlobal()) {
                ClassCustom custom = detail.getCustom();
                SimpleTypeElement type = buildSimpleType(custom.getClassInformation());
                type.setName(custom.getTypeName());
                SchemaHolder hold = findSchema(custom.getNamespace());
                hold.getSchema().getTopLevelChildren().add(type);
                m_classSimpletypes.put(custom.getName(), custom.getTypeQName());
            }
        }
       
        // process all the mapping definitions from directory
View Full Code Here

       
        // fix all references between schemas
        ArrayList holders = new ArrayList(m_uriSchemas.values());
        SchemaElement[] schemas = new SchemaElement[holders.size()];
        for (int i = 0; i < holders.size(); i++) {
            SchemaHolder hold = (SchemaHolder)holders.get(i);
            hold.finish();
            schemas[i] = hold.getSchema();
        }
       
        // set up validation with in-memory schemas
        org.jibx.schema.validation.ValidationContext vctx = new org.jibx.schema.validation.ValidationContext();
        for (int i = 0; i < holders.size(); i++) {
            SchemaHolder holder = (SchemaHolder)holders.get(i);
            String id = holder.getFileName();
            SchemaElement schema = holder.getSchema();
            schema.setResolver(new MemoryResolver(id));
            vctx.setSchema(id, schema);
        }
        for (Iterator iter = exists.iterator(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
View Full Code Here

     * @throws IOException
     */
    public static void writeSchemas(File dir, Collection schemas) throws JiBXException, IOException {
        IBindingFactory fact = BindingDirectory.getFactory(SchemaUtils.XS_PREFIX_BINDING, SchemaElement.class);
        for (Iterator iter = schemas.iterator(); iter.hasNext();) {
            SchemaHolder holder = (SchemaHolder)iter.next();
            if (!holder.isExistingFile()) {
                IMarshallingContext ictx = fact.createMarshallingContext();
                File file = new File(dir, holder.getFileName());
                ictx.setOutput(new FileOutputStream(file), null);
                ictx.setIndent(2);
                ((IMarshallable)holder.getSchema()).marshal(ictx);
                ictx.getXmlWriter().flush();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.jibx.schema.SchemaHolder

Copyright © 2018 www.massapicom. 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.