1 28 29 package org.objectweb.openccm.uml.lib; 30 31 import org.objectweb.util.cmdline.lib.DefaultCommandLine; 32 33 40 41 public class XMI2IR 42 extends org.objectweb.openccm.command.lib.CompilerBase 43 implements org.objectweb.openccm.uml.api.XMI2IR 44 { 45 51 52 private final String checkCommand = "import CIDLChecker; checker = CIDLChecker.CIDLChecker(); checker.checkModel();"; 53 54 55 private final String createCommand = "import CIDLFeeder; feeder = CIDLFeeder.CIDLFeeder(); feeder.createModel();"; 56 57 63 64 fr.lifl.cim.jidlscript.JISInterpreter jis; 65 66 67 org.omg.uml.xmi.UmlXMIImport xmiImport; 68 69 75 76 public 77 XMI2IR() 78 { 79 super(new DefaultCommandLine("xmi2ir", 81 "xmi_uml_document", 82 "Feed the OpenCCM Interface Repository with an XMI 1.1 UML 1.4 document", 83 true), 84 false); 85 } 86 87 93 98 private boolean 99 initJIS() 100 { 101 org.omg.CORBA.ORB orb = org.objectweb.openccm.corba.TheORB.getORB(); 102 try { 103 jis = new fr.lifl.cim.jidlscript.JISInterpreter(orb); 105 String csDirectory = System.getProperty("transformation.cs.dir"); 106 java.net.URL urlDirectory = Thread.currentThread().getContextClassLoader().getResource(csDirectory); 107 fr.lifl.cim.jidlscript.lang.JISModuleLoader.loader.addURL(urlDirectory.toString()); 108 return true; 109 } catch (fr.lifl.cim.jidlscript.lang.JISError jisError) { 110 getConsole().error("Error in Java IDL Script Interpreter initialization: " + jisError.getMessage()); 111 return false; 112 } 113 } 114 115 121 127 134 public int 135 run(java.lang.String [] args) 136 { 137 if(!initAST() || !initJIS() || !initUMLRepository()) 140 return -1; 141 142 try { 143 parseXMIFile(args[0]); 144 } catch (java.lang.Exception exception) { 145 getConsole().error("[ERROR] An error occurs during the reading of the UML model (" + exception.getMessage() + ")."); 146 return -1; 147 } 148 149 try { 150 151 org.omg.CORBA.ComponentIR.Repository ir = org.objectweb.openccm.corba.TheInterfaceRepository.getRepository(); 152 153 getConsole().message("Checking if the UML model is correct..."); 155 jis.eval(checkCommand); 156 getConsole().message("The UML model is correct."); 157 158 getConsole().message("Feeding the UML model into the OpenCCM Interface Repository..."); 160 jis.eval(createCommand); 161 getConsole().message("The UML model is fed into the OpenCCM Interface Repository."); 162 } catch (fr.lifl.cim.jidlscript.lang.JISError e) { 163 if (((fr.lifl.cim.jidlscript.lang.JISException)e.exception).getType().Name().equals("Throw")) { 164 String message = ((fr.lifl.cim.jidlscript.lang.JISThrow)e.exception).eval().toString(); 165 if (message.indexOf("java.lang.NullPointerException") != -1) { 166 getConsole().error("[ERROR] There is a blank field in the UML model (e.g. name, visibility, multiplicity, etc.)."); 167 } else { 168 java.util.StringTokenizer token = new java.util.StringTokenizer (message, "\n"); 170 while (token.hasMoreTokens()) { 171 getConsole().error("[ERROR] " + token.nextToken()); 172 } 173 } 174 } else { 175 getConsole().error("[ERROR] An error occurs during the importation of the UML model. Check if your XMI file is correct (" + e.exception + ")."); 176 } 177 return -1; 178 } 179 180 return 0; 182 } 183 184 190 196 202 208 213 public boolean 214 initUMLRepository() 215 { 216 try { 217 org.omg.uml.UmlPackage pck = null; 218 String metaModelFile = System.getProperty("uml.metamodel.file"); 219 pck = org.objectweb.modfact.jmi.repository.uml.UmlPackageImpl.create(metaModelFile); 220 xmiImport = new org.omg.uml.xmi.UmlXMIImport(); 221 xmiImport.initiate(pck); 222 return true; 223 } catch (java.lang.Exception exception) { 224 getConsole().error("[ERROR] An error occurs during the initialization of the UML repository. Check your environment."); 225 exception.printStackTrace(); 226 return false; 227 } 228 } 229 230 240 public void 241 parseXMIFile(String filename) 242 throws 243 org.xml.sax.SAXException , 244 javax.xml.parsers.ParserConfigurationException , 245 java.io.IOException 246 { 247 getConsole().message("Reading from " + filename + "..."); 248 Object o = xmiImport.parse(filename); 249 org.omg.uml.UmlPackage uml_package = (org.omg.uml.UmlPackage) o; 250 TheUMLPackage.setUMLPackage(uml_package); 251 } 252 253 259 264 public static void 265 main(String [] args) 266 { 267 XMI2IR xmi2ir = new XMI2IR(); 268 xmi2ir.runMain(args); 269 } 270 271 } 272 | Popular Tags |