KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > deployment > wsdd > WSDDDocument


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 package org.apache.axis.deployment.wsdd;
17
18 import org.apache.axis.ConfigurationException;
19 import org.apache.axis.components.logger.LogFactory;
20 import org.apache.axis.encoding.SerializationContext;
21 import org.apache.axis.utils.Messages;
22 import org.apache.axis.utils.XMLUtils;
23 import org.apache.commons.logging.Log;
24 import org.w3c.dom.Document JavaDoc;
25 import org.w3c.dom.Element JavaDoc;
26 import org.xml.sax.InputSource JavaDoc;
27
28 import java.io.IOException JavaDoc;
29 import java.io.StringReader JavaDoc;
30 import java.io.StringWriter JavaDoc;
31
32
33 /**
34  * represents a WSDD Document (this is the top level object in this object model)
35  * Only one of {@link #deployment} and {@link #undeployment} should be valid.
36  */

37 public class WSDDDocument extends WSDDConstants
38 {
39     protected static Log log =
40         LogFactory.getLog(WSDDDocument.class.getName());
41
42     /** owner doc */
43     private Document JavaDoc doc;
44
45     /**
46      * deployment tree. may be null
47      */

48     private WSDDDeployment deployment;
49     /** undeployment tree. may be null */
50     private WSDDUndeployment undeployment;
51
52     /**
53      * empty constructor
54      */

55     public WSDDDocument()
56     {
57     }
58
59     /**
60      * create and bind to a document
61      * @param document (Document) XXX
62      */

63     public WSDDDocument(Document JavaDoc document) throws WSDDException
64     {
65         setDocument(document);
66     }
67
68     /**
69      * bind to a sub-element in a document.
70      * @param e (Element) XXX
71      */

72     public WSDDDocument(Element JavaDoc e) throws WSDDException
73     {
74         doc = e.getOwnerDocument();
75         if (ELEM_WSDD_UNDEPLOY.equals(e.getLocalName())) {
76             undeployment = new WSDDUndeployment(e);
77         } else {
78             deployment = new WSDDDeployment(e);
79         }
80     }
81
82     /**
83      * Get the deployment. If there is no deployment, create an empty one
84      * @return the deployment document
85      */

86     public WSDDDeployment getDeployment()
87     {
88         if (deployment == null) {
89             deployment = new WSDDDeployment();
90         }
91         return deployment;
92     }
93
94     /**
95      * get the deployment as a DOM.
96      * Requires that the deployment member variable is not null.
97      * @return
98      * @throws ConfigurationException
99      */

100     public Document JavaDoc getDOMDocument() throws ConfigurationException {
101         StringWriter JavaDoc writer = new StringWriter JavaDoc();
102         SerializationContext context = new SerializationContext(writer, null);
103         context.setPretty(true);
104         try {
105             deployment.writeToContext(context);
106         } catch (Exception JavaDoc e) {
107             log.error(Messages.getMessage("exception00"), e);
108         }
109         try {
110             writer.close();
111             return XMLUtils.newDocument(new InputSource JavaDoc(new StringReader JavaDoc(writer.getBuffer().toString())));
112         } catch (Exception JavaDoc e) {
113             return null;
114         }
115     }
116
117     /**
118      * write the deployment to the supplied serialization context.
119      * @param context
120      * @throws IOException
121      */

122     public void writeToContext(SerializationContext context)
123         throws IOException JavaDoc
124     {
125         getDeployment().writeToContext(context);
126     }
127
128     /**
129      * Bind to a new document, setting the undeployment nodes if it is an undeployment,
130      * the deployment tree if it is anything else.
131      * @param document XXX
132      */

133     public void setDocument(Document JavaDoc document) throws WSDDException {
134         this.doc = document;
135         Element JavaDoc docEl = doc.getDocumentElement();
136         if (ELEM_WSDD_UNDEPLOY.equals(docEl.getLocalName())) {
137             undeployment = new WSDDUndeployment(docEl);
138         } else {
139             deployment = new WSDDDeployment(docEl);
140         }
141     }
142
143     /**
144      * do a deploy and/or undeploy, depending on what is in the document.
145      * If both trees are set, then undeploy follows deploy.
146      * @param registry
147      * @throws ConfigurationException
148      */

149     public void deploy(WSDDDeployment registry) throws ConfigurationException {
150         if (deployment != null) {
151             deployment.deployToRegistry(registry);
152         }
153         if (undeployment != null) {
154             undeployment.undeployFromRegistry(registry);
155         }
156     }
157 }
158
Popular Tags