1 28 29 package com.idaremedia.antx; 30 31 import org.apache.tools.ant.Project; 32 33 import com.idaremedia.antx.helpers.Tk; 34 import com.idaremedia.antx.parameters.EnumSkeleton; 35 36 49 50 public final class ExportScope extends EnumSkeleton 51 { 52 53 public final int ALL_INDEX = 0; 54 55 public final int THREAD_INDEX = ALL_INDEX+1; 56 57 public final int PROJECT_INDEX = THREAD_INDEX+1; 58 59 60 63 public static final ExportScope THREAD = new ExportScope("thread"); 64 65 68 public static final ExportScope PROJECT = new ExportScope("project"); 69 70 73 public static final ExportScope ALL = new ExportScope("all"); 74 75 76 77 80 public ExportScope() 81 { 82 super(); 83 } 84 85 86 89 private ExportScope(String v) 90 { 91 super(v); 92 } 93 94 95 99 public String [] getValues() 100 { 101 return new String []{"all","thread","project"}; 102 } 103 104 105 106 110 public static final ExportScope DEFAULT_SCOPE= ExportScope.THREAD; 111 112 113 114 123 public static void setTheProperty(ExportScope S, Project P, 124 String name, String value, 125 boolean erase) 126 { 127 if (S==null) { 128 S= ExportScope.DEFAULT_SCOPE; 129 } 130 if (erase) { 131 erase = value.length()==0; } 133 if (ExportScope.THREAD.equals(S)) { 134 if (erase) { 135 ExportedProperties.delete(name); 136 } else { 137 ExportedProperties.set(name,value); 138 } 139 } 140 else { 141 if (P==null) { 142 throw new IllegalArgumentException 143 ("Export.setTheProperty- nonNULL project required"); 144 } 145 if (ExportScope.PROJECT.equals(S)) { 146 P.addReference(name,value); 147 } 148 else { 149 P.setInheritedProperty(name,value); 150 } 151 } 152 } 153 154 155 164 public static String getTheProperty(ExportScope S, Project P, String name) 165 { 166 if (S==null) { 167 S= ExportScope.DEFAULT_SCOPE; 168 } 169 if (ExportScope.THREAD.equals(S)) { 170 return ExportedProperties.readstring(name); 171 } 172 if (P==null) { 173 throw new IllegalArgumentException 174 ("Export.getTheProperty- nonNULL project required"); 175 } 176 if (ExportScope.PROJECT.equals(S)) { 177 return Stringifier.get(false).stringFrom(P.getReference(name),P); 178 } 179 return P.getProperty(name); 180 } 181 182 183 184 185 191 public static ExportScope from(int i) 192 { 193 if (i==ALL.index) { return ALL; } 194 if (i==PROJECT.index) { return PROJECT; } 195 if (i==THREAD.index) { return THREAD; } 196 return null; 197 } 198 199 200 201 208 public static ExportScope from(int i, ExportScope dflt) 209 { 210 ExportScope xs= from(i); 211 return (xs==null) ? dflt : xs; 212 } 213 214 215 216 222 public static ExportScope from(String s) 223 { 224 if (s!=null && s.length()>1) { 225 s = Tk.lowercaseFrom(s); 226 if (Character.isDigit(s.charAt(0))) { 227 try { return from(Integer.parseInt(s)); } 228 catch(Exception nfx) {} 229 } else { 230 if ("default".equals(s)) { return DEFAULT_SCOPE; } 231 if (PROJECT.value.equals(s)) { return PROJECT; } 232 if (THREAD.value.equals(s)) { return THREAD; } 233 if (ALL.value.equals(s)) { return ALL;} 234 if ("system".equals(s)) { return ALL;} 235 } 236 } 237 return null; 238 } 239 240 241 249 public static ExportScope from(String s, ExportScope dflt) 250 { 251 ExportScope xs= from(s); 252 return (xs==null) ? dflt : xs; 253 } 254 } 255 256 257 | Popular Tags |