1 18 19 package org.objectweb.jac.core; 20 21 import java.io.*; 22 import java.util.*; 23 import org.apache.log4j.Logger; 24 import org.objectweb.jac.util.*; 25 26 54 55 public class Application implements Serializable { 56 static Logger logger = Logger.getLogger("application"); 57 58 String name; 59 String path; 60 String constructorClass; 61 String [] arguments; 62 Vector acConfigurations = 63 new Vector(); 64 Hashtable acs = new Hashtable(); 65 boolean instantiated = false; 66 67 Properties props = new Properties(); 68 69 78 79 public Application(String name, String path, 80 String constructorClass, String [] arguments) { 81 this.name = name; 82 if (path==null) { 83 path = System.getProperty("user.dir"); 84 } 85 this.path = path; 86 this.constructorClass = constructorClass; 87 this.arguments = arguments; 88 Collaboration.get().setCurApp(name); 90 } 91 92 95 96 public void init() { 97 Iterator it = acConfigurations.iterator(); 98 while( it.hasNext() ) { 99 ACConfiguration acConf = (ACConfiguration) it.next(); 100 if ( ! acConf.getWeaveOnDemand() ) { 101 ApplicationRepository.get().extend(name,acConf.getName()); 103 } 104 } 105 } 106 107 108 112 113 public String getName() { 114 return name; 115 } 116 117 121 122 public void setName(String name) { 123 this.name = name; 124 } 125 126 131 132 public String getPath() { 133 return path; 134 } 135 136 141 142 public void setPath(String path) { 143 this.path = path; 144 } 145 146 151 152 public String getConstructorClass() { 153 return constructorClass; 154 } 155 156 161 162 public void setConstructorClass(String constructorClass) { 163 this.constructorClass = constructorClass; 164 } 165 166 172 173 public boolean realizes(String acName) { 174 return false; } 176 177 183 184 public boolean configures(String acName) { 185 return false; } 187 188 192 193 public void addAcConfiguration(ACConfiguration configuration) { 194 acConfigurations.add(configuration); 195 } 196 197 201 202 public void removeAcConfiguration(ACConfiguration configuration) { 203 acConfigurations.remove(configuration.getName()); 204 } 205 206 210 211 public Collection getAcConfigurations() { 212 return (org.objectweb.jac.lib.java.util.Vector)acConfigurations.clone(); 213 } 214 215 221 222 public ACConfiguration getAcConfiguration(String name) { 223 Iterator i = acConfigurations.iterator(); 224 while(i.hasNext()) { 225 ACConfiguration conf = (ACConfiguration)i.next(); 226 if (conf.getName().equals(name)) 227 return conf; 228 } 229 return null; 230 } 231 232 239 240 public void start() { 241 if (instantiated) { 242 logger.warn("application '" + name + "' is already instantiated"); 243 return; 244 } 245 try { 246 logger.info("launching application "+this); 247 Class.forName(constructorClass) 248 .getMethod( "main", new Class [] { String [].class } ) 249 .invoke( null, new Object [] { arguments } ); 250 instantiated = true; 251 Iterator it = acConfigurations.iterator(); 252 while( it.hasNext() ) { 253 ACConfiguration conf = (ACConfiguration) it.next(); 254 if( ! conf.weaveOnDemand ) { 255 conf.weave(); 256 } 257 } 258 259 } catch(Exception e) { 260 logger.error("application '" + name + "' unable to start",e); 261 } 262 } 263 264 265 268 269 public String toString() { 270 return "Application " + name; 271 } 272 273 } 274 | Popular Tags |