Package org.apache.axis2.wsdl.databinding

Examples of org.apache.axis2.wsdl.databinding.JavaTypeMapper


            WSDLExtensibilityElement extensiblityElt;
            SchemaTypeSystem sts = null;
            Vector xmlObjectsVector = new Vector();
            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();

            for (int i = 0; i < typesArray.size(); i++) {
                extensiblityElt = (WSDLExtensibilityElement) typesArray.get(i);
                Schema schema;

                if (ExtensionConstants.SCHEMA.equals(extensiblityElt.getType())) {
                    schema = (Schema) extensiblityElt;
                    XmlOptions options = new XmlOptions();

                    options.setLoadAdditionalNamespaces(
                            configuration.getWom().getNamespaces()); //add the namespaces


                    Stack importedSchemaStack = schema.getImportedSchemaStack();
                    File schemaFolder = new File(configuration.getOutputLocation(), SCHEMA_FOLDER);
                    schemaFolder.mkdir();
                    //compile these schemas
                    while (!importedSchemaStack.isEmpty()) {
                        Element element = (Element)importedSchemaStack.pop();
                        String tagetNamespace = element.getAttribute("targetNamespace");
                        if (!processedSchemas.contains(tagetNamespace)){

                            // we are not using DOM toString method here, as it seems it depends on the
                            // JDK version that is being used.
                            String s = DOM2Writer.nodeToString(element);

                            //write the schema to a file
                            File tempFile = File.createTempFile("temp", ".xsd", schemaFolder);
                            FileWriter writer = new FileWriter(tempFile);
                            writer.write(s);
                            writer.flush();
                            writer.close();


                            xmlObjectsVector.add(
                                    XmlObject.Factory.parse(
                                            element
                                            , options));

                            processedSchemas.add(tagetNamespace);
                        }
                    }
                }
            }

            // add the third party schemas
            //todo pehaps checking the namespaces would be a good idea to
            //make the generated code work efficiently
            for (int i = 0; i < additionalSchemas.length; i++) {
                xmlObjectsVector.add(XmlObject.Factory.parse(
                        additionalSchemas[i]
                        , null));
            }

            //compile the type system
            XmlObject[] objeArray = convertToXMLObjectArray(xmlObjectsVector);
            BindingConfig config = new Axis2BindingConfig();

            //set the STS name to null. it makes the generated class include a unique (but random) STS name
            sts = XmlBeans.compileXmlBeans(null, null,
                    objeArray,
                    config, XmlBeans.getContextTypeLoader(),
                    new Axis2Filer(),
                    null);

            // prune the generated schema type system and add the list of base64 types
            FindBase64Types(sts);

            //get the schematypes and add the document types to the type mapper
            SchemaType[] schemaType = sts.documentTypes();
            SchemaType type;
            for (int j = 0; j < schemaType.length; j++) {
                type = schemaType[j];
                mapper.addTypeMapping(type.getDocumentElementName(),
                        type.getFullJavaName());
            }
            //set the type mapper to the config
            configuration.setTypeMapper(mapper);

            // write the mapper to a file for later retriival
            writeMappingsToFile(mapper.getAllTypeMappings());

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here


            SchemaCompiler schemaCompiler = new SchemaCompiler(options);
            schemaCompiler
                    .compile(xmlSchemaTypeVector);

            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();
            //get the processed element map and transfer it to the type mapper
            Map processedMap = schemaCompiler.getProcessedElementMap();
            Iterator processedkeys = processedMap.keySet().iterator();
            QName qNameKey;
            while (processedkeys.hasNext()) {
                qNameKey =(QName)processedkeys.next();
                mapper.addTypeMapping(qNameKey,processedMap.get(qNameKey));
            }

            //set the type mapper to the config
            configuration.setTypeMapper(mapper);
View Full Code Here

            Vector xmlObjectsVector = new Vector();
             //create the type mapper
        //First try to take the one that is already there
        TypeMapper mapper = configuration.getTypeMapper();
        if (mapper==null){
            mapper =new JavaTypeMapper();
        }

            for (int i = 0; i < typesList.size(); i++) {
                XmlSchema schema = (XmlSchema) typesList.get(i);
                xmlObjectsVector.add(new InputSource(new StringReader(getSchemaAsString(schema))));
View Full Code Here

            SchemaCompiler schemaCompiler = new SchemaCompiler(options);
            // run the schema compiler
            schemaCompiler.compile(xmlSchemaTypeVector);

            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();

            if (options.isWriteOutput()){
                //get the processed element map and transfer it to the type mapper
                Map processedMap = schemaCompiler.getProcessedElementMap();
                Iterator processedkeys = processedMap.keySet().iterator();
                QName qNameKey;
                while (processedkeys.hasNext()) {
                    qNameKey = (QName) processedkeys.next();
                    mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
                }

            }else{
                //get the processed model map and transfer it to the type mapper
                //since the options mentiond that its not writable, it should have
                //populated the model map
                Map processedModelMap = schemaCompiler.getProcessedModelMap();
                Iterator processedkeys = processedModelMap.keySet().iterator();
                QName qNameKey;
                while (processedkeys.hasNext()) {
                    qNameKey = (QName) processedkeys.next();
                    mapper.addTypeMappingObject(qNameKey, processedModelMap.get(qNameKey));
                }

                Map processedMap = schemaCompiler.getProcessedElementMap();
                processedkeys = processedMap.keySet().iterator();
                while (processedkeys.hasNext()) {
                    qNameKey = (QName) processedkeys.next();
                    mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
                }

                //get the ADB template from the schema compilers property bag and set the
                //template
                configuration.putProperty(XSLTConstants.EXTERNAL_TEMPLATE_PROPERTY_KEY,
View Full Code Here

            WSDLExtensibilityElement extensiblityElt;
            SchemaTypeSystem sts;
            Vector xmlObjectsVector = new Vector();
            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();

            for (int i = 0; i < typesArray.size(); i++) {
                extensiblityElt = (WSDLExtensibilityElement) typesArray.get(i);
                Schema schema;

                if (ExtensionConstants.SCHEMA.equals(extensiblityElt.getType())) {
                    schema = (Schema) extensiblityElt;
                    XmlOptions options = new XmlOptions();

                    options.setLoadAdditionalNamespaces(
                            configuration.getWom().getNamespaces()); //add the namespaces


                    Stack importedSchemaStack = schema.getImportedSchemaStack();
                    File schemaFolder = null;
                    if(debug) {
                        schemaFolder = new File(configuration.getOutputLocation(), SCHEMA_FOLDER);
                        schemaFolder.mkdir();
                    }
                    //compile these schemas
                    while (!importedSchemaStack.isEmpty()) {
                        Element element = (Element) importedSchemaStack.pop();
                        String tagetNamespace = element.getAttribute("targetNamespace");
                        if (!processedSchemas.contains(tagetNamespace)) {

                            if(debug) {
                                // we are not using DOM toString method here, as it seems it depends on the
                                // JDK version that is being used.
                                String s = DOM2Writer.nodeToString(element);
   
                                //write the schema to a file
                                File tempFile = File.createTempFile("temp", ".xsd", schemaFolder);
                                FileWriter writer = new FileWriter(tempFile);
                                writer.write(s);
                                writer.flush();
                                writer.close();
                            }

                            xmlObjectsVector.add(
                                    XmlObject.Factory.parse(
                                            element
                                            , options));

                            processedSchemas.add(tagetNamespace);
                        }
                    }
                }
            }

            // add the third party schemas
            //todo perhaps checking the namespaces would be a good idea to
            //make the generated code work efficiently
            for (int i = 0; i < additionalSchemas.length; i++) {
                xmlObjectsVector.add(XmlObject.Factory.parse(
                        additionalSchemas[i]
                        , null));
            }

            //compile the type system
            XmlObject[] objeArray = convertToXMLObjectArray(xmlObjectsVector);
            BindingConfig config = new Axis2BindingConfig();

            //set the STS name to null. it makes the generated class include a unique (but random) STS name
            sts = XmlBeans.compileXmlBeans(null, null,
                    objeArray,
                    config, XmlBeans.getContextTypeLoader(),
                    new Axis2Filer(),
                    null);

            // prune the generated schema type system and add the list of base64 types
            FindBase64Types(sts);
            findPlainBase64Types(sts);

            //get the schematypes and add the document types to the type mapper
            SchemaType[] schemaType = sts.documentTypes();
            SchemaType type;
            for (int j = 0; j < schemaType.length; j++) {
                type = schemaType[j];
                mapper.addTypeMappingName(type.getDocumentElementName(),
                        type.getFullJavaName());
            }
            //set the type mapper to the config
            configuration.setTypeMapper(mapper);

            if(debug) {
                // write the mapper to a file for later retriival
                writeMappingsToFile(mapper.getAllMappedNames());
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here

            WSDLExtensibilityElement extensiblityElt;

            Vector xmlObjectsVector = new Vector();
            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();

            for (int i = 0; i < typesArray.size(); i++) {
                extensiblityElt = (WSDLExtensibilityElement) typesArray.get(i);
                Schema schema;

                if (ExtensionConstants.SCHEMA.equals(extensiblityElt.getType())) {
                    schema = (Schema) extensiblityElt;

//                    TODO: FIXME                   
//                    Map namespaceMap = configuration.getWom().getNamespaces();
//                    if (namespaceMap != null && !namespaceMap.isEmpty()) {
//                        Iterator nameSpaces = namespaceMap.keySet().iterator();
//                        String nsPrefix;
//                        String nsURI;
//                        while (nameSpaces.hasNext()) {
//                            nsPrefix = (String) nameSpaces.next();
//                            nsURI = namespaceMap.get(nsPrefix).toString();
//                            parser.addImport(nsURI, null);
//                        }
//                    }

                    Stack importedSchemaStack = schema.getImportedSchemaStack();
                    File schemaFolder = null;
                    if(debug) {
                        schemaFolder = new File(configuration.getOutputLocation(), SCHEMA_FOLDER);
                        schemaFolder.mkdir();
                    }
                    //compile these schemas
                    while (!importedSchemaStack.isEmpty()) {
                        Element element = (Element) importedSchemaStack.pop();
                        String tagetNamespace = element.getAttribute("targetNamespace");
                        if (!processedSchemas.contains(tagetNamespace)) {

                            String s = DOM2Writer.nodeToString(element);
                            xmlObjectsVector.add(new InputSource(new StringReader(s)));
                            processedSchemas.add(tagetNamespace);
                        }
                    }
                }
            }


//            TODO: FIXME           
//            Element[] additionalSchemas = loadAdditionalSchemas();
//            // Need to add the third party schemas
//            for (int i = 0; i < additionalSchemas.length; i++) {
//                String s = DOM2Writer.nodeToString(additionalSchemas[i]);
//                xmlObjectsVector.add(new InputSource(new StringReader(s)));
//            }

            File outputDir = new File(configuration.getOutputLocation(), "src");

            JAXBSchemaReader reader = new JAXBSchemaReader();
            reader.setSupportingExtensions(true);

            GeneratorImpl generator = new GeneratorImpl();
            generator.setTargetDirectory(outputDir);
            generator.setForcingOverwrite(false);
            generator.setSchemaReader(reader);

            for (int i = 0; i < xmlObjectsVector.size(); i++) {
                SchemaSG sg = generator.generate((InputSource) xmlObjectsVector.elementAt(i));
                ObjectSG[] elements = sg.getElements();
                for(int j=0;j<elements.length;j++){
                    XsQName qName = elements[j].getName();
                    JavaQName name = elements[j].getClassContext().getXMLInterfaceName();
                    mapper.addTypeMappingName(new QName(qName.getNamespaceURI(), qName.getLocalName()),
                                            name.getPackageName() + '.' + name.getClassName());
                }
                TypeSG[] types = sg.getTypes();
                for(int j=0;j<types.length;j++){
                    XsQName qName = types[j].getName();
                    JavaQName name = types[j].getRuntimeType();
                    mapper.addTypeMappingName(new QName(qName.getNamespaceURI(), qName.getLocalName()),
                                            name.getPackageName() + '.' + name.getClassName());
                }
                GroupSG[] groups = sg.getGroups();
                for(int j=0;j<groups.length;j++){
                    XsQName qName = groups[j].getName();
                    JavaQName name = groups[j].getClassContext().getXMLInterfaceName();
                    mapper.addTypeMappingName(new QName(qName.getNamespaceURI(), qName.getLocalName()),
                                            name.getPackageName() + '.' + name.getClassName());
                }
            }

//            TODO: FIXME                   
//            // prune the generated schema type system and add the list of base64 types
//            FindBase64Types(sts);
//
//            //get the schematypes and add the document types to the type mapper
//            SchemaType[] schemaType = sts.documentTypes();
//            SchemaType type;
//            for (int j = 0; j < schemaType.length; j++) {
//                type = schemaType[j];
//                mapper.addTypeMappingName(type.getDocumentElementName(),
//                        type.getFullJavaName());
//            }

            //set the type mapper to the config
            configuration.setTypeMapper(mapper);

            if(debug) {
                // write the mapper to a file for later retriival
                writeMappingsToFile(mapper.getAllMappedNames());
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here

            WSDLExtensibilityElement extensiblityElt;
            SchemaTypeSystem sts;
            Vector xmlObjectsVector = new Vector();
            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();

            for (int i = 0; i < typesArray.size(); i++) {
                extensiblityElt = (WSDLExtensibilityElement) typesArray.get(i);
                Schema schema;

                if (ExtensionConstants.SCHEMA.equals(extensiblityElt.getType())) {
                    schema = (Schema) extensiblityElt;
                    XmlOptions options = new XmlOptions();

                    options.setLoadAdditionalNamespaces(
                            configuration.getWom().getNamespaces()); //add the namespaces


                    Stack importedSchemaStack = schema.getImportedSchemaStack();
                    File schemaFolder = null;
                    if(debug) {
                        schemaFolder = new File(configuration.getOutputLocation(), SCHEMA_FOLDER);
                        schemaFolder.mkdir();
                    }
                    //compile these schemas
                    while (!importedSchemaStack.isEmpty()) {
                        Element element = (Element) importedSchemaStack.pop();
                        String tagetNamespace = element.getAttribute("targetNamespace");
                        if (!processedSchemas.contains(tagetNamespace)) {

                            if(debug) {
                                // we are not using DOM toString method here, as it seems it depends on the
                                // JDK version that is being used.
                                String s = DOM2Writer.nodeToString(element);
   
                                //write the schema to a file
                                File tempFile = File.createTempFile("temp", ".xsd", schemaFolder);
                                FileWriter writer = new FileWriter(tempFile);
                                writer.write(s);
                                writer.flush();
                                writer.close();
                            }

                            xmlObjectsVector.add(
                                    XmlObject.Factory.parse(
                                            element
                                            , options));

                            processedSchemas.add(tagetNamespace);
                        }
                    }
                }
            }

            // add the third party schemas
            //todo perhaps checking the namespaces would be a good idea to
            //make the generated code work efficiently
            for (int i = 0; i < additionalSchemas.length; i++) {
                xmlObjectsVector.add(XmlObject.Factory.parse(
                        additionalSchemas[i]
                        , null));
            }

            //compile the type system
            XmlObject[] objeArray = convertToXMLObjectArray(xmlObjectsVector);
            BindingConfig config = new Axis2BindingConfig();

            //set the STS name to null. it makes the generated class include a unique (but random) STS name
            sts = XmlBeans.compileXmlBeans(null, null,
                    objeArray,
                    config, XmlBeans.getContextTypeLoader(),
                    new Axis2Filer(),
                    null);

            // prune the generated schema type system and add the list of base64 types
            FindBase64Types(sts);

            //get the schematypes and add the document types to the type mapper
            SchemaType[] schemaType = sts.documentTypes();
            SchemaType type;
            for (int j = 0; j < schemaType.length; j++) {
                type = schemaType[j];
                mapper.addTypeMappingName(type.getDocumentElementName(),
                        type.getFullJavaName());
            }
            //set the type mapper to the config
            configuration.setTypeMapper(mapper);

            if(debug) {
                // write the mapper to a file for later retriival
                writeMappingsToFile(mapper.getAllMappedNames());
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here

            SchemaCompiler schemaCompiler = new SchemaCompiler(options);
            schemaCompiler
                    .compile(xmlSchemaTypeVector);

            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();

            if (options.isWriteOutput()){
                //get the processed element map and transfer it to the type mapper
                Map processedMap = schemaCompiler.getProcessedElementMap();
                Iterator processedkeys = processedMap.keySet().iterator();
                QName qNameKey;
                while (processedkeys.hasNext()) {
                    qNameKey = (QName) processedkeys.next();
                    mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
                }

            }else{
                //get the processed model map and transfer it to the type mapper
                //since the options mentiond that its not writable, it should have
                //populated the model map
                Map processedModelMap = schemaCompiler.getProcessedModelMap();
                Iterator processedkeys = processedModelMap.keySet().iterator();
                QName qNameKey;
                while (processedkeys.hasNext()) {
                    qNameKey = (QName) processedkeys.next();
                    mapper.addTypeMappingObject(qNameKey, processedModelMap.get(qNameKey));
                }

                Map processedMap = schemaCompiler.getProcessedElementMap();
                processedkeys = processedMap.keySet().iterator();
                while (processedkeys.hasNext()) {
                    qNameKey = (QName) processedkeys.next();
                    mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
                }

                //get the ADB template from the schema compilers property bag and set the
                //template
                configuration.putProperty(XSLTConstants.EXTERNAL_TEMPLATE_PROPERTY_KEY,
View Full Code Here

                            return new FileWriter(file);
                        }
                    }, null);

            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();
            SchemaType[] types= sts.documentTypes();

            for (int i= 0; i < types.length; i++){
                //System.out.println("type name = " + types[i].getFullJavaImplName()+" "+types[i].getDocumentElementName());
                mapper.addTypeMapping(types[i].getDocumentElementName(), types[i].getFullJavaName());
            }
            //set the type mapper to the config
            configuration.setTypeMapper(mapper);

        } catch (XmlException e) {
View Full Code Here

            SchemaTypeSystem sts;
            List completeSchemaList = new ArrayList();
            List topLevelSchemaList = new ArrayList();

            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();
            Map nameSpacesMap = cgconfig.getAxisService().getNameSpacesMap();

            // process all the schemas and make a list of all of them for
            // resolving entities
            for (int i = 0; i < schemas.size(); i++) {
                XmlSchema schema = (XmlSchema) schemas.get(i);
                XmlOptions options = new XmlOptions();
                options.setLoadAdditionalNamespaces(
                        nameSpacesMap); //add the namespaces
                Document[] allSchemas = schema.getAllSchemas();
                for (int j = 0; j < allSchemas.length; j++) {
                    Document allSchema = allSchemas[j];
                    completeSchemaList.add(
                            XmlObject.Factory.parse(
                                    allSchema
                                    , options));

                }
            }

            //make another list of top level schemas for passing into XMLbeans
            for (int i = 0; i < schemas.size(); i++) {
                XmlSchema schema = (XmlSchema) schemas.get(i);
                XmlOptions options = new XmlOptions();
                options.setLoadAdditionalNamespaces(
                        nameSpacesMap); //add the namespaces
                topLevelSchemaList.add(
                        XmlObject.Factory.parse(
                                getSchemaAsString(schema)
                                , options));

            }

            // add the third party schemas
            //todo perhaps checking the namespaces would be a good idea to
            //make the generated code work efficiently
            for (int i = 0; i < additionalSchemas.length; i++) {
                completeSchemaList.add(XmlObject.Factory.parse(
                        additionalSchemas[i]
                        , null));
                topLevelSchemaList.add(XmlObject.Factory.parse(
                        additionalSchemas[i]
                        , null));
            }

            //compile the type system
            Axis2EntityResolver er = new Axis2EntityResolver();
            er.setSchemas(convertToSchemaDocumentArray(completeSchemaList));
            er.setBaseUri(cgconfig.getBaseURI());


            sts = XmlBeans.compileXmlBeans(
                    //set the STS name to null. it makes the generated class
                    // include a unique (but random) STS name
                    null,
                    null,
                    convertToSchemaArray(topLevelSchemaList),
                    new Axis2BindingConfig(cgconfig.getUri2PackageNameMap()),
                    XmlBeans.getContextTypeLoader(),
                    new Axis2Filer(cgconfig.getOutputLocation()),
                    new XmlOptions().setEntityResolver(er));

            // prune the generated schema type system and add the list of base64 types
            cgconfig.putProperty(XSLTConstants.BASE_64_PROPERTY_KEY,
                    findBase64Types(sts));
            cgconfig.putProperty(XSLTConstants.PLAIN_BASE_64_PROPERTY_KEY,
                    findPlainBase64Types(sts));

            //get the schematypes and add the document types to the type mapper
            SchemaType[] schemaType = sts.documentTypes();
            SchemaType type;
            for (int j = 0; j < schemaType.length; j++) {
                type = schemaType[j];
                mapper.addTypeMappingName(type.getDocumentElementName(),
                        type.getFullJavaName());
            }

            //return mapper to be set in the config
            return mapper;
View Full Code Here

TOP

Related Classes of org.apache.axis2.wsdl.databinding.JavaTypeMapper

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.