Package commonj.sdo.helper

Examples of commonj.sdo.helper.XSDHelper


    public void testGenerateSchema() throws IOException {
        HelperContext context = SDOUtil.createHelperContext();
        URL url = getClass().getResource("/ipo.xsd");
        Assert.assertNotNull(url);
        InputStream is = url.openStream();
        XSDHelper xsdHelper = context.getXSDHelper();
        xsdHelper.define(is, url.toExternalForm());
        TypeHelper typeHelper = context.getTypeHelper();
        Type type = typeHelper.getType("http://www.example.com/IPO", "PurchaseOrderType");
        Assert.assertNotNull(type);
        /*
        SDOContextHelper.generateSchema(context, Arrays.asList(type));
View Full Code Here


                  String wsdlURL = artifact.getLocation();
                    URLConnection connection = new URL(wsdlURL).openConnection();
                    connection.setUseCaches(false);
                    InputStream xsdInputStream = connection.getInputStream();
                    try {
                        XSDHelper xsdHelper = importSDO.getHelperContext().getXSDHelper();
                        xsdHelper.define(xsdInputStream, wsdlURL);
                    } finally {
                        xsdInputStream.close();
                    }
                    importSDO.setUnresolved(false);
                } else {
View Full Code Here

        List children = handler.getChildren(document, op, true);
        assertEquals(5, children.size());
    }

    public void testWrapper() throws Exception {
        XSDHelper xsdHelper = context.getXSDHelper();
        xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null);
        XMLHelper xmlHelper = context.getXMLHelper();
        XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml"));
        Operation op = new OperationImpl();
        List children = handler.getChildren(document, op, true);
        assertEquals(5, children.size());
View Full Code Here

        assertEquals(5, children.size());
    }
   
    public void testCreate() {
        HelperContext context = HelperProvider.getDefaultContext();
        XSDHelper xsdHelper = context.getXSDHelper();
        xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null);
        ElementInfo element = new ElementInfo(new QName("http://www.example.com/wrapper", "op"), null);
        Operation op = new OperationImpl();
        WrapperInfo wrapperInfo = new WrapperInfo(SDODataBinding.NAME, element, null, null, null);
        op.setWrapper(wrapperInfo);
        DataObject wrapper = (DataObject) handler.create(op, true);
View Full Code Here

          Class typeInterfaceClass = classLoader.loadClass(typeInterface);
          // TODO: introspect and register the type
        }
      }

      XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper);
      for (Iterator iter = getXsdMetaData().iterator(); iter.hasNext();)
      {
        XSDMetaData metadata = (XSDMetaData)iter.next();
        URL url = getClass().getResource(metadata.getLocation());
        InputStream inputStream = url.openStream();
        xsdHelper.define(inputStream, url.toString());
      }

      XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper);
      for (Iterator iter = getTypeMetaData().iterator(); iter.hasNext();)
      {
View Full Code Here

        ClassLoader cl=Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(resourceLoader.getClassLoader());
           
            // Create an XSD helper
            XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper);
           
            ClassWriter cw = new ClassWriter(false);

            // Generate the interface
            interfaceName = interfaceName.replace('.', '/');
            cw.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, interfaceName, null, "java/lang/Object", EMPTY_STRINGS);

            // Generate methods from the WSDL operations
            for (Operation operation : (List<Operation>) portType.getOperations()) {
               
                //FIXME Workaround for TUSCANY-170, we will need to make this consistent with the algorithm used by Axis2 WSDL2Java
                // to generate method names from operations names
                //String methodName = XMLNameUtil.getJavaNameFromXMLName(operation.getName(), false);
                String methodName = operation.getName();
               
                // FIXME later we may want to wwitch to use the Axis2 WSDL2Java (not to generate the Java source,
                // just to figure the WSDL to Java mapping)
               
                // Derive the method signature from the input message part (and check if it's a doc-wrapped or doc-bare operation)
                List<Class> inputTypes=new ArrayList<Class>();
                boolean wrapped = false;
                if (operation.getInput() != null && operation.getInput().getMessage()!=null && !operation.getInput().getMessage().getParts().isEmpty()) {
                    QName qname=((Part)operation.getInput().getMessage().getParts().values().iterator().next()).getElementName();
                    if (qname!=null) {
                        Property property = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true);
                        commonj.sdo.Type type = property.getType();
                        if (property.getName().equals(operation.getName())) {
                            String localName = xsdHelper.getLocalName(type);
                            if (localName.indexOf("_._")!=-1) {
                                for (Property param : (List<Property>)type.getProperties()) {
                                    Class inputType = param.getType().getInstanceClass();
                                    if (inputType == null)
                                        inputType = Object.class;
                                    inputTypes.add(inputType);
                                }
                                wrapped=true;
                            }
                        }

                        // Bare doc style
                        if (!wrapped) {
                            Class inputType = type.getInstanceClass();
                            if (inputType == null)
                                inputType = Object.class;
                            inputTypes.add(inputType);
                        }
                       
                    } else {
                        // FIXME only support elements for now
                    }
                }
               
                // Derive the return type from the output message part (also support doc-wrapped and doc-bare here)
                Class outputType=Void.class;
                if (operation.getOutput() != null && operation.getOutput().getMessage()!=null && !operation.getOutput().getMessage().getParts().isEmpty()) {
                    QName qname=((Part)operation.getOutput().getMessage().getParts().values().iterator().next()).getElementName();
                    if (qname!=null) {
                        Property property = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true);
                        commonj.sdo.Type type = property.getType();
                        if (wrapped) {
                            if (!type.getProperties().isEmpty()) {
                                outputType=((Property)type.getProperties().get(0)).getType().getInstanceClass();
                                if (outputType==null)
View Full Code Here

    public static DataObject toWrappedDataObject(TypeHelper typeHelper,
                                                 Object ret,
                                                 Object[] os,
                                                 QName typeQN) {
        XSDHelper xsdHelper = new XSDHelperImpl(typeHelper);
        Property property = xsdHelper.getGlobalProperty(typeQN.getNamespaceURI(),
                typeQN.getLocalPart(), true);
        DataObject dataObject = new DataFactoryImpl(typeHelper).create(property.getType());
        List ips = dataObject.getInstanceProperties();
        int offset = 0;
        if (ret != null) {
View Full Code Here

        // Initialize the SDO runtime
        DataObjectUtil.initRuntime();
        EPackage.Registry packageRegistry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
        ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(packageRegistry);
        XSDHelper xsdHelper = new XSDHelperImpl(extendedMetaData);

        try {
           
            // Load the WSDL file
            File inputFile = new File(wsdlFileName).getAbsoluteFile();
            InputStream inputStream = new FileInputStream(inputFile);
           
            // Define SDO metadata
            xsdHelper.define(inputStream, inputFile.toURI().toString());

            if (targetDirectory == null) {
                targetDirectory = new File(wsdlFileName).getCanonicalFile().getParent();
            } else {
                targetDirectory = new File(targetDirectory).getCanonicalPath();
View Full Code Here

  public static void generateFromXMLSchema(String xsdFileName, String targetDirectory, String javaPackage, String prefix, int genOptions)
  {
    DataObjectUtil.initRuntime();
    EPackage.Registry packageRegistry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
    ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(packageRegistry);
    XSDHelper xsdHelper = new XSDHelperImpl(extendedMetaData);

    try
    {
      File inputFile = new File(xsdFileName).getAbsoluteFile();
      InputStream inputStream = new FileInputStream(inputFile);
      xsdHelper.define(inputStream, inputFile.toURI().toString());

      if (targetDirectory == null)
      {
        targetDirectory = new File(xsdFileName).getCanonicalFile().getParent();
      }
View Full Code Here

public class XSDHelperTestCase extends TestCase {
    private static final String TEST_MODEL = "/simple.xsd";
    private URL modelURL;

    public void testDefineWithLocation() throws IOException {
        XSDHelper xsdHelper = SDOUtil.createXSDHelper(SDOUtil.createTypeHelper());
        List types = xsdHelper.define(modelURL.openStream(), modelURL.toString());
        assertEquals(2, types.size());
    }
View Full Code Here

TOP

Related Classes of commonj.sdo.helper.XSDHelper

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.