1 19 package org.enhydra.zeus.transform; 20 21 import org.enhydra.zeus.InvalidCollectionTypeException; 22 import org.enhydra.zeus.util.ClassUtils; 23 24 34 public class TransformerOptions { 35 36 37 protected String defaultPackage; 38 39 40 protected String interfacePackage; 41 42 43 protected String implementationPackage; 44 45 46 protected int defaultCollectionType; 47 48 53 public TransformerOptions() { 54 this("", ClassUtils.COLLECTION_TYPE_LIST); 55 } 56 57 66 public TransformerOptions(String defaultPackage, 67 int defaultCollectionType) { 68 this.defaultPackage = defaultPackage; 69 interfacePackage = null; 70 implementationPackage = null; 71 try { 72 setDefaultCollectionType(defaultCollectionType); 73 } catch (InvalidCollectionTypeException e) { 74 try { 75 setDefaultCollectionType(ClassUtils.COLLECTION_TYPE_LIST); 76 } catch (InvalidCollectionTypeException neverHappens) { } 77 } 78 } 79 80 91 public TransformerOptions(String interfacePackage, 92 String implementationPackage, 93 int defaultCollectionType) { 94 defaultPackage = ""; 95 interfacePackage = interfacePackage; 96 implementationPackage = implementationPackage; 97 try { 98 setDefaultCollectionType(defaultCollectionType); 99 } catch (InvalidCollectionTypeException e) { 100 try { 101 setDefaultCollectionType(ClassUtils.COLLECTION_TYPE_LIST); 102 } catch (InvalidCollectionTypeException neverHappens) { } 103 } 104 } 105 106 123 public void setDefaultPackage(String defaultPackage) { 124 if (defaultPackage == null) { 125 throw new IllegalArgumentException ("A TransformerOptions cannot " + 126 "have a null value for the default package. To use the " + 127 "default package, specify an empty String (\"\")."); 128 } 129 130 this.defaultPackage = defaultPackage; 131 } 132 133 141 public void setInterfacePackage(String interfacePackage) { 142 if (interfacePackage == null) { 143 throw new IllegalArgumentException ("A TransformerOptions cannot " + 144 "have a null value for the interface package. To use the " + 145 "default package, specify an empty String (\"\")."); 146 } 147 this.interfacePackage = interfacePackage; 148 } 149 150 158 public String getInterfacePackage() { 159 if (interfacePackage != null) { 160 return interfacePackage; 161 } else { 162 return defaultPackage; 163 } 164 } 165 166 174 public void setImplementationPackage(String implementationPackage) { 175 if (implementationPackage == null) { 176 throw new IllegalArgumentException ("A TransformerOptions cannot " + 177 "have a null value for the implementation package. To use " + 178 "the default package, specify an empty String (\"\")."); 179 } 180 this.implementationPackage = implementationPackage; 181 } 182 183 191 public String getImplementationPackage() { 192 if (implementationPackage != null) { 193 return implementationPackage; 194 } else { 195 return defaultPackage; 196 } 197 } 198 199 214 public void setDefaultCollectionType(int defaultCollectionType) 215 throws InvalidCollectionTypeException { 216 217 if (!ClassUtils.isCollectionConstant(defaultCollectionType)) { 219 throw new InvalidCollectionTypeException(); 220 } 221 222 this.defaultCollectionType = defaultCollectionType; 224 } 225 226 239 public void setDefaultCollectionType(String defaultCollectionTypeString) 240 throws InvalidCollectionTypeException { 241 242 this.defaultCollectionType = 244 ClassUtils.getCollectionTypeAsInt(defaultCollectionTypeString); 245 } 246 247 256 public String getDefaultCollectionType() { 257 return ClassUtils.getCollectionTypeAsString(defaultCollectionType); 258 } 259 } 260 | Popular Tags |