KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > impl > llom > mtom > MTOMStAXSOAPModelBuilder


1 /**
2  * Copyright 2001-2004 The Apache Software Foundation.
3  * <p/>
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  * <p/>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p/>
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  * <p/>
16  */

17 package org.apache.axis2.om.impl.llom.mtom;
18
19 import org.apache.axis2.attachments.MIMEHelper;
20 import org.apache.axis2.om.*;
21 import org.apache.axis2.om.impl.llom.OMTextImpl;
22 import org.apache.axis2.soap.SOAPFactory;
23 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import javax.activation.DataHandler JavaDoc;
28 import javax.xml.stream.XMLStreamReader;
29
30 /**
31  * @author <a HREF="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
32  */

33
34 public class MTOMStAXSOAPModelBuilder extends StAXSOAPModelBuilder {
35     private Log log = LogFactory.getLog(getClass());
36     
37     /**
38      * <code>mimeHelper</code> handles deffered parsing of incoming MIME
39      * Messages
40      */

41     MIMEHelper mimeHelper;
42     
43     int partIndex = 0;
44     
45     public MTOMStAXSOAPModelBuilder(XMLStreamReader parser,
46             SOAPFactory factory, MIMEHelper mimeHelper) {
47         super(parser, factory);
48         this.mimeHelper = mimeHelper;
49     }
50     
51     /**
52      * @param reader
53      * @param mimeHelper2
54      */

55     public MTOMStAXSOAPModelBuilder(XMLStreamReader reader,
56             MIMEHelper mimeHelper) {
57         super(reader);
58         this.mimeHelper = mimeHelper;
59     }
60     
61     protected OMNode createOMElement() throws OMException {
62         
63         String JavaDoc elementName = parser.getLocalName();
64         
65         String JavaDoc namespaceURI = parser.getNamespaceURI();
66         
67         // create an OMBlob if the element is an <xop:Include>
68
if (elementName.equalsIgnoreCase("Include")
69                 & namespaceURI
70                 .equalsIgnoreCase("http://www.w3.org/2004/08/xop/include")) {
71             
72             OMText node;
73             String JavaDoc contentID = null;
74             String JavaDoc contentIDName = null;
75             OMAttribute Attr;
76             if (lastNode == null) {
77                 // Decide whether to ckeck the level >3 or not
78
throw new OMException(
79                 "XOP:Include element is not supported here");
80             }
81             if (parser.getAttributeCount() > 0) {
82                 contentID = parser.getAttributeValue(0);
83                 contentID = contentID.trim();
84                 contentIDName = parser.getAttributeLocalName(0);
85                 if (contentIDName.equalsIgnoreCase("href")
86                         & contentID.substring(0, 3).equalsIgnoreCase("cid")) {
87                     contentID = contentID.substring(4);
88                 } else {
89                     throw new OMException(
90                     "contentID not Found in XOP:Include element");
91                 }
92             } else {
93                 throw new OMException(
94                 "Href attribute not found in XOP:Include element");
95             }
96             
97             // This cannot happen. XOP:Include is always the only child of an parent element
98
// cause it is same as having some text
99
// if (lastNode.isComplete()) {
100
// node = new OMTextImpl(contentID, (OMElement) lastNode.getParent(), this);
101
// lastNode.setNextSibling(node);
102
// node.setPreviousSibling(lastNode);
103
//} else {
104
OMElement e = (OMElement) lastNode;
105                 node = new OMTextImpl(contentID, (OMElement) lastNode, this);
106                 e.setFirstChild(node);
107                 node.setComplete(true);
108             //}
109
return node;
110             
111         } else {
112             OMElement node;
113             if (lastNode == null) {
114                 node = constructNode(null, elementName, true);
115             } else if (lastNode.isComplete()) {
116                 node = constructNode((OMElement)lastNode.getParent(), elementName, false);
117                 lastNode.setNextSibling(node);
118                 node.setPreviousSibling(lastNode);
119             } else {
120                 OMElement e = (OMElement) lastNode;
121                 node = constructNode((OMElement) lastNode, elementName, false);
122                 e.setFirstChild(node);
123             }
124             
125             // fill in the attributes
126
processAttributes(node);
127             //TODO Exception when trying to log . check this
128
// log.info("Build the OMElelment {" + node.getLocalName() + '}'
129
// + node.getLocalName() + "By the StaxSOAPModelBuilder");
130
return node;
131         }
132     }
133     
134     public DataHandler JavaDoc getDataHandler(String JavaDoc blobContentID) throws OMException {
135         return mimeHelper.getDataHandler(blobContentID);
136     }
137 }
138
Popular Tags