1 28 29 package org.objectweb.util.launcher.parser ; 30 31 32 import java.util.Iterator ; 33 34 import java.net.URL ; 35 36 import org.objectweb.util.launcher.LauncherException ; 37 import org.objectweb.util.trace.TraceSystem; 38 39 40 50 public class ParserZeus 51 implements Parser 52 { 53 54 protected java.util.ArrayList parsed_files_ ; 55 56 59 public ParserZeus() { 60 parsed_files_ = new java.util.ArrayList (); 61 } 62 63 71 protected String replaceTag(String tagged) { 72 StringBuffer result = new StringBuffer (); 73 int start = 0; 74 int end = tagged.indexOf(RepositoryZeus.separator); 75 while(end != -1) { 76 result.append(tagged.substring(start,end)); 77 start=end+1; 78 end= tagged.indexOf(RepositoryZeus.separator,start); 79 if (end != -1) { 80 String tag = tagged.substring(start,end); 81 String value = System.getProperty(tag); 82 if (value == null) 83 result.append("@"+tag+"@"); 84 else { 85 TraceSystem.get("repository").debug("Replacing tag @"+tag+"@ with value "+value); 86 result.append(value); 87 } 88 } 89 start = end+1; 90 end = tagged.indexOf(RepositoryZeus.separator,start); 91 } 92 result.append(tagged.substring(start)); 93 return result.toString(); 94 } 95 96 101 protected Launcher readFile(String url) { 102 try { 103 return readFile(new java.net.URL (replaceTag(url))); 104 } catch (Exception ex) { 105 TraceSystem.get("decoder").error("Exception raised: "+ex); 106 throw new LauncherException(ex); 107 } 108 } 109 110 115 protected Launcher readFile(URL url) { 116 TraceSystem.get("parser").info("Reading "+url+" ..."); 117 try { 118 return LauncherUnmarshaller.unmarshal(url.openStream()) ; 119 } catch (java.io.IOException e) { 120 TraceSystem.get("decoder").error("[I/O Error] : "+e); 121 throw new LauncherException(e); 122 } 123 } 124 125 126 132 protected RepositoryZeus parseFile(Launcher config) { 133 RepositoryZeus repository = new RepositoryZeus(); 134 parseFile(repository,config); 135 return repository; 136 } 137 138 144 protected void parseFile(RepositoryZeus repository, Launcher config) { 145 TraceSystem.get("parser").info("Zeus Parsing for "+config+" ..."); 146 if (config.getIncludeList()!=null) { 147 for(Iterator i = config.getIncludeList().iterator() ; i.hasNext() ;) { 148 Include incl = (Include)i.next(); 149 if ( !parsed_files_.contains(incl.getUrl()) ) { 150 parsed_files_.add(incl.getUrl()); 151 parseFile(repository,readFile(incl.getUrl())); 152 } 153 } 154 } 155 156 if (config.getClasspathList()!=null) { 157 for(Iterator i = config.getClasspathList().iterator() ; i.hasNext() ; ) { 158 Classpath c = (Classpath)i.next(); 159 TraceSystem.get("parser").debug("Adding classpath "+c.getId()+" ..."); 160 repository.addClasspath(c.getId(),c); 161 } 162 } 163 164 if (config.getArgumentsList()!=null) { 165 for(Iterator i = config.getArgumentsList().iterator() ; i.hasNext() ; ) { 166 Arguments a = (Arguments)i.next(); 167 TraceSystem.get("parser").debug("Adding argument "+a.getId()+" ..."); 168 repository.addArgument(a.getId(),a); 169 } 170 } 171 172 if (config.getPropertiesList()!=null) { 173 for(Iterator i = config.getPropertiesList().iterator() ; i.hasNext() ; ) { 174 Properties p = (Properties)i.next(); 175 TraceSystem.get("parser").debug("Adding property "+p.getId()+" ..."); 176 repository.addProperty(p.getId(),p); 177 } 178 } 179 180 if (config.getRunList()!=null) { 181 for(Iterator i = config.getRunList().iterator() ; i.hasNext() ; ) { 182 Run r = (Run)i.next(); 183 TraceSystem.get("parser").debug("Adding run "+r.getId()+" ..."); 184 repository.addRun(r.getId(), r); 185 } 186 } 187 188 if (config.getContextList()!=null) { 189 for(Iterator i = config.getContextList().iterator() ; i.hasNext() ; ) { 190 Context c = (Context)i.next(); 191 TraceSystem.get("parser").debug("Adding context "+c.getId()); 192 repository.addContext(c.getId(), c); 193 } 194 } 195 } 196 197 198 203 public Repository load(String url) { 204 return parseFile(readFile(url)); 205 } 206 } 207 | Popular Tags |