KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > qvt > service > ModelImpl


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 JavaDoc modelURL;
19   String JavaDoc metaModelURL;
20     
21   public ModelImpl(String JavaDoc metaModelURL) throws Exception JavaDoc {
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 JavaDoc metaModelURL, String JavaDoc modelURL) throws Exception JavaDoc {
31     this(metaModelURL);
32     reader.read(modelURL, model);
33   }
34    
35   public ModelImpl( InputStream metaModelStream) throws Exception JavaDoc {
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 JavaDoc {
44     this(metaModelStream);
45     reader.read(modelStream, "", model);
46   }
47   
48   public RefPackage getModel() {
49       return model;
50   }
51     
52   public String JavaDoc getMetaModelURL() {
53       return metaModelURL;
54   }
55     
56   public String JavaDoc getModelURL() {
57       return modelURL;
58   }
59     
60   public void writeModelTo(java.io.OutputStream JavaDoc out) throws Exception JavaDoc {
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