1 package org.objectweb.modfact.qvt.service; 2 3 import java.io.*; 4 import java.util.*; 5 import javax.jmi.reflect.*; 6 import javax.jmi.xmi.*; 7 import org.objectweb.modfact.jmi.reflect.RefPackageImpl; 8 import org.objectweb.modfact.jmi.xmi.*; 9 10 public class ModelImpl implements Model { 11 12 static XmiReader reader = new XmiReaderImpl(); 13 static XmiWriter writer = new XmiWriterImpl(); 14 15 RefPackage model; 16 RefPackage metaModel; 17 18 String modelURL; 19 String metaModelURL; 20 21 public ModelImpl(String metaModelURL) throws Exception { 22 this.metaModelURL = metaModelURL; 23 metaModel = RefPackageImpl.getM2Repository(); 24 reader.read(metaModelURL, metaModel); 25 model = RefPackageImpl.getM1Repository( 26 findMofPackage() 27 ); 28 } 29 30 public ModelImpl( String metaModelURL, String modelURL) throws Exception { 31 this(metaModelURL); 32 reader.read(modelURL, model); 33 } 34 35 public ModelImpl( InputStream metaModelStream) throws Exception { 36 metaModel = RefPackageImpl.getM2Repository(); 37 reader.read(metaModelStream, "", metaModel); 38 model = RefPackageImpl.getM1Repository( 39 findMofPackage() 40 ); 41 } 42 43 public ModelImpl( InputStream metaModelStream, InputStream modelStream) throws Exception { 44 this(metaModelStream); 45 reader.read(modelStream, "", model); 46 } 47 48 public RefPackage getModel() { 49 return model; 50 } 51 52 public String getMetaModelURL() { 53 return metaModelURL; 54 } 55 56 public String getModelURL() { 57 return modelURL; 58 } 59 60 public void writeModelTo(java.io.OutputStream out) throws Exception { 61 writer.write(out, model, "1.2"); 62 } 63 64 RefObject findMofPackage() { 65 Iterator it = metaModel.refClass("Package").refAllOfClass().iterator(); 66 return (RefObject) ((RefObject)it.next()).refOutermostComposite(); 67 } 68 69 } 70 | Popular Tags |