Package org.apache.axis2.wsdl.databinding

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


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

            //change the  default class name of the mapper to
            //xmlbeans specific XMLObject
            mapper.setDefaultMappingName(XmlObject.class.getName());
View Full Code Here


                    new BindingConfig(), XmlBeans.getContextTypeLoader(),
                    new Axis2Filer(),
                    null);

            //create the type mapper
            JavaTypeMapper mapper = new JavaTypeMapper();
            SchemaType[] schemaType = sts.documentTypes();
            SchemaType type;
            for (int i = 0; i < schemaType.length; i++) {
                type = schemaType[i];
                mapper.addTypeMapping(type.getDocumentElementName(),
                        type.getFullJavaName());
            }

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

                        xmlObjectsVector.add(thisSchema);
                    }
                }

                //create the type mapper
                JavaTypeMapper mapper = new JavaTypeMapper();
                int length = 0;
                for (int j = 0; j < length; j++) {
//                    mapper.addTypeMapping();
                }
                //set the type mapper to the config
View Full Code Here

            final Map schemaToInputSourceMap = new HashMap();
            final Map<String, StringBuffer> publicIDToStringMap = new HashMap<String, StringBuffer>();

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

            String baseURI = cgconfig.getBaseURI();
            if (!baseURI.endsWith("/")){
               baseURI = baseURI + "/";
            }


            for (int i = 0; i < schemas.size(); i++) {
                XmlSchema schema = (XmlSchema)schemas.get(i);
                InputSource inputSource =
                        new InputSource(new StringReader(getSchemaAsString(schema)));
                //here we have to set a proper system ID. otherwise when processing the
                // included schaemas for this schema we have a problem
                // it creates the system ID using this target namespace value

                inputSource.setSystemId(baseURI + "xsd" + i + ".xsd");
                inputSource.setPublicId(schema.getTargetNamespace());
                schemaToInputSourceMap.put(schema,inputSource);
            }

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

            Map nsMap = cgconfig.getUri2PackageNameMap();
            EntityResolver resolver = new EntityResolver() {
                public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
                    InputSource returnInputSource = null;
                    XmlSchema key = null;
                    for (Iterator iter = schemaToInputSourceMap.keySet().iterator();iter.hasNext();) {
                        key = (XmlSchema) iter.next();
                        String nsp = key.getTargetNamespace();
                        if (nsp != null && nsp.equals(publicId)) {

                            // when returning the input stream we have to always return a new
                            // input stream.
                            // sinc jaxbri internally consumes the input stream it gives an
                            // exception.
                            returnInputSource = new InputSource(new StringReader(getSchemaAsString(key)));
                            InputSource existingInputSource = (InputSource) schemaToInputSourceMap.get(key);
                            returnInputSource.setSystemId(existingInputSource.getSystemId());
                            returnInputSource.setPublicId(existingInputSource.getPublicId());
                            break;
                        }
                    }
                    if (returnInputSource == null){
                        // then we have to find this using the file system
                        if (systemId != null){
                            returnInputSource = new InputSource(systemId);
                            returnInputSource.setSystemId(systemId);
                        }
                    }

                    if (returnInputSource == null) {
                        if (publicId != null) {

                            if (!publicIDToStringMap.containsKey(publicId)) {
                                URL url = new URL(publicId);
                                BufferedReader bufferedReader =
                                        new BufferedReader(new InputStreamReader(url.openStream()));
                                StringBuffer stringBuffer = new StringBuffer();
                                String str = null;
                                while ((str = bufferedReader.readLine()) != null) {
                                    stringBuffer.append(str);
                                }
                                publicIDToStringMap.put(publicId, stringBuffer);
                            }

                            String schemaString = publicIDToStringMap.get(publicId).toString();
                            returnInputSource = new InputSource(new StringReader(schemaString));
                            returnInputSource.setPublicId(publicId);
                            returnInputSource.setSystemId(publicId);
                        }
                    }
                    return returnInputSource;
                }
            };


            Map properties = cgconfig.getProperties();
            String bindingFileName = (String) properties.get(BINDING_FILE_NAME);

            XmlSchema key = null;
            for (Iterator schemaIter = schemaToInputSourceMap.keySet().iterator();
                 schemaIter.hasNext();) {

                SchemaCompiler sc = XJC.createSchemaCompiler();
                if (bindingFileName != null){
                    if (bindingFileName.endsWith(".jar")) {
                        scanEpisodeFile(new File(bindingFileName), sc);
                    } else {
                        InputSource inputSoruce = new InputSource(new FileInputStream(bindingFileName));
                        inputSoruce.setSystemId(new File(bindingFileName).toURI().toString());
                        sc.getOptions().addBindFile(inputSoruce);
                    }

                }

                key = (XmlSchema) schemaIter.next();

                if (nsMap != null) {
                    Iterator iterator = nsMap.entrySet().iterator();
                    while(iterator.hasNext()){
                        Map.Entry entry = (Map.Entry) iterator.next();
                        String namespace = (String) entry.getKey();
                        String pkg = (String)nsMap.get(namespace);
                        registerNamespace(sc, namespace, pkg);
                    }
                }

                sc.setEntityResolver(resolver);

                sc.setErrorListener(new ErrorListener(){
                    public void error(SAXParseException saxParseException) {
                        log.error(saxParseException.getMessage());
                        log.debug(saxParseException.getMessage(), saxParseException);
                    }

                    public void fatalError(SAXParseException saxParseException) {
                        log.error(saxParseException.getMessage());
                        log.debug(saxParseException.getMessage(), saxParseException);
                    }

                    public void warning(SAXParseException saxParseException) {
                        log.warn(saxParseException.getMessage());
                        log.debug(saxParseException.getMessage(), saxParseException);
                    }

                    public void info(SAXParseException saxParseException) {
                        log.info(saxParseException.getMessage());
                        log.debug(saxParseException.getMessage(), saxParseException);
                    }
                });

                sc.parseSchema((InputSource) schemaToInputSourceMap.get(key));
                sc.getOptions().addGrammar((InputSource) schemaToInputSourceMap.get(key));

                for (Object property : properties.keySet()){
                    String propertyName = (String) property;
                    if (propertyName.startsWith("X")) {
                        String[] args = null;
                        String propertyValue = (String) properties.get(property);
                        if (propertyValue != null) {
                            args = new String[]{"-" + propertyName, propertyValue};
                        } else {
                            args = new String[]{"-" + propertyName};
                        }
                        sc.getOptions().parseArguments(args);
                    }
                }

                // Bind the XML
                S2JJAXBModel jaxbModel = sc.bind();

                if(jaxbModel == null){
                    throw new RuntimeException("Unable to generate code using jaxbri");
                }

                // Emit the code artifacts
                JCodeModel codeModel = jaxbModel.generateCode(null, null);
                FileCodeWriter writer = new FileCodeWriter(outputDir);
                codeModel.build(writer);

                Collection mappings = jaxbModel.getMappings();

                Iterator iter = mappings.iterator();

                while (iter.hasNext()) {
                    Mapping mapping = (Mapping)iter.next();
                    QName qn = mapping.getElement();
                    String typeName = mapping.getType().getTypeClass().fullName();

                    mapper.addTypeMappingName(qn, typeName);
                }

                //process the unwrapped parameters
                if (!cgconfig.isParametersWrapped()) {
                    //figure out the unwrapped operations
                    List axisServices = cgconfig.getAxisServices();
                    for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
                        AxisService axisService = (AxisService)servicesIter.next();
                        for (Iterator operations = axisService.getOperations();
                             operations.hasNext();) {
                            AxisOperation op = (AxisOperation)operations.next();

                            if (WSDLUtil.isInputPresentForMEP(op.getMessageExchangePattern())) {
                                AxisMessage message = op.getMessage(
                                        WSDLConstants.MESSAGE_LABEL_IN_VALUE);
                                if (message != null &&
                                        message.getParameter(Constants.UNWRAPPED_KEY) != null) {

                                    Mapping mapping = jaxbModel.get(message.getElementQName());
                                    List elementProperties = mapping.getWrapperStyleDrilldown();
                                    for(int j = 0; j < elementProperties.size(); j++){
                                        Property elementProperty = (Property) elementProperties.get(j);

                                        QName partQName =
                                                    WSDLUtil.getPartQName(op.getName().getLocalPart(),
                                                                          WSDLConstants.INPUT_PART_QNAME_SUFFIX,
                                                                          elementProperty.elementName().getLocalPart());
                                        //this type is based on a primitive type- use the
                                        //primitive type name in this case
                                        String fullJaveName =
                                                elementProperty.type().fullName();
                                        if (elementProperty.type().isArray()) {
                                            fullJaveName = fullJaveName.concat("[]");
                                        }
                                        mapper.addTypeMappingName(partQName, fullJaveName);

                                        if (elementProperty.type().isPrimitive()) {
                                            mapper.addTypeMappingStatus(partQName, Boolean.TRUE);
                                        }
                                        if (elementProperty.type().isArray()) {
                                            mapper.addTypeMappingStatus(partQName,
                                                                        Constants.ARRAY_TYPE);
                                        }
                                    }
                                }
                            }

                            if (WSDLUtil.isOutputPresentForMEP(op.getMessageExchangePattern())) {
                                AxisMessage message = op.getMessage(
                                        WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
                                if (message != null &&
                                        message.getParameter(Constants.UNWRAPPED_KEY) != null) {

                                    Mapping mapping = jaxbModel.get(message.getElementQName());
                                    List elementProperties = mapping.getWrapperStyleDrilldown();
                                    for(int j = 0; j < elementProperties.size(); j++){
                                        Property elementProperty = (Property) elementProperties.get(j);

                                        QName partQName =
                                                    WSDLUtil.getPartQName(op.getName().getLocalPart(),
                                                                          WSDLConstants.OUTPUT_PART_QNAME_SUFFIX,
                                                                          elementProperty.elementName().getLocalPart());
                                        //this type is based on a primitive type- use the
                                        //primitive type name in this case
                                        String fullJaveName =
                                                elementProperty.type().fullName();
                                        if (elementProperty.type().isArray()) {
                                            fullJaveName = fullJaveName.concat("[]");
                                        }
                                        mapper.addTypeMappingName(partQName, fullJaveName);

                                        if (elementProperty.type().isPrimitive()) {
                                            mapper.addTypeMappingStatus(partQName, Boolean.TRUE);
                                        }
                                        if (elementProperty.type().isArray()) {
                                            mapper.addTypeMappingStatus(partQName,
                                                                        Constants.ARRAY_TYPE);
                                        }
                                    }
                                }
                            }
View Full Code Here

            }


            Vector xmlObjectsVector = new Vector();
            //create the type mapper
            JavaTypeMapper 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))));
            }

//            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());
                }
            }

            //set the type mapper to the config
View Full Code Here

                accumulateElements(o, elements);
            }


            // build type mapping from JiBX mappings for elements
            JavaTypeMapper mapper = new JavaTypeMapper();
            for (Iterator iter = elements.iterator(); iter.hasNext();) {
                QName qname = (QName)iter.next();
                if (qname != null) {
                    String cname = (String)jibxmap.get(qname);
                    if (cname == null) {
                        throw new RuntimeException("No JiBX mapping defined for " + qname);
                    }
                    mapper.addTypeMappingName(qname, cname);
                }
            }

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

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

            //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

            }

            Vector xmlObjectsVector = new Vector();

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

            String baseURI = cgconfig.getBaseURI();

            for (int i = 0; i < schemas.size(); i++) {
                XmlSchema schema = (XmlSchema)schemas.get(i);
                InputSource inputSource =
                        new InputSource(new StringReader(getSchemaAsString(schema)));
                inputSource.setSystemId(baseURI);
                xmlObjectsVector.add(inputSource);
            }

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

            Map nsMap = cgconfig.getUri2PackageNameMap();

            for (int i = 0; i < xmlObjectsVector.size(); i++) {

                SchemaCompiler sc = XJC.createSchemaCompiler();
                XmlSchema schema = (XmlSchema)schemas.get(i);

                String pkg = null;
                if (nsMap != null) {
                    pkg = (String)nsMap.get(schema.getTargetNamespace());
                }
                if (pkg == null) {
                    pkg = extractNamespace(schema);
                }
                sc.setDefaultPackageName(pkg);

                sc.parseSchema((InputSource)xmlObjectsVector.elementAt(i));

                // Bind the XML
                S2JJAXBModel jaxbModel = sc.bind();

                // Emit the code artifacts
                JCodeModel codeModel = jaxbModel.generateCode(null, null);
                FileCodeWriter writer = new FileCodeWriter(outputDir);
                codeModel.build(writer);

                Collection mappings = jaxbModel.getMappings();

                Iterator iter = mappings.iterator();

                while (iter.hasNext()) {
                    Mapping mapping = (Mapping)iter.next();
                    QName qn = mapping.getElement();
                    String typeName = mapping.getType().getTypeClass().fullName();

                    mapper.addTypeMappingName(qn, typeName);
                }
            }

            // Return the type mapper
            return 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

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

            //change the  default class name of the mapper to
            //xmlbeans specific XMLObject
            mapper.setDefaultMappingName(XmlObject.class.getName());
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.