001 /** 002 * 003 * Copyright 2003-2004 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.webservices; 018 019 import java.util.ArrayList; 020 import java.util.HashMap; 021 022 023 /** 024 * A dtd version of the J2EE webservices.xml file would look like this: 025 * <p/> 026 * webservices (webservice-description+) 027 * webservice-description (webservice-description-name, wsdl-file, jaxrpc-mapping-file, port-component+) 028 * port-component (port-component-name, wsdl-port, service-endpoint-interface, service-impl-bean, handler*) 029 * service-impl-bean (ejb-link|servlet-link) 030 * handler (handler-name, handler-class, init-param*, soap-header*, soap-role*) 031 */ 032 public class WebServices { 033 /** 034 * List of WebServiceDescription objects 035 * 036 * @see org.apache.geronimo.webservices.WebServiceDescription 037 */ 038 private ArrayList webServiceDescriptionList = new ArrayList(); 039 /** 040 * Map of WebServiceDescription objects indexed by webServiceDescriptionName 041 * 042 * @see org.apache.geronimo.webservices.WebServiceDescription#getWebServiceDescriptionName 043 */ 044 private HashMap webServiceDescriptionMap = new HashMap(); 045 046 public void addWebServiceDescription(WebServiceDescription webServiceDescription) throws IndexOutOfBoundsException { 047 webServiceDescriptionList.add(webServiceDescription); 048 webServiceDescriptionMap.put(webServiceDescription.getWebServiceDescriptionName(), webServiceDescription); 049 } 050 051 public void addWebServiceDescription(int index, WebServiceDescription webServiceDescription) throws IndexOutOfBoundsException { 052 webServiceDescriptionList.add(index, webServiceDescription); 053 webServiceDescriptionMap.put(webServiceDescription.getWebServiceDescriptionName(), webServiceDescription); 054 } 055 056 public boolean removeWebServiceDescription(WebServiceDescription webServiceDescription) { 057 webServiceDescriptionMap.remove(webServiceDescription.getWebServiceDescriptionName()); 058 return webServiceDescriptionList.remove(webServiceDescription); 059 } 060 061 public WebServiceDescription getWebServiceDescription(int index) throws IndexOutOfBoundsException { 062 if ((index < 0) || (index > webServiceDescriptionList.size())) { 063 throw new IndexOutOfBoundsException(); 064 } 065 return (WebServiceDescription) webServiceDescriptionList.get(index); 066 } 067 068 public WebServiceDescription[] getWebServiceDescription() { 069 int size = webServiceDescriptionList.size(); 070 WebServiceDescription[] mArray = new WebServiceDescription[size]; 071 for (int index = 0; index < size; index++) { 072 mArray[index] = (WebServiceDescription) webServiceDescriptionList.get(index); 073 } 074 return mArray; 075 } 076 077 public WebServiceDescription getWebServiceDescription(String webServiceDescriptionName) { 078 return (WebServiceDescription) webServiceDescriptionMap.get(webServiceDescriptionName); 079 } 080 081 public void setWebServiceDescription(int index, WebServiceDescription webServiceDescription) throws IndexOutOfBoundsException { 082 if ((index < 0) || (index > webServiceDescriptionList.size())) { 083 throw new IndexOutOfBoundsException(); 084 } 085 WebServiceDescription removed = (WebServiceDescription) webServiceDescriptionList.set(index, webServiceDescription); 086 webServiceDescriptionMap.remove(removed.getWebServiceDescriptionName()); 087 webServiceDescriptionMap.put(webServiceDescription.getWebServiceDescriptionName(), webServiceDescription); 088 } 089 090 public void setWebServiceDescription(WebServiceDescription[] webServiceDescriptionArray) { 091 clearWebServiceDescription(); 092 for (int i = 0; i < webServiceDescriptionArray.length; i++) { 093 WebServiceDescription webServiceDescription = webServiceDescriptionArray[i]; 094 webServiceDescriptionList.add(webServiceDescription); 095 webServiceDescriptionMap.put(webServiceDescription.getWebServiceDescriptionName(), webServiceDescription); 096 } 097 } 098 099 public void clearWebServiceDescription() { 100 webServiceDescriptionList.clear(); 101 webServiceDescriptionMap.clear(); 102 } 103 }