Examples of UnmarshalRecord


Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

        descriptor.getInheritancePolicy().setClassIndicatorField(isColl);
        descriptor.getInheritancePolicy().setClassExtractor(new ClassExtractor() {
            @Override
            public Class<?> extractClassFromRow(Record record, Session session) {
                Class<?> clz = Result.class;
                UnmarshalRecord uRecord = (UnmarshalRecord)record;
                Attributes attrs = uRecord.getAttributes();
                if (attrs != null) {
                    for (int i = 0, l = attrs.getLength(); i < l; i++) {
                        String attributeName = attrs.getQName(i);
                        if (attributeName.equals("isCollection")) {
                            String value = attrs.getValue(i);
View Full Code Here

Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

               RootLevelXmlAdapter adapter= null;
                 if(jaxbContext.getTypeMappingInfoToJavaTypeAdapters().size() >0){
                   adapter = jaxbContext.getTypeMappingInfoToJavaTypeAdapters().get(type);
                 }
             
                UnmarshalRecord unmarshalRecord = (UnmarshalRecord) xmlDescriptor.getObjectBuilder().createRecord((AbstractSession) xmlUnmarshaller.getXMLContext().getSession(0));
                XMLStreamReaderReader staxReader = new XMLStreamReaderReader(xmlUnmarshaller);
                unmarshalRecord.setUnmarshaller(xmlUnmarshaller);
                unmarshalRecord.setXMLReader(staxReader);
                staxReader.setContentHandler(unmarshalRecord);
                staxReader.parse(streamReader);
                Object value = null;
                if(unmarshalRecord.isNil()) {
                    value = null;
                } else {
                    value = unmarshalRecord.getCurrentObject();
                }
                if(value instanceof WrappedValue){
                  value = ((WrappedValue)value).getValue();
                }
               
                if(value instanceof ManyValue){
                  value = ((ManyValue)value).getItem();
                }
                if(adapter != null) {
                    try {
                        value = adapter.getXmlAdapter().unmarshal(value);
                    } catch(Exception ex) {
                        throw new JAXBException(XMLMarshalException.marshalException(ex));
                    }
                }
                Class declaredClass = null;
                if(type.getType() instanceof Class){
                    declaredClass = (Class)type.getType();
                }else{
                    declaredClass = Object.class;
                }
                return new JAXBElement(new QName(unmarshalRecord.getRootElementNamespaceUri(), unmarshalRecord.getLocalName()), declaredClass, value);
            }
            if(jaxbContext.getTypeMappingInfoToGeneratedType() == null) {
                return unmarshal(streamReader, type.getType());
            }
            RootLevelXmlAdapter adapter= null;
View Full Code Here

Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

        }
        return true;
    }

    public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) {
        UnmarshalRecord childRecord = unmarshalRecord.getChildRecord();
        if (null != childRecord) {
            Object childObject = childRecord.getCurrentObject();
            // OBJECT VALUE
            if (xmlAnyObjectMapping.usesXMLRoot()) {
                XMLDescriptor workingDescriptor = childRecord.getDescriptor();
                if (workingDescriptor != null) {
                    String prefix = xPathFragment.getPrefix();
                    if ((prefix == null) && (xPathFragment.getNamespaceURI() != null)) {
                        prefix = unmarshalRecord.resolveNamespaceUri(xPathFragment.getNamespaceURI());
                    }
View Full Code Here

Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

                    throw DescriptorException.missingClassIndicatorField(unmarshalRecord, xmlDescriptor.getInheritancePolicy().getDescriptor());
                }
            }
        }
        TreeObjectBuilder targetObjectBuilder = (TreeObjectBuilder)xmlDescriptor.getObjectBuilder();
        UnmarshalRecord childRecord = unmarshalRecord.getChildUnmarshalRecord(targetObjectBuilder);
        childRecord.setAttributes(atts);
        childRecord.startDocument();
        childRecord.initializeRecord(null);
        childRecord.startElement(xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), xPathFragment.getShortName(), atts);

        XMLReader xmlReader = unmarshalRecord.getXMLReader();
        xmlReader.setContentHandler(childRecord);
        xmlReader.setLexicalHandler(childRecord);
    }
View Full Code Here

Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

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

            UnmarshalRecord unmarshalRecord;
            if (isPrimitiveType) {
                unmarshalRecord = new XMLRootRecord(primitiveWrapperClass);
                unmarshalRecord.setSession((AbstractSession) unmarshaller.getXMLContext().getSession(0));
                unmarshalRecord.setXMLReader(this.getXMLReader());
            } else if (xmlDescriptor.hasInheritance()) {
                unmarshalRecord = new UnmarshalRecord(null);
                unmarshalRecord.setUnmarshaller(unmarshaller);
                unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
                unmarshalRecord.setXMLReader(this.getXMLReader());
                unmarshalRecord.setAttributes(atts);
               
                Class classValue = xmlDescriptor.getInheritancePolicy().classFromRow(unmarshalRecord, session);
               
                if (classValue == null) {
                    // no xsi:type attribute - look for type indicator on the default root element
                    QName leafElementType = xmlDescriptor.getDefaultRootElementType();

                    // if we have a user-set type, try to get the class from the inheritance policy
                    if (leafElementType != null) {
                        Object indicator = xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementType);
                        if(indicator != null) {
                            classValue = (Class)indicator;
                        }
                    }
                }
                if (classValue != null) {
                    xmlDescriptor = (XMLDescriptor)session.getDescriptor(classValue);
                } else {
                    // since there is no xsi:type attribute, we'll use the descriptor
                    // that was retrieved based on the rootQName -  we need to make
                    // sure it is non-abstract
                    if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
                        // need to throw an exception here
                        throw DescriptorException.missingClassIndicatorField(unmarshalRecord, xmlDescriptor.getInheritancePolicy().getDescriptor());
                    }
                }
                unmarshalRecord = (UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord(session);
            } else {
                unmarshalRecord = (UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord(session);
                unmarshalRecord.setXMLReader(this.getXMLReader());
            }
            this.descriptor = xmlDescriptor;
            this.rootRecord = unmarshalRecord;
           
            unmarshalRecord.setUnmarshaller(this.unmarshaller);
            unmarshalRecord.setXMLReader(this.getXMLReader());

            if (locator != null) {
                unmarshalRecord.setDocumentLocator(xmlReader.getLocator());
            }
            unmarshalRecord.setAttributes(atts);
           
            boolean hasNilAttribute = (atts != null && null != atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_NIL_ATTRIBUTE));                      
            unmarshalRecord.setNil(isNil || hasNilAttribute);
         
            unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
           
            unmarshalRecord.startDocument();
            unmarshalRecord.initializeRecord(null);
            xmlReader.setContentHandler(unmarshalRecord);
            xmlReader.setLexicalHandler(unmarshalRecord);
            unmarshalRecord.startElement(namespaceURI, localName, qName, atts);

            // if we located the descriptor via xsi:type attribute, create and
            // return an XMLRoot object
        } catch (EclipseLinkException e) {
            if (null == xmlReader.getErrorHandler()) {
View Full Code Here

Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

                if(getContentHandler() instanceof SAXUnmarshallerHandler) {
                    SAXUnmarshallerHandler saxUnmarshallerHandler = (SAXUnmarshallerHandler) contentHandler;
                    list.add(saxUnmarshallerHandler.getObject());
                    saxUnmarshallerHandler.setObject(null);
                } else if(getContentHandler() instanceof UnmarshalRecord) {
                    UnmarshalRecord unmarshalRecord = (UnmarshalRecord) contentHandler;
                    Object unmarshalledObject = unmarshalRecord.getCurrentObject();
                    if(includeRoot && unmarshalClass != null){
                        if(!(unmarshalledObject instanceof XMLRoot)) {
                            XMLRoot xmlRoot = new XMLRoot();
                            xmlRoot.setNamespaceURI(unmarshalRecord.getRootElementNamespaceUri());
                            xmlRoot.setLocalName(unmarshalRecord.getLocalName());
                            xmlRoot.setObject(unmarshalledObject);
                            unmarshalledObject = xmlRoot;
                        }
                    }
                    list.add(unmarshalledObject);
                    unmarshalRecord.setCurrentObject(null);
                    unmarshalRecord.setRootElementName(null);
                unmarshalRecord.setLocalName(null);
                }
            }
            if(getContentHandler() instanceof SAXUnmarshallerHandler) {
                ((SAXUnmarshallerHandler) getContentHandler()).setObject(list);
            } else if(getContentHandler() instanceof UnmarshalRecord) {
View Full Code Here

Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

                            
          boolean isTextValue = isTextValue(parentLocalName);          
            int size = tree.getChildCount();
            if(size == 0){      
              if(contentHandler instanceof UnmarshalRecord){
                UnmarshalRecord ur = (UnmarshalRecord)contentHandler;                 
                    XPathNode node = ur.getNonAttributeXPathNode(uri, parentLocalName, parentLocalName, null);
                    if(node != null){
                      NodeValue nv = node.getNodeValue();
                      if(nv == null && node.getTextNode() != null){
                        nv = node.getTextNode().getUnmarshalNodeValue();
                      }
                      if(nv != null && nv.isContainerValue()){
                        ur.getContainerInstance(((ContainerValue)nv));
                      }
                    }
              }
            }
            startCollection();
           
            if(size == 1){
        CommonTree ct = (CommonTree) tree.getChild(0);
        if(ct != null && ct.getType() == JSONLexer.NULL){
          contentHandler.setNil(true);
        }
        if(!isTextValue){
                  contentHandler.startElement(uri, parentLocalName, parentLocalName, attributes.setTree(ct, attributePrefix, namespaces, namespaceSeparator, namespaceAware));
                  }
                   parse(ct);
                   if(!isTextValue){
                      contentHandler.endElement(uri, parentLocalName, parentLocalName);
                   }
      }else{
           
      XPathFragment groupingXPathFragment = null;
      XPathFragment itemXPathFragment = null;
            if(contentHandler instanceof UnmarshalRecord) {
                UnmarshalRecord unmarshalRecord = (UnmarshalRecord) contentHandler;
                if(unmarshalRecord.getUnmarshaller().isWrapperAsCollectionName()) {
                    XPathNode unmarshalRecordXPathNode = unmarshalRecord.getXPathNode();
                    if(null != unmarshalRecordXPathNode) {
                        XPathFragment currentFragment = new XPathFragment();
                        currentFragment.setLocalName(parentLocalName);
                        currentFragment.setNamespaceURI(uri);
                        currentFragment.setNamespaceAware(namespaceAware);
View Full Code Here

Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

     * Create a new row/record for the object builder.
     * This allows subclasses to define different record types.
     */
    public AbstractRecord createRecord(AbstractSession session) {
        lazyInitialize();
        UnmarshalRecord uRec = new UnmarshalRecord(this);
        uRec.setSession(session);
        return uRec;
    }
View Full Code Here

Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

    private void giveToOXToProcess(String namespaceURI, String localName, String qName, Attributes atts, XMLDescriptor xmlDescriptor) throws SAXException {
        AbstractSession session = ((SDOXMLHelper)aHelperContext.getXMLHelper()).getXmlContext().getReadSession(xmlDescriptor);

        //taken from SAXUnmarshallerHandler start Element
        UnmarshalRecord unmarshalRecord;
        if (xmlDescriptor.hasInheritance()) {
            unmarshalRecord = new UnmarshalRecord((TreeObjectBuilder)xmlDescriptor.getObjectBuilder());
            unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
            unmarshalRecord.setAttributes(atts);
            if(parentRecord != null){
                unmarshalRecord.setXMLReader(parentRecord.getXMLReader());
            }
            Class classValue = xmlDescriptor.getInheritancePolicy().classFromRow(unmarshalRecord, session);
            if (classValue == null) {
                // no xsi:type attribute - look for type indicator on the default root element
                QName leafElementType = xmlDescriptor.getDefaultRootElementType();

                // if we have a user-set type, try to get the class from the inheritance policy
                if (leafElementType != null) {
                    Object indicator = xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementType);
                    if(indicator != null) {
                        classValue = (Class)indicator;
                    }
                }
            }
            if (classValue != null) {
                xmlDescriptor = (XMLDescriptor)session.getDescriptor(classValue);
            } else {
                // since there is no xsi:type attribute, we'll use the descriptor
                // that was retrieved based on the rootQName -  we need to make
                // sure it is non-abstract
                if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
                    // need to throw an exception here
                    throw DescriptorException.missingClassIndicatorField(unmarshalRecord, xmlDescriptor.getInheritancePolicy().getDescriptor());
                }
            }
        }

        unmarshalRecord = (UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord(session);
        unmarshalRecord.setParentRecord(parentRecord);
        unmarshalRecord.setUnmarshaller(parentRecord.getUnmarshaller());
        unmarshalRecord.setXMLReader(parentRecord.getXMLReader());
        unmarshalRecord.startDocument();
        unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
        unmarshalRecord.startElement(namespaceURI, localName, qName, atts);

        parentRecord.getXMLReader().setContentHandler(unmarshalRecord);

        try {
            unmarshalRecord.getXMLReader().setProperty("http://xml.org/sax/properties/lexical-handler", unmarshalRecord);
        } catch (SAXNotRecognizedException ex) {
        } catch (SAXNotSupportedException ex) {
            //if lexical handling is not supported by this parser, just ignore.
        }

        currentDataObjects.push(unmarshalRecord.getCurrentObject());
        depth++;
    }
View Full Code Here

Examples of org.eclipse.persistence.oxm.record.UnmarshalRecord

    public Object unmarshal(InputSource inputSource, Class clazz, XMLReader xmlReader) {
        if (inputSource != null && null == inputSource.getSystemId()) {
            inputSource.setSystemId(this.systemId);
        }
       
        UnmarshalRecord unmarshalRecord =null;
        XMLDescriptor xmlDescriptor = null;

        // for XMLObjectReferenceMappings we need a non-shared cache, so
        // try and get a Unit Of Work from the XMLContext
        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.
        boolean isPrimitiveWrapper = false;
        if(clazz == ClassConstants.OBJECT) {
          try{
                SAXUnmarshallerHandler saxUnmarshallerHandler = new SAXUnmarshallerHandler(xmlUnmarshaller.getXMLContext());
                saxUnmarshallerHandler.setXMLReader(xmlReader);
                saxUnmarshallerHandler.setUnmarshaller(xmlUnmarshaller);
                saxUnmarshallerHandler.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
                setContentHandler(xmlReader, saxUnmarshallerHandler);
                xmlReader.parse(inputSource);
           
                // resolve any mapping references
                saxUnmarshallerHandler.resolveReferences();
                return saxUnmarshallerHandler.getObject();
            } catch (IOException e) {
                throw XMLMarshalException.unmarshalException(e);
            } catch (SAXException e) {
                throw convertSAXException(e);
            }
        } else {
            // for XMLObjectReferenceMappings we need a non-shared cache, so
            // try and get a Unit Of Work from the XMLContext
          try{
            session = xmlUnmarshaller.getXMLContext().getReadSession(clazz);
            xmlDescriptor = (XMLDescriptor) session.getDescriptor(clazz);
            unmarshalRecord = (UnmarshalRecord) xmlDescriptor.getObjectBuilder().createRecord(session);

           
          }catch(XMLMarshalException xme){
            if(xme.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT){                  
                   isPrimitiveWrapper = isPrimitiveWrapper(clazz);
                   if (isPrimitiveWrapper) {
                          unmarshalRecord = new XMLRootRecord(clazz);
                          unmarshalRecord.setSession((AbstractSession) xmlUnmarshaller.getXMLContext().getSession(0));
                   }else{
                     throw xme;
                   }
                  
            }else{
               throw xme;
            }
              
          }          
        }

        try {
            unmarshalRecord.setXMLReader(xmlReader);
            unmarshalRecord.setUnmarshaller(xmlUnmarshaller);
            setContentHandler(xmlReader, unmarshalRecord);
            xmlReader.setLexicalHandler(unmarshalRecord);
            xmlReader.parse(inputSource);
        } catch (IOException e) {
            throw XMLMarshalException.unmarshalException(e);
        } catch (SAXException e) {
            throw convertSAXException(e);
        } finally {
          xmlUnmarshaller.getStringBuffer().reset();
        }

        // resolve mapping references
        unmarshalRecord.resolveReferences(session, xmlUnmarshaller.getIDResolver());

        if (isPrimitiveWrapper) {
            return unmarshalRecord.getCurrentObject();
        }
        return xmlDescriptor.wrapObjectInXMLRoot(unmarshalRecord, this.isResultAlwaysXMLRoot);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.