Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/axis/encoding/ser/castor/CastorDeserializer.java


1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.axis.encoding.ser.castor;
18  
19  import org.apache.axis.encoding.DeserializationContext;
20  import org.apache.axis.encoding.Deserializer;
21  import org.apache.axis.encoding.DeserializerImpl;
22  import org.apache.axis.message.MessageElement;
23  import org.apache.axis.utils.Messages;
24  import org.exolab.castor.xml.MarshalException;
25  import org.exolab.castor.xml.Unmarshaller;
26  import org.exolab.castor.xml.ValidationException;
27  import org.xml.sax.SAXException;
28  
29  import javax.xml.namespace.QName;
30  
31  /**
32   * Castor deserializer
33   * 
34   * @author Olivier Brand (olivier.brand@vodafone.com)
35   * @author Steve Loughran
36   * @version 1.0
37   */
38  public class CastorDeserializer
39          extends DeserializerImpl
40          implements Deserializer {
41  
42      public QName xmlType;
43      public Class javaType;
44  
45      public CastorDeserializer(Class javaType, QName xmlType) {
46          this.xmlType = xmlType;
47          this.javaType = javaType;
48      }
49  
50      /**
51       * Return something even if no characters were found.
52       */
53      public void onEndElement(
54              String namespace,
55              String localName,
56              DeserializationContext context)
57              throws SAXException {
58          try {
59              MessageElement msgElem = context.getCurElement();
60              if (msgElem != null) {
61                  // Unmarshall the nested XML element into a castor object of type 'javaType'
62                  value = Unmarshaller.unmarshal(javaType, msgElem.getAsDOM());
63              }
64          } catch (MarshalException me) {
65              log.error(Messages.getMessage("castorMarshalException00"), me);
66              throw new SAXException(Messages.getMessage("castorMarshalException00")
67                      + me.getLocalizedMessage());
68          } catch (ValidationException ve) {
69              log.error(Messages.getMessage("castorValidationException00"), ve);
70              throw new SAXException(Messages.getMessage("castorValidationException00")
71                      + ve.getLocation() + ": " + ve.getLocalizedMessage());
72          } catch (Exception exp) {
73              log.error(Messages.getMessage("exception00"), exp);
74              throw new SAXException(exp);
75          }
76  
77      }
78  }