View Javadoc

1   /**
2    *
3    * Copyright 2003-2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.geronimo.webservices;
18  
19  import java.util.ArrayList;
20  import java.util.HashMap;
21  
22  
23  /**
24   * A dtd version of the J2EE webservices.xml file would look like this:
25   * <p/>
26   * webservices (webservice-description+)
27   * webservice-description (webservice-description-name, wsdl-file, jaxrpc-mapping-file, port-component+)
28   * port-component (port-component-name, wsdl-port, service-endpoint-interface, service-impl-bean, handler*)
29   * service-impl-bean (ejb-link|servlet-link)
30   * handler (handler-name, handler-class, init-param*, soap-header*, soap-role*)
31   */
32  public class WebServices {
33      /**
34       * List of WebServiceDescription objects
35       *
36       * @see org.apache.geronimo.webservices.WebServiceDescription
37       */
38      private ArrayList webServiceDescriptionList = new ArrayList();
39      /**
40       * Map of WebServiceDescription objects indexed by webServiceDescriptionName
41       *
42       * @see org.apache.geronimo.webservices.WebServiceDescription#getWebServiceDescriptionName
43       */
44      private HashMap webServiceDescriptionMap = new HashMap();
45  
46      public void addWebServiceDescription(WebServiceDescription webServiceDescription) throws IndexOutOfBoundsException {
47          webServiceDescriptionList.add(webServiceDescription);
48          webServiceDescriptionMap.put(webServiceDescription.getWebServiceDescriptionName(), webServiceDescription);
49      }
50  
51      public void addWebServiceDescription(int index, WebServiceDescription webServiceDescription) throws IndexOutOfBoundsException {
52          webServiceDescriptionList.add(index, webServiceDescription);
53          webServiceDescriptionMap.put(webServiceDescription.getWebServiceDescriptionName(), webServiceDescription);
54      }
55  
56      public boolean removeWebServiceDescription(WebServiceDescription webServiceDescription) {
57          webServiceDescriptionMap.remove(webServiceDescription.getWebServiceDescriptionName());
58          return webServiceDescriptionList.remove(webServiceDescription);
59      }
60  
61      public WebServiceDescription getWebServiceDescription(int index) throws IndexOutOfBoundsException {
62          if ((index < 0) || (index > webServiceDescriptionList.size())) {
63              throw new IndexOutOfBoundsException();
64          }
65          return (WebServiceDescription) webServiceDescriptionList.get(index);
66      }
67  
68      public WebServiceDescription[] getWebServiceDescription() {
69          int size = webServiceDescriptionList.size();
70          WebServiceDescription[] mArray = new WebServiceDescription[size];
71          for (int index = 0; index < size; index++) {
72              mArray[index] = (WebServiceDescription) webServiceDescriptionList.get(index);
73          }
74          return mArray;
75      }
76  
77      public WebServiceDescription getWebServiceDescription(String webServiceDescriptionName) {
78          return (WebServiceDescription) webServiceDescriptionMap.get(webServiceDescriptionName);
79      }
80  
81      public void setWebServiceDescription(int index, WebServiceDescription webServiceDescription) throws IndexOutOfBoundsException {
82          if ((index < 0) || (index > webServiceDescriptionList.size())) {
83              throw new IndexOutOfBoundsException();
84          }
85          WebServiceDescription removed = (WebServiceDescription) webServiceDescriptionList.set(index, webServiceDescription);
86          webServiceDescriptionMap.remove(removed.getWebServiceDescriptionName());
87          webServiceDescriptionMap.put(webServiceDescription.getWebServiceDescriptionName(), webServiceDescription);
88      }
89  
90      public void setWebServiceDescription(WebServiceDescription[] webServiceDescriptionArray) {
91          clearWebServiceDescription();
92          for (int i = 0; i < webServiceDescriptionArray.length; i++) {
93              WebServiceDescription webServiceDescription = webServiceDescriptionArray[i];
94              webServiceDescriptionList.add(webServiceDescription);
95              webServiceDescriptionMap.put(webServiceDescription.getWebServiceDescriptionName(), webServiceDescription);
96          }
97      }
98  
99      public void clearWebServiceDescription() {
100         webServiceDescriptionList.clear();
101         webServiceDescriptionMap.clear();
102     }
103 }