KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.axis.encoding.ser;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 Document
32  *
33  * @author Davanum Srinivas <dims@yahoo.com>
34  */

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