View Javadoc

1   /**********************************************************************
2    * JSXAdapter.java
3    * created on 07.07.2006 by netseeker
4    * $Source$
5    * $Date$
6    * $Revision$
7    *
8    * ====================================================================
9    *
10   *  Copyright 2006 netseeker aka Michael Manske
11   *
12   *  Licensed under the Apache License, Version 2.0 (the "License");
13   *  you may not use this file except in compliance with the License.
14   *  You may obtain a copy of the License at
15   *
16   *      http://www.apache.org/licenses/LICENSE-2.0
17   *
18   *  Unless required by applicable law or agreed to in writing, software
19   *  distributed under the License is distributed on an "AS IS" BASIS,
20   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   *  See the License for the specific language governing permissions and
22   *  limitations under the License.
23   * ====================================================================
24   *
25   * This file is part of the EJOE framework.
26   * For more information on the author, please see
27   * <http://www.manskes.de/>.
28   *
29   *********************************************************************/
30  
31  package de.netseeker.ejoe.adapter.commercial;
32  
33  import java.io.IOException;
34  import java.io.InputStream;
35  import java.io.ObjectInputStream;
36  import java.io.OutputStream;
37  
38  import de.netseeker.ejoe.adapter.BaseAdapter;
39  
40  /***
41   * Simple (de)serialize adapter using the JSX (Java Serialization to XML)
42   * 
43   * @see http://javaserializationtoxml.com
44   * @author netseeker
45   * @since 0.3.9.1
46   */
47  public class JSXAdapter extends BaseAdapter
48  {
49      private static final long serialVersionUID = 1L;
50  
51      /***
52       * 
53       */
54      public JSXAdapter()
55      {
56          super();
57      }
58  
59      /*
60       * (non-Javadoc)
61       * 
62       * @see de.netseeker.ejoe.adapter.SerializeAdapter#read(java.io.InputStream)
63       */
64      public Object read( InputStream in ) throws IOException
65      {
66          Object obj = null;
67          ObjectInputStream oin = new JSX.ObjectReader( in );
68  
69          try
70          {
71              obj = oin.readObject();
72          }
73          catch ( ClassNotFoundException e )
74          {
75              IOException ioe = new IOException( e.toString() );
76              ioe.setStackTrace( e.getStackTrace() );
77              throw ioe;
78          }
79  
80          return obj;
81      }
82  
83      /*
84       * (non-Javadoc)
85       * 
86       * @see de.netseeker.ejoe.adapter.SerializeAdapter#write(java.lang.Object, java.io.OutputStream)
87       */
88      public void write( Object obj, OutputStream out ) throws IOException
89      {
90          JSX.ObjectWriter oout = new JSX.ObjectWriter( out );
91          oout.writeObject( obj );
92          oout.close();
93      }
94  }