001/* 002 * Copyright (c) 2003-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.util.Vector; 033 034/** 035 * This class extends from EcoGridService, it contains selected status from user 036 * interface 037 * 038 * @author Jing Tao 039 * 040 */ 041 042public class SelectableEcoGridService extends EcoGridService { 043 044 private SelectableServiceName selectableServiceName = null; 045 private SelectableDocumentType[] selectableDcoumentTypeList = null;// inlcude 046 // selected and unselected 047 private SelectableDocumentType[] selectedDocumentTypeList = null;// only 048 049 // selected part 050 /** 051 * Default constructor and inits selected service name and document type 052 * array 053 */ 054 public SelectableEcoGridService() { 055 super(); 056 initSeletableServiceName(); 057 initSelectableDocumentTypeList(); 058 }// SelectedEcoGridService 059 060 /** 061 * Copy Constructor, copy a EcoGridService and inited selected service name 062 * and selected document type array 063 * 064 * @param myService 065 * EcoGridService 066 */ 067 public SelectableEcoGridService(EcoGridService myService) { 068 super(myService); 069 initSeletableServiceName(); 070 initSelectableDocumentTypeList(); 071 } 072 073 /* 074 * Method to initial Seletect service name 075 */ 076 private void initSeletableServiceName() { 077 selectableServiceName = new SelectableServiceName(); 078 selectableServiceName.setServiceName(super.getServiceName()); 079 selectableServiceName 080 .setIsSelected(SelectableObjectInterface.DEFAULTSELECTIONSTATUS); 081 }// initSelectedServiceName 082 083 /* 084 * Method to initial select document type array 085 */ 086 private void initSelectableDocumentTypeList() { 087 DocumentType[] documentTypeList = super.getDocumentTypeList(); 088 if (documentTypeList != null) { 089 int length = documentTypeList.length; 090 selectableDcoumentTypeList = new SelectableDocumentType[length]; 091 for (int i = 0; i < length; i++) { 092 DocumentType documentType = documentTypeList[i]; 093 SelectableDocumentType selectedDcoumetType = new SelectableDocumentType( 094 documentType, this.getSelectableServiceName() 095 .getIsSelected()); // inherit from service 096 // selection 097 // SelectableObjectInterface.DEFAULTSELECTIONSTATUS); 098 selectableDcoumentTypeList[i] = selectedDcoumetType; 099 } 100 }// if 101 }// initSeletedCoumentTypeList 102 103 /** 104 * Method to get selected service name 105 * 106 * @return SelectedServiceName 107 */ 108 public SelectableServiceName getSelectableServiceName() { 109 return this.selectableServiceName; 110 }// getSelectedServieName 111 112 /** 113 * Method to set selectable service name(both selected and unselected) 114 * 115 * @param selectedServiceName 116 * SelectedServiceName 117 */ 118 public void setSelectableServiceName( 119 SelectableServiceName selectedServiceName) { 120 this.selectableServiceName = selectedServiceName; 121 }// setSelectedServiceName 122 123 /** 124 * Method to get selectable DocumentType list(both selected and unselected) 125 * 126 * @return SelectedDocumentType[] 127 */ 128 public SelectableDocumentType[] getSelectableDocumentTypeList() { 129 return this.selectableDcoumentTypeList; 130 }// getSelectedDocumentTypeList 131 132 /** 133 * Method to set selected docuemnt type list( 134 * 135 * @param selectedDocumentTypeList 136 * SelectedDocumentType[] 137 */ 138 public void setSelectedDocumentTypeList( 139 SelectableDocumentType[] selectedDocumentTypeList) { 140 this.selectedDocumentTypeList = selectedDocumentTypeList; 141 }// setSelectedDocumentTypeList 142 143 /** 144 * Method to get selectable DocumentType list(only selected) 145 * 146 * @return SelectedDocumentType[] 147 */ 148 public SelectableDocumentType[] getSelectedDocumentTypeList() { 149 if (selectableDcoumentTypeList != null) { 150 int length = selectableDcoumentTypeList.length; 151 Vector docList = new Vector(); 152 for (int i = 0; i < length; i++) { 153 SelectableDocumentType type = selectableDcoumentTypeList[i]; 154 if (type.getIsSelected()) { 155 docList.add(type); 156 } 157 } 158 int size = docList.size(); 159 selectedDocumentTypeList = new SelectableDocumentType[size]; 160 for (int j = 0; j < size; j++) { 161 selectedDocumentTypeList[j] = (SelectableDocumentType) docList 162 .elementAt(j); 163 } 164 } 165 return this.selectedDocumentTypeList; 166 }// getSelectedDocumentTypeList 167 168 /** 169 * Method to add a selected document type into list 170 * 171 * @param selectedDocumentType 172 */ 173 public void addSelectedDocumentType(SelectableDocumentType type) { 174 int size = 0; 175 if (selectedDocumentTypeList != null) { 176 size = selectedDocumentTypeList.length; 177 } 178 SelectableDocumentType[] list = new SelectableDocumentType[size + 1]; 179 for (int i = 0; i < size; i++) { 180 list[i] = selectedDocumentTypeList[i]; 181 } 182 list[size] = type; 183 selectedDocumentTypeList = list; 184 } 185 186 /** 187 * Method to set selectable docuemnt type list 188 * 189 * @param selectedDocumentTypeList 190 * SelectedDocumentType[] 191 */ 192 public void setSelectableDocumentTypeList( 193 SelectableDocumentType[] selectedDocumentTypeList) { 194 this.selectableDcoumentTypeList = selectedDocumentTypeList; 195 }// setSelectedDocumentTypeList 196 197 /** 198 * Method to transfer a vecotr of ecogrid service to default selected 199 * ecogrid service vector. This is a utility method 200 * 201 * @param serviceVector 202 * Vector 203 * @return Vector 204 */ 205 public static Vector transferServiceVectToDefaultSelectedServiceVect( 206 Vector serviceVector) { 207 Vector selectedServiceVector = new Vector(); 208 if (serviceVector == null) { 209 return selectedServiceVector; 210 }// if 211 int size = serviceVector.size(); 212 for (int i = 0; i < size; i++) { 213 EcoGridService service = (EcoGridService) serviceVector 214 .elementAt(i); 215 SelectableEcoGridService selectedService = new SelectableEcoGridService( 216 service); 217 DocumentType[] docList = service.getDocumentTypeList(); 218 if (docList != null) { 219 int length = docList.length; 220 SelectableDocumentType[] selectableDocList = new SelectableDocumentType[length]; 221 for (int j = 0; j < length; j++) { 222 DocumentType type = docList[j]; 223 String namespace = type.getNamespace(); 224 String label = type.getLabel(); 225 boolean isSelected = SelectableObjectInterface.DEFAULTSELECTIONSTATUS; 226 try { 227 SelectableDocumentType newDoc = new SelectableDocumentType( 228 namespace, label, isSelected); 229 selectableDocList[j] = newDoc; 230 } catch (Exception e) { 231 continue; 232 } 233 234 } 235 selectedService 236 .setSelectableDocumentTypeList(selectableDocList); 237 selectedService.setSelectedDocumentTypeList(selectableDocList); 238 } 239 selectedServiceVector.add(selectedService); 240 }// for 241 return selectedServiceVector; 242 }// transferServiceVectToDefaultSelectedServiceVect 243 244 /** 245 * This method will copy a ecogrid service to another one. The difference to 246 * the copy constructor is, it creates a new array for document type 247 * 248 * @param oldService 249 * EcoGridService 250 * @return EcoGridService 251 */ 252 public static SelectableEcoGridService copySelectableEcoGridService( 253 SelectableEcoGridService oldService) throws Exception { 254 255 SelectableEcoGridService newService = new SelectableEcoGridService(); 256 SelectableServiceName selectableServiceName = oldService 257 .getSelectableServiceName(); 258 String serviceName = selectableServiceName.getServiceName(); 259 boolean selected = selectableServiceName.getIsSelected(); 260 SelectableServiceName newSelectableServiceName = new SelectableServiceName(); 261 newSelectableServiceName.setServiceName(serviceName); 262 newSelectableServiceName.setIsSelected(selected); 263 newService.setSelectableServiceName(newSelectableServiceName); 264 String serviceType = oldService.getServiceType(); 265 newService.setServiceType(serviceType); 266 newService.setServiceGroup(oldService.getServiceGroup()); 267 String endpoint = oldService.getEndPoint(); 268 newService.setEndPoint(endpoint); 269 SelectableDocumentType[] oldArray = oldService 270 .getSelectableDocumentTypeList(); 271 if (oldArray != null) { 272 int length = oldArray.length; 273 SelectableDocumentType[] newArray = new SelectableDocumentType[length]; 274 for (int i = 0; i < length; i++) { 275 SelectableDocumentType oldDoc = oldArray[i]; 276 String namespace = oldDoc.getNamespace(); 277 String label = oldDoc.getLabel(); 278 boolean isSelected = oldDoc.getIsSelected(); 279 SelectableDocumentType newDoc = new SelectableDocumentType( 280 namespace, label, isSelected); 281 newArray[i] = newDoc; 282 }// for 283 newService.setSelectableDocumentTypeList(newArray); 284 }// if 285 return newService; 286 }// copyEcoGridService 287 288}// SelectedEcoGridService