1 26 27 package org.objectweb.openccm.Deployment; 28 29 public class ParameterConverter{ 30 31 34 private ParameterType parameterTypes[] = 35 new ParameterType[]{new ORBParameter(), 36 new IORParameter(), 37 new SimpleParameter()}; 38 41 private abstract class ParameterType { 42 43 public abstract boolean is_a(String param); 44 45 public abstract String convert(String param); 46 47 public abstract boolean implyNextConvertion(); 48 } 49 50 53 private class SimpleParameter extends ParameterType{ 54 55 public boolean is_a(String param) 56 { 57 return param!=null; 58 } 59 60 public String convert(String param) 61 { 62 return param; 63 } 64 65 public boolean 66 implyNextConvertion() 67 { 68 return false; 69 } 70 71 public String 72 toString() 73 { 74 return "SimpleType"; 75 } 76 } 77 78 79 80 class TestAuthenticator extends java.net.Authenticator { 81 82 private String username = "titi"; 83 private String password = "titi"; 84 85 public TestAuthenticator() {} 86 87 public java.net.PasswordAuthentication getPasswordAuthentication() 88 { 89 return new java.net.PasswordAuthentication (username,(password.toCharArray())); 90 } 91 } 92 93 97 private class IORParameter extends SimpleParameter { 98 99 public boolean is_a(String param) 100 { 101 return param.endsWith(".IOR")||param.endsWith(".ior"); 102 } 103 104 public String convert(String param) 105 { 106 107 String ch=param.substring(param.indexOf("=")+1); 108 try{ 109 110 java.net.URL url=new java.net.URL (ch); 112 113 115 118 119 124 java.io.InputStream in=url.openStream(); byte []b=new byte[in.available()]; 126 127 in.read(b,0,in.available()); 128 ch=param.substring(0,param.indexOf("=")+1)+(new String (b)).trim(); 129 } 131 catch(Exception e) 132 { 133 e.printStackTrace(); 134 System.err.println("Cannot read the URL contents."); 135 return param ; 136 137 } 138 return ch; 139 } 140 141 public String 142 toString() 143 { 144 return "IORType"; 145 } 146 } 147 148 152 public class ORBParameter extends SimpleParameter{ 153 154 155 public boolean is_a(String param) 156 { 157 return param.startsWith("-ORB"); 158 } 159 160 161 public boolean 162 implyNextConvertion() 163 { 164 return true; 165 } 166 167 public String 168 toString() 169 { 170 return "ORBType"; 171 } 172 } 173 174 177 private class Parameter{ 178 179 180 private String arg=null; 181 private ParameterType type; 182 private Parameter next; 183 private int index; 184 185 public Parameter(String args[],int index ){ 186 this.arg=args[index]; 187 this.index=index; 188 189 for(int i=0;i<parameterTypes.length ;i++) 190 { 191 if(parameterTypes[i].is_a(arg)){ 192 this.type=parameterTypes[i]; 193 break; 194 } 195 } 196 if(args.length-1>index) 197 next= new Parameter(args,index+1); 198 199 } 200 201 public void convert(){ 202 arg=type.convert(arg); 203 } 204 205 public java.util.LinkedList 206 processTreatment() 207 { 208 209 if(next==null){ 210 java.util.LinkedList ll= new java.util.LinkedList (); 211 ll.addFirst(arg); 212 return ll; 213 } 214 215 if(type.implyNextConvertion()) 216 next.convert(); 217 218 java.util.LinkedList ll=next.processTreatment(); 219 ll.addFirst(arg); 220 return ll; 221 } 222 223 public ParameterType 224 getParameterType() 225 { 226 return type; 227 } 228 229 } 230 231 234 public String [] 235 convertParameter(String args[]) 236 { 237 java.util.LinkedList ll=(new Parameter(args,0)).processTreatment(); 238 239 String [] ch=(String [])ll.toArray(new String [ll.size()]); 240 241 242 return ch; 243 } 244 245 252 253 } 254 | Popular Tags |