View Javadoc

1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006, 2007 Imola Informatica.
3    *  All rights reserved. This program and the accompanying materials
4    *  are made available under the terms of the LGPL License v2.1
5    *  which accompanies this distribution, and is available at
6    *  http://www.gnu.org/licenses/lgpl.html
7    *******************************************************************************/
8   package it.imolinfo.jbi4ejb.runtime;
9   
10  import it.imolinfo.jbi4ejb.Logger;
11  import it.imolinfo.jbi4ejb.LoggerFactory;
12  
13  import javax.xml.namespace.QName;
14  
15  import org.codehaus.xfire.MessageContext;
16  import org.codehaus.xfire.aegis.MessageReader;
17  import org.codehaus.xfire.aegis.MessageWriter;
18  import org.codehaus.xfire.aegis.type.Type;
19  import org.codehaus.xfire.fault.XFireFault;
20  
21  /**
22   * This class is used to customize the 'byte' data type (java) mapping in XFire.
23   */
24  public class ByteType extends Type {
25  
26      /**
27       * Logger.
28       */
29      private static final Logger LOG = LoggerFactory.getLogger(ByteType.class);
30  
31      /**
32      * Empty Constructor.
33      *
34      * Setting up the XML Schema.
35      */
36      public ByteType() {
37          setNillable(true);
38          setSchemaType(new QName("http://www.w3.org/2001/XMLSchema","byte"));
39          setTypeClass(byte.class);
40      }
41  
42      
43      /**
44       * Reads a ByteType object.
45       * 
46       * @param reader
47       *            The reader
48       * @param context
49       *            The MessageContext
50       * 
51       * @return
52       *          The read object
53       * 
54       * @throws XFireFault
55       *             If some problem occurs
56       * 
57       * The readen object
58       * @see org.codehaus.xfire.aegis.type.Type#readObject(org.codehaus.xfire.aegis.MessageReader,
59       *      org.codehaus.xfire.MessageContext)
60       */
61      public Object readObject(MessageReader reader, MessageContext context)
62          throws XFireFault {
63  
64          LOG.debug(">>>>> ByteType.readObject - begin:" + reader.getValue());
65  
66          String value = reader.getValue();
67  
68          if (value == null || "".equals(value)){
69          LOG.debug("<<<<< ByteType.readObject - end: the value is null.");
70          return null;
71          }
72  
73          LOG.debug("<<<<< ByteType.readObject - end: the value is " + value);
74          return new Byte(value);
75      }
76  
77      
78      /**
79       * Writes out the ByteType object.
80       * 
81       * @param object
82       *          The object 
83       * @param writer
84       *          The writer
85       * @param context
86       *          The MessageContext
87       * 
88       * @throws XFireFault
89       *              If some problem occurs
90       * 
91       * @see org.codehaus.xfire.aegis.type.Type#writeObject(java.lang.Object,
92       *      org.codehaus.xfire.aegis.MessageWriter,
93       *      org.codehaus.xfire.MessageContext)
94       */
95      public void writeObject(Object object,
96                              MessageWriter writer,
97                              MessageContext context) throws XFireFault {
98          String objectString = "";
99          if (object != null) {
100             objectString = object.toString();
101         }
102         
103         if (LOG.isDebugEnabled()) {
104             String debugMsg = ">>>>> ByteType.writeObject - begin: object=" + object
105             + "; class=" + objectString;
106             LOG.debug(debugMsg);
107         }
108         
109         writer.writeValue(objectString);
110 
111         LOG.debug("<<<<< ByteType.writeObject - end");
112     }
113 
114 }