KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > WebServicesDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment;
24
25 import java.util.Iterator JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.HashSet JavaDoc;
28
29 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
30 import com.sun.enterprise.deployment.node.WebServicesDescriptorNode;
31
32 /**
33  * Information about the web services defined in a single module.
34  *
35  * @author Kenneth Saks
36  * @author Jerome Dochez
37  */

38
39 public class WebServicesDescriptor extends RootDeploymentDescriptor {
40
41     // Module in which these web services are defined.
42
private BundleDescriptor bundleDesc;
43
44     private Collection JavaDoc<WebService> webServices;
45     /**
46      * Default constructor.
47      */

48     public WebServicesDescriptor() {
49         webServices = new HashSet JavaDoc<WebService>();
50     }
51
52     /**
53      * @return the default version of the deployment descriptor
54      * loaded by this descriptor
55      */

56     public String JavaDoc getDefaultSpecVersion() {
57         return WebServicesDescriptorNode.SPEC_VERSION;
58     }
59
60     public void setBundleDescriptor(BundleDescriptor module) {
61         bundleDesc = module;
62     }
63
64     public BundleDescriptor getBundleDescriptor() {
65         return bundleDesc;
66     }
67
68     public boolean hasWebServices() {
69         return !(webServices.isEmpty());
70     }
71
72     public WebService getWebServiceByName(String JavaDoc webServiceName) {
73         for (WebService webService : webServices) {
74             if( webService.getName().equals(webServiceName) ) {
75                 return webService;
76             }
77         }
78         return null;
79     }
80
81     public void addWebService(WebService descriptor) {
82         descriptor.setWebServicesDescriptor(this);
83         webServices.add(descriptor);
84         super.changed();
85     }
86
87     public void removeWebService(WebService descriptor) {
88         descriptor.setWebServicesDescriptor(null);
89         webServices.remove(descriptor);
90         super.changed();
91     }
92
93     public Collection JavaDoc<WebService> getWebServices() {
94         return new HashSet JavaDoc<WebService>(webServices);
95     }
96
97     /**
98      * Endpoint has a unique name within all the endpoints in the module.
99      * @return WebServiceEndpoint or null if not found
100      */

101     public WebServiceEndpoint getEndpointByName(String JavaDoc endpointName) {
102         for(Iterator JavaDoc iter = getEndpoints().iterator(); iter.hasNext();) {
103             WebServiceEndpoint next = (WebServiceEndpoint) iter.next();
104             if( next.getEndpointName().equals(endpointName) ) {
105                 return next;
106             }
107         }
108         return null;
109     }
110
111     public boolean hasEndpointsImplementedBy(EjbDescriptor ejb) {
112         return !(getEndpointsImplementedBy(ejb).isEmpty());
113     }
114
115     public Collection JavaDoc<WebServiceEndpoint> getEndpointsImplementedBy(EjbDescriptor ejb) {
116         Collection JavaDoc<WebServiceEndpoint> endpoints = new HashSet JavaDoc();
117         if( ejb instanceof EjbSessionDescriptor ) {
118             for(WebServiceEndpoint next : getEndpoints()) {
119                 if( next.implementedByEjbComponent(ejb) ) {
120                     endpoints.add(next);
121                 }
122             }
123         }
124         return endpoints;
125     }
126
127     public boolean hasEndpointsImplementedBy(WebComponentDescriptor desc) {
128         return !(getEndpointsImplementedBy(desc).isEmpty());
129     }
130
131     public Collection JavaDoc<WebServiceEndpoint> getEndpointsImplementedBy(WebComponentDescriptor desc) {
132         Collection JavaDoc<WebServiceEndpoint> endpoints = new HashSet JavaDoc();
133         for(WebServiceEndpoint next : getEndpoints()) {
134             if( next.implementedByWebComponent(desc) ) {
135                 endpoints.add(next);
136             }
137         }
138         return endpoints;
139     }
140
141     public Collection JavaDoc<WebServiceEndpoint> getEndpoints() {
142         Collection JavaDoc allEndpoints = new HashSet JavaDoc();
143         for(WebService webService : webServices) {
144             allEndpoints.addAll( webService.getEndpoints() );
145         }
146         return allEndpoints;
147     }
148     
149     public ModuleType JavaDoc getModuleType() {
150         if (bundleDesc!=null) {
151           return bundleDesc.getModuleType();
152         }
153         return null;
154     }
155
156     
157     //
158
// Dummy RootDeploymentDescriptor implementations for methods that
159
// do not apply to WebServicesDescriptor.
160
//
161
public String JavaDoc getModuleID() { return ""; }
162     public ClassLoader JavaDoc getClassLoader() { return null; }
163     public boolean isApplication() {return false; }
164
165     /**
166      * Returns a formatted String of the attributes of this object.
167      */

168     public void print(StringBuffer JavaDoc toStringBuffer) {
169     super.print(toStringBuffer);
170         if (hasWebServices()) {
171             for (Iterator JavaDoc itr = getWebServices().iterator();itr.hasNext();) {
172                 WebService aWebService = (WebService) itr.next();
173                 toStringBuffer.append("\n Web Service : ");
174                 aWebService.print(toStringBuffer);
175             }
176         }
177     }
178     
179 }
180
Popular Tags