KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > message > HeaderBuilder


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.message;
18
19 /**
20  *
21  * @author Glen Daniels (gdaniels@allaire.com)
22  */

23
24 import org.apache.axis.AxisFault;
25 import org.apache.axis.Constants;
26 import org.apache.axis.components.logger.LogFactory;
27 import org.apache.axis.encoding.DeserializationContext;
28 import org.apache.axis.soap.SOAPConstants;
29 import org.apache.axis.utils.Messages;
30 import org.apache.commons.logging.Log;
31 import org.xml.sax.Attributes JavaDoc;
32 import org.xml.sax.SAXException JavaDoc;
33
34 public class HeaderBuilder extends SOAPHandler
35 {
36     protected static Log log =
37         LogFactory.getLog(HeaderBuilder.class.getName());
38
39     private SOAPHeaderElement header;
40     private SOAPEnvelope envelope;
41
42     HeaderBuilder(SOAPEnvelope envelope)
43     {
44         this.envelope = envelope;
45     }
46
47     public void startElement(String JavaDoc namespace, String JavaDoc localName,
48                              String JavaDoc prefix, Attributes JavaDoc attributes,
49                              DeserializationContext context)
50         throws SAXException JavaDoc
51     {
52         SOAPConstants soapConstants = context.getSOAPConstants();
53
54         if (soapConstants == SOAPConstants.SOAP12_CONSTANTS &&
55             attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) {
56
57             AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER,
58                 null, Messages.getMessage("noEncodingStyleAttrAppear", "Header"), null, null, null);
59
60             throw new SAXException JavaDoc(fault);
61         }
62
63         if (!context.isDoneParsing()) {
64             if (myElement == null) {
65                 try {
66                     myElement = new SOAPHeader(namespace, localName, prefix,
67                                                attributes, context,
68                                                envelope.getSOAPConstants());
69                 } catch (AxisFault axisFault) {
70                     throw new SAXException JavaDoc(axisFault);
71                 }
72                 envelope.setHeader((SOAPHeader)myElement);
73             }
74             context.pushNewElement(myElement);
75         }
76     }
77
78     public SOAPHandler onStartChild(String JavaDoc namespace,
79                                     String JavaDoc localName,
80                                     String JavaDoc prefix,
81                                     Attributes JavaDoc attributes,
82                                     DeserializationContext context)
83         throws SAXException JavaDoc
84     {
85         try {
86             header = new SOAPHeaderElement(namespace, localName, prefix,
87                                            attributes, context);
88         } catch (AxisFault axisFault) {
89             throw new SAXException JavaDoc(axisFault);
90         }
91
92         SOAPHandler handler = new SOAPHandler();
93         handler.myElement = header;
94
95         return handler;
96     }
97
98     public void onEndChild(String JavaDoc namespace, String JavaDoc localName,
99                            DeserializationContext context)
100     {
101     }
102 }
103
Popular Tags