Package org.eclipse.persistence.oxm

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


    /**
     * INTERNAL: Return the descriptor for the document.
     */
    protected XMLDescriptor getDescriptor(DOMRecord xmlRecord) throws XMLMarshalException {
        XMLContext xmlContext = xmlUnmarshaller.getXMLContext();
        QName rootQName = new QName(xmlRecord.getNamespaceURI(), xmlRecord.getLocalName());
        XMLDescriptor xmlDescriptor = xmlContext.getDescriptor(rootQName);
        if (null == xmlDescriptor) {
            // Try to find a descriptor based on the schema type
            String type = ((Element) xmlRecord.getDOM()).getAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL, "type");
            if (null != type) {
                XPathFragment typeFragment = new XPathFragment(type);
                String namespaceURI = xmlRecord.resolveNamespacePrefix(typeFragment.getPrefix());
                typeFragment.setNamespaceURI(namespaceURI);
                xmlDescriptor = xmlContext.getDescriptorByGlobalType(typeFragment);
            }
            if (null == xmlDescriptor) {
                throw XMLMarshalException.noDescriptorWithMatchingRootElement(rootQName.toString());
            }
        }


            xmlVersion = (String) PrivilegedAccessHelper.invokeMethod(getVersion, xmlRow.getDocument(), new Object[] {});
        } catch (Exception ex) {
            //if the methods aren't available, then just use the default values
        }

        XMLContext xmlContext = xmlUnmarshaller.getXMLContext();

        // handle 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
        if (XMLConversionManager.getDefaultJavaTypes().get(referenceClass) != null) {
            // we're assuming that since we're unmarshalling to a primitive
            // wrapper, the root element has a single text node
            Object nodeVal;
            try {
                Text rootTxt = (Text) xmlRow.getDOM().getFirstChild();
                nodeVal = rootTxt.getNodeValue();
            } catch (Exception ex) {
                // here, either the root element doesn't have a text node as a
                // first child, or there is no first child at all - in any case,
                // try converting null
                nodeVal = null;
            }
 
            Object obj = ((XMLConversionManager) xmlContext.getSession(0).getDatasourcePlatform().getConversionManager()).convertObject(nodeVal, referenceClass);
            XMLRoot xmlRoot = new XMLRoot();
            xmlRoot.setObject(obj);
            String lName = xmlRow.getDOM().getLocalName();
            if (lName == null) {
                lName = xmlRow.getDOM().getNodeName();
            }
            xmlRoot.setLocalName(lName);
            xmlRoot.setNamespaceURI(xmlRow.getDOM().getNamespaceURI());
            xmlRoot.setEncoding(xmlEncoding);
            xmlRoot.setVersion(xmlVersion);
            return xmlRoot;
        }

        // for XMLObjectReferenceMappings we need a non-shared cache, so
        // try and get a Unit Of Work from the XMLContext
        AbstractSession readSession = xmlContext.getReadSession(referenceClass);

        ReadObjectQuery query = new ReadObjectQuery();
        query.setReferenceClass(referenceClass);
        query.setSession(readSession);

        XMLDescriptor descriptor = (XMLDescriptor) readSession.getDescriptor(referenceClass);
        if (descriptor == null) {
            throw XMLMarshalException.descriptorNotFoundInProject(referenceClass.getName());
        }

        xmlRow.setUnmarshaller(xmlUnmarshaller);
        xmlRow.setDocPresPolicy(xmlContext.getDocumentPreservationPolicy(readSession));
        XMLObjectBuilder objectBuilder = (XMLObjectBuilder) descriptor.getObjectBuilder();
        Object object = objectBuilder.buildObject(query, xmlRow, null);

        // resolve mapping references
        xmlUnmarshaller.resolveReferences(readSession);

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

        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);

            // Mixed Content
            Object collection = unmarshalRecord.getContainerInstance(this);
            startElementProcessText(unmarshalRecord, collection);
            XMLDescriptor xmlDescriptor = null;

            XMLContext xmlContext = unmarshalRecord.getUnmarshaller().getXMLContext();

            if (xmlAnyCollectionMapping.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);
                // Check if descriptor is for a wrapper, if it is null it out and let continue
                if (xmlDescriptor != null && xmlDescriptor.isWrapper()) {
                  xmlDescriptor = null;
                }
            }

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

                    }
                    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())) {

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.