001/*
002 * Copyright (c) 2004-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.ecoinformatics.seek.ecogrid;
031
032import java.io.Serializable;
033
034import org.apache.commons.logging.Log;
035import org.apache.commons.logging.LogFactory;
036import org.ecoinformatics.seek.ecogrid.exception.InvalidEcoGridServiceException;
037
038/**
039 * This class represents a ecogrid service metadata
040 * 
041 * @author Jing Tao
042 * 
043 */
044
045public class EcoGridService implements Serializable {
046        private String serviceGroup = null;
047        private String description = null;
048
049        private String serviceName = null;
050        private String wsdlURL = null;
051        private String serviceType = null;
052        private String endPoint = null;
053        private String serviceClassification = null;
054        private DocumentType[] documentTypeList = null;
055
056        private static Log log;
057        private static boolean isDebugging;
058        static {
059                log = LogFactory
060                                .getLog("org.ecoinformatics.seek.ecogrid.EcoGridService");
061                isDebugging = log.isDebugEnabled();
062        }
063
064        /**
065         * Default constructor
066         */
067        public EcoGridService() {
068        }// EcoGridService
069
070        /**
071         * Copy constructor
072         * 
073         * @param myService
074         *            EcoGridService
075         */
076        public EcoGridService(EcoGridService myService) {
077                this.serviceName = myService.getServiceName();
078                this.serviceGroup = myService.getServiceGroup();
079                this.description = myService.getDescription();
080                this.wsdlURL = myService.getWsdlURL();
081                this.serviceType = myService.getServiceType();
082                this.endPoint = myService.getEndPoint();
083                this.serviceClassification = myService.getServiceClassification();
084                this.documentTypeList = myService.getDocumentTypeList();
085        }
086
087        /**
088         * Get service name
089         * 
090         * @return String
091         */
092        public String getServiceName() {
093                return this.serviceName;
094        }// getServiceName
095
096        /**
097         * Set service name
098         * 
099         * @param serviceName
100         *            String
101         */
102        public void setServiceName(String serviceName) {
103                this.serviceName = serviceName;
104        }// setServiceName
105
106        /**
107         * Get wsdl url for this service
108         * 
109         * @return String
110         */
111        public String getWsdlURL() {
112                return this.wsdlURL;
113        }// getWsdlURL
114
115        /**
116         * Set wsdl url for this service
117         * 
118         * @param wsdlURL
119         *            String
120         */
121        public void setWsdlURL(String wsdlURL) {
122                this.wsdlURL = wsdlURL;
123        }// setWsdlURL
124
125        /**
126         * Get service type of this service
127         * 
128         * @return String
129         */
130        public String getServiceType() {
131                return this.serviceType;
132        }// getServiceType
133
134        /**
135         * Set service type for this service
136         * 
137         * @param serviceType
138         *            String
139         */
140        public void setServiceType(String serviceType)
141                        throws InvalidEcoGridServiceException {
142                if (serviceType == null || serviceType.trim().equals("")) {
143                        throw new InvalidEcoGridServiceException(
144                                        "service type couldn't be null in ecogrid service");
145                }
146
147                this.serviceType = serviceType;
148        }// setServiceType
149
150        /**
151         * Get end point for this service
152         * 
153         * @return String
154         */
155        public String getEndPoint() {
156                return this.endPoint;
157        }// getEndPoint
158
159        /**
160         * Set end point for this service
161         * 
162         * @param endPoint
163         *            String
164         */
165        public void setEndPoint(String endPoint)
166                        throws InvalidEcoGridServiceException {
167                if (endPoint == null || endPoint.trim().equals("")) {
168                        throw new InvalidEcoGridServiceException(
169                                        "End Point couldn't be null in ecogrid service");
170                }
171                this.endPoint = endPoint;
172        }// setEndPoint
173
174        /**
175         * Get service classification
176         * 
177         * @return String
178         */
179        public String getServiceClassification() {
180                return this.serviceClassification;
181        }// getServiceClassification
182
183        /**
184         * Set service classification
185         * 
186         * @param serviceClassification
187         *            String
188         */
189        public void setServiceClassification(String serviceClassification) {
190                this.serviceClassification = serviceClassification;
191        }// setServiceLcassification
192
193        /**
194         * Get document type list in this service
195         * 
196         * @return DocumentType[]
197         */
198        public DocumentType[] getDocumentTypeList() {
199                return documentTypeList;
200        }// getDcoumentTypeList
201
202        /**
203         * Set document type list in this service
204         * 
205         * @param documentTypeList
206         *            DocumentType[]
207         */
208        public void setDocumentTypeList(DocumentType[] documentTypeList) {
209                this.documentTypeList = documentTypeList;
210        }// setDocumentTypeList
211
212        /**
213         * This method will copy a ecogrid service to another one. The difference to
214         * the copy constructor is, it creates a new array for document type
215         * 
216         * @param oldService
217         *            EcoGridService
218         * @return EcoGridService
219         */
220        public static EcoGridService copyEcoGridService(EcoGridService oldService)
221                        throws Exception {
222
223                EcoGridService newService = new EcoGridService();
224                String serviceName = oldService.getServiceName();
225                newService.setServiceName(serviceName);
226                String serviceType = oldService.getServiceType();
227                newService.setServiceType(serviceType);
228                String endpoint = oldService.getEndPoint();
229                newService.setEndPoint(endpoint);
230                newService.setServiceGroup(oldService.getServiceGroup());
231                newService.setServiceClassification(oldService
232                                .getServiceClassification());
233                newService.setWsdlURL(oldService.getWsdlURL());
234                DocumentType[] oldArray = oldService.getDocumentTypeList();
235                if (oldArray != null) {
236                        int length = oldArray.length;
237                        DocumentType[] newArray = new DocumentType[length];
238                        for (int i = 0; i < length; i++) {
239                                DocumentType oldDoc = oldArray[i];
240                                String namespace = oldDoc.getNamespace();
241                                String label = oldDoc.getLabel();
242                                DocumentType newDoc = new DocumentType(namespace, label);
243                                newArray[i] = newDoc;
244                        }// for
245                        newService.setDocumentTypeList(newArray);
246                }// if
247                return newService;
248        }// copyEcoGridService
249
250        /**
251         * Method to print out the service
252         */
253        public void print() {
254                if (!isDebugging) {
255                        return;
256                }
257
258                log.debug("Service Name: " + serviceName);
259                log.debug("Service Group: " + serviceGroup);
260                log.debug("Service WSDL: " + wsdlURL);
261                log.debug("Service Type: " + serviceType);
262                log.debug("End Point: " + endPoint);
263                log.debug("Service Classification: " + serviceClassification);
264                if (documentTypeList != null) {
265                        for (int i = 0; i < documentTypeList.length; i++) {
266                                DocumentType type = documentTypeList[i];
267                                if (type != null) {
268                                        type.print();
269                                }// if
270                        }// for
271                }// if
272        }// print
273
274        public String getServiceGroup() {
275                return this.serviceGroup;
276        }
277
278        public void setServiceGroup(String name) {
279                this.serviceGroup = name;
280        }
281
282        public String getDescription() {
283                return description;
284        }
285
286        public void setDescription(String description) {
287                this.description = description;
288        }
289
290}// EcoGridService