KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > DetailImpl


1 /*
2  * Copyright 2004,2005 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 package org.apache.axis2.saaj;
17
18 import org.apache.axis2.om.OMAbstractFactory;
19 import org.apache.axis2.om.OMElement;
20 import org.apache.axis2.om.OMFactory;
21 import org.apache.axis2.om.OMNamespace;
22
23 import javax.xml.soap.Detail JavaDoc;
24 import javax.xml.soap.DetailEntry JavaDoc;
25 import javax.xml.soap.Name JavaDoc;
26 import javax.xml.soap.SOAPException JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * Class DetailImpl
32  *
33  * @author Ashutosh Shahi
34  * ashutosh.shahi@gmail.com
35  */

36 public class DetailImpl extends SOAPFaultElementImpl implements Detail JavaDoc {
37     
38     /**
39      * Field detail
40      */

41     OMElement detail;
42     
43     /**
44      * Constructor DetailImpl
45      *
46      * @param detailName
47      * @param parent
48      */

49     public DetailImpl(javax.xml.namespace.QName JavaDoc detailName, OMElement parent){
50         OMFactory omFactory = OMAbstractFactory.getOMFactory();
51         detail = omFactory.createOMElement(detailName, parent);
52     }
53     
54     /*public DetailImpl(OMElement detail){
55         this.detail = detail;
56     }*/

57
58     /**
59      * Method addDetailEntry
60      *
61      * @param name
62      * @return
63      * @throws SOAPException
64      * @see javax.xml.soap.Detail#addDetailEntry(javax.xml.soap.Name)
65      */

66     public DetailEntry JavaDoc addDetailEntry(Name JavaDoc name) throws SOAPException JavaDoc {
67         
68         // Create a OMElement and add it as a child of Detail
69
// May need change after OM allows adding multiple detailEntries
70
// as then we can delegate the task there rather than dealing with OMElement here
71
String JavaDoc localName = name.getLocalName();
72         OMFactory omFactory = OMAbstractFactory.getOMFactory();
73         OMNamespace ns = omFactory.createOMNamespace(name.getURI(), name.getPrefix());
74         OMElement detailEntry = omFactory.createOMElement(localName, ns);
75         detail.addChild(detailEntry);
76         return (new DetailEntryImpl(detailEntry));
77     }
78     
79     /**
80      * Method addDetailEntry
81      *
82      * @param detailEntry
83      * @return
84      */

85     protected DetailEntry JavaDoc addDetailEntry(org.apache.axis2.om.OMNode detailEntry){
86         detail.addChild(detailEntry);
87         return (new DetailEntryImpl((OMElement)detailEntry));
88     }
89
90     /**
91      * Method getDetailEntries
92      *
93      * @return
94      * @see javax.xml.soap.Detail#getDetailEntries()
95      */

96     public Iterator JavaDoc getDetailEntries() {
97         // Get the detailEntried which will be omElements
98
// convert them to soap DetailEntry and return the iterator
99
Iterator JavaDoc detailEntryIter = detail.getChildren();
100         ArrayList JavaDoc aList = new ArrayList JavaDoc();
101         while(detailEntryIter.hasNext()){
102             Object JavaDoc o = detailEntryIter.next();
103             if(o instanceof org.apache.axis2.om.OMElement){
104                 OMElement omDetailEntry = (OMElement)o;
105                 DetailEntry JavaDoc detailEntry = new DetailEntryImpl(omDetailEntry);
106                 aList.add(detailEntry);
107             }
108         }
109         return aList.iterator();
110     }
111
112 }
113
Popular Tags