Package javolution.xml

Examples of javolution.xml.XMLObjectReader


        }

    }

    protected Object deserialize( final byte[] in ) {
        XMLObjectReader reader = null;
        try {
            final ByteArrayInputStream bis = new ByteArrayInputStream( in );
            reader = XMLObjectReader.newInstance( bis );
            final XMLReferenceResolver xmlReferenceResolver = new XMLReferenceResolver();
            xmlReferenceResolver.setIdentifierAttribute( JavolutionTranscoder.REFERENCE_ATTRIBUTE_ID );
            xmlReferenceResolver.setReferenceAttribute( JavolutionTranscoder.REFERENCE_ATTRIBUTE_REF_ID );
            reader.setReferenceResolver( xmlReferenceResolver );
            reader.setBinding( new ReflectionBinding( getClass().getClassLoader() ) );
            if ( !reader.hasNext() ) {
                throw new IllegalStateException( "reader has no input" );
            }
            return reader.read( "session" );
        } catch ( final RuntimeException e ) {
            throw e;
        } catch ( final javolution.xml.stream.XMLStreamException e ) {
            throw new RuntimeException( e );
        } finally {
            try {
                reader.close();
            } catch ( final XMLStreamException e ) {
                // fail silently
            }
        }
    }
View Full Code Here


        return doDeserialize( in, "attributes" );
    }

    private <T> T doDeserialize( final byte[] in, final String name ) {
        // getLogger().info( "Loading serialized:\n" + new String( in ) );
        XMLObjectReader reader = null;
        try {
            final ByteArrayInputStream bis = new ByteArrayInputStream( in );
            reader = XMLObjectReader.newInstance( bis );
            final XMLReferenceResolver xmlReferenceResolver = new XMLReferenceResolver();
            xmlReferenceResolver.setIdentifierAttribute( REFERENCE_ATTRIBUTE_ID );
            xmlReferenceResolver.setReferenceAttribute( REFERENCE_ATTRIBUTE_REF_ID );
            reader.setReferenceResolver( xmlReferenceResolver );
            reader.setBinding( _xmlBinding );
            if ( !reader.hasNext() ) {
                throw new IllegalStateException( "reader has no input" );
            }
            return reader.<T> read( name );
        } catch ( final RuntimeException e ) {
            LOG.warn( "Caught Exception decoding "+ in.length +" bytes of data", e );
            throw new TranscoderDeserializationException(e);
        } catch ( final XMLStreamException e ) {
            LOG.warn( "Caught Exception decoding "+ in.length +" bytes of data", e );
View Full Code Here

        }

    }

    protected <T> T deserialize( final byte[] in, final XMLBinding binding ) {
        XMLObjectReader reader = null;
        try {
            final ByteArrayInputStream bis = new ByteArrayInputStream( in );
            reader = XMLObjectReader.newInstance( bis );
            final XMLReferenceResolver xmlReferenceResolver = new XMLReferenceResolver();
            xmlReferenceResolver.setIdentifierAttribute( JavolutionTranscoder.REFERENCE_ATTRIBUTE_ID );
            xmlReferenceResolver.setReferenceAttribute( JavolutionTranscoder.REFERENCE_ATTRIBUTE_REF_ID );
            reader.setReferenceResolver( xmlReferenceResolver );
            reader.setBinding( binding );
            if ( !reader.hasNext() ) {
                throw new IllegalStateException( "reader has no input" );
            }
            return reader.<T> read( "root" );
        } catch ( final RuntimeException e ) {
            throw e;
        } catch ( final javolution.xml.stream.XMLStreamException e ) {
            throw new RuntimeException( e );
        } finally {
            try {
                reader.close();
            } catch ( final XMLStreamException e ) {
                // fail silently
            }
        }
    }
View Full Code Here

        }

    }

    protected <T> T deserialize( final byte[] in, final XMLBinding binding ) {
        XMLObjectReader reader = null;
        try {
            final ByteArrayInputStream bis = new ByteArrayInputStream( in );
            reader = XMLObjectReader.newInstance( bis );
            final XMLReferenceResolver xmlReferenceResolver = new XMLReferenceResolver();
            xmlReferenceResolver.setIdentifierAttribute( JavolutionTranscoder.REFERENCE_ATTRIBUTE_ID );
            xmlReferenceResolver.setReferenceAttribute( JavolutionTranscoder.REFERENCE_ATTRIBUTE_REF_ID );
            reader.setReferenceResolver( xmlReferenceResolver );
            reader.setBinding( binding );
            if ( !reader.hasNext() ) {
                throw new IllegalStateException( "reader has no input" );
            }
            return reader.<T> read( "root" );
        } catch ( final RuntimeException e ) {
            LOG.error( "Could not deserialize.", e );
            throw e;
        } catch ( final javolution.xml.stream.XMLStreamException e ) {
            LOG.error( "Could not deserialize.", e );
            throw new RuntimeException( e );
        } finally {
            try {
                reader.close();
            } catch ( final XMLStreamException e ) {
                // fail silently
            }
        }
    }
View Full Code Here

        binding.setClassAttribute(null);
    }

    protected JSSnapshot readSnapshot(String importFileName) throws SerializerException
    {
        XMLObjectReader reader = null;
        JSSnapshot snap = null;
        try
        {
          File exists = new File(importFileName);
          if (exists.exists())
            reader = XMLObjectReader.newInstance(new FileInputStream(importFileName));
          else
            reader = XMLObjectReader.newInstance(this.getClass().getClassLoader().getResourceAsStream(importFileName));
        }
        catch (Exception e)
        {
            throw new SerializerException(SerializerException.FILE_READER_ERROR.create(new String[] { importFileName,
                    e.getMessage() }));
        }
        try
        {
            if (this.binding != null)
                reader.setBinding(this.binding);
            snap = (JSSnapshot) reader.read(TAG_SNAPSHOT, JSSnapshot.class);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            new SerializerException(SerializerException.FILE_PROCESSING_ERROR.create(new String[] { importFileName,
                    e.getMessage() }));
        }
        finally
        {
            /** ensure the reader is closed */
            try
            {
                log.debug("*********closing up reader ********");
                reader.close();
            }
            catch (Exception e1)
            {
                log.debug("Error in closing reader " + e1.getMessage());
                /**
 
View Full Code Here

        binding.setClassAttribute(null);
    }

    protected JSSnapshot readSnapshot(String importFileName, String snapshotTagName) throws SerializerException
    {
        XMLObjectReader reader = null;
        JSSnapshot snap = null;
        try
        {
          File exists = new File(importFileName);
          if (exists.exists())
            reader = XMLObjectReader.newInstance(new FileInputStream(importFileName));
          else
            reader = XMLObjectReader.newInstance(this.getClass().getClassLoader().getResourceAsStream(importFileName));
        }
        catch (Exception e)
        {
            throw new SerializerException(SerializerException.FILE_READER_ERROR.create(new String[] { importFileName,
                    e.getMessage() }));
        }
        try
        {
            if (this.binding != null)
                reader.setBinding(this.binding);
            snap = (JSSnapshot) reader.read(snapshotTagName, JSSnapshot.class);
        }
        catch (Exception e)
        {
            new SerializerException(SerializerException.FILE_PROCESSING_ERROR.create(new String[] { importFileName,
                    e.getMessage() }));
        }
        finally
        {
            /** ensure the reader is closed */
            try
            {
                log.debug("*********closing up reader ********");
                reader.close();
            }
            catch (Exception e1)
            {
                log.debug("Error in closing reader " + e1.getMessage());
                /**
 
View Full Code Here

TOP

Related Classes of javolution.xml.XMLObjectReader

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.