KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > ser > ElementDeserializer


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;
18
19 import org.apache.axis.MessageContext;
20 import org.apache.axis.components.logger.LogFactory;
21 import org.apache.axis.encoding.DeserializationContext;
22 import org.apache.axis.encoding.DeserializerImpl;
23 import org.apache.axis.message.MessageElement;
24 import org.apache.axis.utils.Messages;
25 import org.apache.commons.logging.Log;
26 import org.xml.sax.SAXException JavaDoc;
27
28 import java.util.List JavaDoc;
29
30 /**
31  * Deserializer for DOM elements
32  *
33  * @author Glen Daniels (gdaniels@apache.org)
34  * Modified by @author Rich scheuerle <scheu@us.ibm.com>
35  */

36 public class ElementDeserializer extends DeserializerImpl
37 {
38     protected static Log log =
39         LogFactory.getLog(ElementDeserializer.class.getName());
40
41    public static final String JavaDoc DESERIALIZE_CURRENT_ELEMENT = "DeserializeCurrentElement";
42
43     public final void onEndElement(String JavaDoc namespace, String JavaDoc localName,
44                                    DeserializationContext context)
45         throws SAXException JavaDoc
46     {
47         try {
48             MessageElement msgElem = context.getCurElement();
49             if ( msgElem != null ) {
50                 MessageContext messageContext = context.getMessageContext();
51                 Boolean JavaDoc currentElement = (Boolean JavaDoc) messageContext.getProperty(DESERIALIZE_CURRENT_ELEMENT);
52                 if (currentElement != null && currentElement.booleanValue()) {
53                     value = msgElem.getAsDOM();
54                     messageContext.setProperty(DESERIALIZE_CURRENT_ELEMENT, Boolean.FALSE);
55                     return;
56                 }
57                 List JavaDoc children = msgElem.getChildren();
58                 if ( children != null ) {
59                     msgElem = (MessageElement) children.get(0);
60                     if ( msgElem != null )
61                         value = msgElem.getAsDOM();
62                 }
63             }
64         }
65         catch( Exception JavaDoc exp ) {
66             log.error(Messages.getMessage("exception00"), exp);
67             throw new SAXException JavaDoc( exp );
68         }
69     }
70 }
71
Popular Tags