Package org.eclipse.persistence.oxm

Examples of org.eclipse.persistence.oxm.XMLContext$XMLContextState


        return true;
    }

    public boolean startElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) {
        try {
            XMLContext xmlContext = unmarshalRecord.getUnmarshaller().getXMLContext();
            XMLDescriptor xmlDescriptor = null;
            if (xmlAnyObjectMapping.usesXMLRoot()) {
                String schemaType = atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
                XPathFragment frag = new XPathFragment();
                if ((null != schemaType) && (!schemaType.equals(""))) {
                    frag.setXPath(schemaType);

                    if (frag.hasNamespace()) {
                        String prefix = frag.getPrefix();
                        String url = unmarshalRecord.resolveNamespacePrefix(prefix);
                        frag.setNamespaceURI(url);

                        QName qname = new QName(url, frag.getLocalName());
                        unmarshalRecord.setTypeQName(qname);
                    }
                    xmlDescriptor = xmlContext.getDescriptorByGlobalType(frag);
                }
            }

            if (xmlDescriptor == null) {
                QName qname = new QName(xPathFragment.getNamespaceURI(), xPathFragment.getLocalName());
                xmlDescriptor = xmlContext.getDescriptor(qname);
            }
            workingDescriptor = xmlDescriptor;

            if (null == xmlDescriptor) {
                //need to give to special handler, let it find out what to do depending on if this is simple or complex content


        unmarshalRecord.getChildRecord().setXMLReader(unmarshalRecord.getXMLReader());
    }

    protected XMLDescriptor findReferenceDescriptor(UnmarshalRecord unmarshalRecord, Attributes atts, DatabaseMapping mapping) {
        XMLDescriptor returnDescriptor = null;
        XMLContext xmlContext = unmarshalRecord.getUnmarshaller().getXMLContext();

        //try xsi:type
        String schemaType = atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
        if ((schemaType != null) && (!schemaType.equals(""))) {
            XPathFragment frag = new XPathFragment();
            frag.setXPath(schemaType);

            if (frag.hasNamespace()) {
                String prefix = frag.getPrefix();
                String url = unmarshalRecord.resolveNamespacePrefix(prefix);
                frag.setNamespaceURI(url);
            }
            returnDescriptor = xmlContext.getDescriptorByGlobalType(frag);
        } else {
            //try leaf element type
            QName leafType = ((XMLField)mapping.getField()).getLastXPathFragment().getLeafElementType();
            if (leafType != null) {
                XPathFragment frag = new XPathFragment();
                String xpath = leafType.getLocalPart();
                String uri = leafType.getNamespaceURI();
                if ((uri != null) && !uri.equals("")) {
                    frag.setNamespaceURI(uri);
                    String prefix = ((XMLDescriptor)mapping.getDescriptor()).getNonNullNamespaceResolver().resolveNamespaceURI(uri);
                    if ((prefix != null) && !prefix.equals("")) {
                        xpath = prefix + ":" + xpath;
                    }
                }
                frag.setXPath(xpath);

                returnDescriptor = xmlContext.getDescriptorByGlobalType(frag);
            }
        }
        if (returnDescriptor == null) {
            throw XMLMarshalException.noDescriptorFound(mapping);
        }

     *
     */
    public void loadXMLSchema(InputStream xrSchemaStream) {

        SchemaModelProject schemaProject = new SchemaModelProject();
        XMLContext xmlContext = new XMLContext(schemaProject);
        XMLUnmarshaller unmarshaller = xmlContext.createUnmarshaller();
        Schema schema = (Schema)unmarshaller.unmarshal(xrSchemaStream);
        NamespaceResolver nr = schema.getNamespaceResolver();
        String targetNamespace = schema.getTargetNamespace();
        nr.put(TARGET_NAMESPACE_PREFIX, targetNamespace);
        xrService.schema = schema;

            throw DBWSException.couldNotLocateOXSessionForService(xrService.name);
        }
        ((XMLLogin)xrService.oxSession.getDatasourceLogin()).setEqualNamespaceResolvers(false);
        ProjectHelper.fixOROXAccessors(xrService.orSession.getProject(),
            xrService.oxSession.getProject());
        xrService.xmlContext = new XMLContext(xrService.oxSession.getProject());
        xrService.oxSession = xrService.xmlContext.getSession(0);
    }

        return unmarshal(inputSource, clazz);
    }

    public Object unmarshal(InputSource inputSource) {
        try {
            XMLContext xmlContext = xmlUnmarshaller.getXMLContext();
            if (xmlContext.hasDocumentPreservation()) {
                Node domElement = xmlParser.parse(inputSource).getDocumentElement();
                return unmarshal(domElement);
            }
            SAXUnmarshallerHandler saxUnmarshallerHandler = new SAXUnmarshallerHandler(xmlContext);
            saxUnmarshallerHandler.setXMLReader(xmlReader);

            throw convertSAXException(e);
        }
    }

    public Object unmarshal(InputSource inputSource, Class clazz) {
        XMLContext xmlContext = xmlUnmarshaller.getXMLContext();

        if (xmlContext.hasDocumentPreservation()) {
            Node domElement = xmlParser.parse(inputSource).getDocumentElement();
            return unmarshal(domElement, clazz);
        }
        boolean isPrimitiveWrapper = XMLConversionManager.getDefaultJavaTypes().get(clazz) != null;
        UnmarshalRecord unmarshalRecord;
        XMLDescriptor xmlDescriptor = null;

        AbstractSession session = null;

        // check for case where the reference class is a primitive wrapper - in this case, we
        // need to use the conversion manager to convert the node's value to the primitive
        // wrapper class, then create, populate and return an XMLRoot.  This will be done
        // via XMLRootRecord.
        if (isPrimitiveWrapper) {
            unmarshalRecord = new XMLRootRecord(clazz);
            unmarshalRecord.setSession((AbstractSession) xmlUnmarshaller.getXMLContext().getSession(0));
        } else {
            // for XMLObjectReferenceMappings we need a non-shared cache, so
            // try and get a Unit Of Work from the XMLContext
            session = xmlContext.getReadSession(clazz);
            xmlDescriptor = (XMLDescriptor) session.getDescriptor(clazz);
            unmarshalRecord = (UnmarshalRecord) xmlDescriptor.getObjectBuilder().createRecord(session);
        }
        try {
            unmarshalRecord.setXMLReader(xmlReader);

                    }
                    XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
                    XMLParser parser = xmlPlatform.newXMLParser();
                    parser.setNamespaceAware(true);
                    parser.setWhitespacePreserving(false);
                  XMLContext context = new XMLContext(p);
                  context.getSession(Project.class).getEventManager().addListener(
                    new MissingDescriptorListener());
                  XMLUnmarshaller unmarshaller = context.createUnmarshaller();
                  project = (Project)unmarshaller.unmarshal(url);
              }
            }
            catch (ValidationException validationException) {
                if (validationException.getErrorCode() == ValidationException.PROJECT_XML_NOT_FOUND) {

    public boolean load(SessionManager sessionManager, ClassLoader loader) {
        Document document = loadDocument(loader);

        if(getExceptionStore().isEmpty()){
            if (document.getDocumentElement().getTagName().equals("sessions")) {
                XMLContext context = new XMLContext(new XMLSessionConfigProject_11_1_1());
                XMLUnmarshaller unmarshaller = context.createUnmarshaller();
                SessionConfigs configs = (SessionConfigs)unmarshaller.unmarshal(document);
                XRSessionsFactory factory = new XRSessionsFactory();
                Map<String, Session> sessions = factory.buildSessionConfigs(configs, loader);
                for (Map.Entry<String, Session> entry : sessions.entrySet()) {
                    if (!sessionManager.getSessions().containsKey(entry.getKey())) {

        }
        if (xrServiceStream == null) {
            throw new WebServiceException(DBWSException.couldNotLocateFile(DBWS_SERVICE_XML));
        }
        DBWSModelProject xrServiceModelProject = new DBWSModelProject();
        XMLContext xmlContext = new XMLContext(xrServiceModelProject);
        XMLUnmarshaller unmarshaller = xmlContext.createUnmarshaller();
        XRServiceModel xrServiceModel;
        try {
            xrServiceModel = (XRServiceModel)unmarshaller.unmarshal(xrServiceStream);
        }
        catch (XMLMarshalException e) {
            // something went wrong parsing the eclipselink-dbws.xml - can't recover from that
            throw new WebServiceException(DBWSException.couldNotParseDBWSFile());
        }
        try {
            xrServiceStream.close();
        }
        catch (IOException ioe) {
            /* safe to ignore */
        }

        String path = WSDL_DIR + DBWS_SCHEMA_XML;
        if (sc != null) {
            path = "WEB-INF/" + path;
            xrSchemaStream = sc.getResourceAsStream(path);
        }
        else {
            // if ServletContext is null, then we are running in JavaSE6 'container-less' mode
            xrSchemaStream = parentClassLoader.getResourceAsStream(path);
        }
        if (xrSchemaStream == null) {
            throw new WebServiceException(DBWSException.couldNotLocateFile(DBWS_SCHEMA_XML));
        }
        try {
            buildService(xrServiceModel); // inherit xrService processing from XRServiceFactory
        }
        catch (Exception e) {
            // something went wrong building the service
            throw new WebServiceException(e);
        }

        // the xrService built by 'buildService' above is overridden to produce an
        // instance of DBWSAdapter (a sub-class of XRService)
        DBWSAdapter dbwsAdapter = (DBWSAdapter)xrService;

        // get inline schema from WSDL - has additional types for the operations
        StringWriter sw = new StringWriter();
        InputStream wsdlInputStream = null;
        path = WSDL_DIR + DBWS_WSDL;
        if (sc != null) {
            path = WEB_INF_DIR + path;
            wsdlInputStream = sc.getResourceAsStream(path);
        }
        else {
            // if ServletContext is null, then we are running in JavaSE6 'container-less' mode
            wsdlInputStream = parentClassLoader.getResourceAsStream(path);
        }
        if (wsdlInputStream == null) {
            throw new WebServiceException(DBWSException.couldNotLocateFile(DBWS_WSDL));
        }
        try {
            StreamSource wsdlStreamSource = new StreamSource(wsdlInputStream);
          Transformer t = TransformerFactory.newInstance().newTransformer(new StreamSource(
              new StringReader(MATCH_SCHEMA)));
          StreamResult streamResult = new StreamResult(sw);
          t.transform(wsdlStreamSource, streamResult);
          sw.toString();
          wsdlInputStream.close();
            SchemaModelProject schemaProject = new SchemaModelProject();
            XMLContext xmlContext2 = new XMLContext(schemaProject);
            unmarshaller = xmlContext2.createUnmarshaller();
            Schema extendedSchema = (Schema)unmarshaller.unmarshal(new StringReader(sw.toString()));
            dbwsAdapter.setExtendedSchema(extendedSchema);
        }
        catch (Exception e) {
          // that's Ok, WSDL may not contain inline schema

            throw new SOAPFaultException(soapFault);
        }

        XMLRoot xmlRoot = null;
        try {
            XMLContext xmlContext = dbwsAdapter.getXMLContext();
            xmlRoot = (XMLRoot)xmlContext.createUnmarshaller().unmarshal(body,
                Invocation.class);
        }
        catch (XMLMarshalException e) {
            SOAPFault soapFault = null;
            try {

TOP

Related Classes of org.eclipse.persistence.oxm.XMLContext$XMLContextState

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.