KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.deployment.wsdd;
56
57 import org.jboss.axis.ConfigurationException;
58 import org.jboss.axis.encoding.SerializationContext;
59 import org.jboss.axis.encoding.SerializationContextImpl;
60 import org.jboss.axis.utils.Messages;
61 import org.jboss.axis.utils.XMLUtils;
62 import org.jboss.logging.Logger;
63 import org.w3c.dom.Document JavaDoc;
64 import org.w3c.dom.Element JavaDoc;
65 import org.xml.sax.InputSource JavaDoc;
66
67 import java.io.IOException JavaDoc;
68 import java.io.StringReader JavaDoc;
69 import java.io.StringWriter JavaDoc;
70
71
72 /**
73  * represents a WSDD Document (this is the top level object in this object model)
74  */

75 public class WSDDDocument extends WSDDConstants
76 {
77    private static Logger log = Logger.getLogger(WSDDDocument.class.getName());
78
79    private Document JavaDoc doc;
80
81    private WSDDDeployment deployment;
82    private WSDDUndeployment undeployment;
83
84    /**
85     *
86     */

87    public WSDDDocument()
88    {
89    }
90
91    /**
92     * @param doc (Document) XXX
93     */

94    public WSDDDocument(Document JavaDoc doc) throws WSDDException
95    {
96       this.doc = doc;
97       Element JavaDoc docEl = doc.getDocumentElement();
98       if (ELEM_WSDD_UNDEPLOY.equals(docEl.getLocalName()))
99       {
100          undeployment = new WSDDUndeployment(docEl);
101       }
102       else
103       {
104          deployment = new WSDDDeployment(docEl);
105       }
106    }
107
108    /**
109     * @param e (Element) XXX
110     */

111    public WSDDDocument(Element JavaDoc e) throws WSDDException
112    {
113       doc = e.getOwnerDocument();
114       if (ELEM_WSDD_UNDEPLOY.equals(e.getLocalName()))
115       {
116          undeployment = new WSDDUndeployment(e);
117       }
118       else
119       {
120          deployment = new WSDDDeployment(e);
121       }
122    }
123
124    /**
125     * @return XXX
126     */

127    public WSDDDeployment getDeployment()
128    {
129       if (deployment == null)
130          deployment = new WSDDDeployment();
131       return deployment;
132    }
133
134    public Document JavaDoc getDOMDocument() throws ConfigurationException
135    {
136       StringWriter JavaDoc writer = new StringWriter JavaDoc();
137       SerializationContext context = new SerializationContextImpl(writer, null);
138       context.setPretty(true);
139       try
140       {
141          deployment.writeToContext(context);
142       }
143       catch (Exception JavaDoc e)
144       {
145          log.error(Messages.getMessage("exception00"), e);
146       }
147       try
148       {
149          writer.close();
150          return XMLUtils.newDocument(new InputSource JavaDoc(new StringReader JavaDoc(writer.getBuffer().toString())));
151       }
152       catch (Exception JavaDoc e)
153       {
154          return null;
155       }
156    }
157
158    public void writeToContext(SerializationContext context)
159            throws IOException JavaDoc
160    {
161       getDeployment().writeToContext(context);
162    }
163
164    /**
165     * @param document XXX
166     */

167    public void setDocument(Document JavaDoc document)
168    {
169       doc = document;
170
171       deployment = null;
172    }
173
174    public void deploy(WSDDDeployment registry) throws ConfigurationException
175    {
176       if (deployment != null)
177       {
178          deployment.deployToRegistry(registry);
179       }
180       if (undeployment != null)
181       {
182          undeployment.undeployFromRegistry(registry);
183       }
184    }
185 }
186
Popular Tags