1 20 package org.objectweb.modfact.jmi.xmiio.exporter; 21 22 import javax.jmi.model.ModelElement; 23 import javax.jmi.reflect.RefObject; 24 25 import org.objectweb.modfact.jmi.generator.TagGenerator; 26 import org.objectweb.modfact.jmi.logging.Level; 27 import org.objectweb.modfact.jmi.logging.ModFactLogger; 28 29 34 public abstract class XMIExport extends TagGenerator { 35 36 37 protected String _dtd; 38 39 40 protected String _model; 41 42 43 protected String _metamodel; 44 45 46 protected java.util.Hashtable _elements = new java.util.Hashtable (); 47 48 49 protected int _element_index = 1; 50 51 52 protected java.util.Hashtable _type_codes = new java.util.Hashtable (); 53 54 55 protected int _type_code_index = 1; 56 57 58 protected ModFactLogger _logger; 59 60 66 protected XMIExport(String dtd, String model, String metamodel) { 67 super(); 68 _dtd = dtd; 69 _model = model; 70 _metamodel = metamodel; 71 } 72 76 public void parseName(String name) { 77 System.err.println("parseName(" + name + ")"); 78 } 79 80 84 public void parse(Object root_package) { 85 outputln("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 86 if (_dtd.length() > 0) { 87 try { 88 java.net.URL url = new java.net.URL (_dtd); 89 outputln("<!DOCTYPE XMI SYSTEM \"" + url.toString() + "\">"); 90 } catch (java.net.MalformedURLException murle) { 91 murle.printStackTrace(); 92 } 93 } 94 outputln("<XMI verifier=\"false\" xmi.version=\"1.1\">"); 95 xmiHeaderTemplate(); 96 xmiContentTemplate(root_package); 97 outputln("</XMI>"); 98 flushFile(); 99 } 100 101 104 public void xmiHeaderTemplate() { 105 _logger.log(Level.FINE, "XMI Header generation ..."); 106 outputln("<XMI.header>"); 107 outputln("<XMI.model xmi.name=\"" + _model + "\"/>"); 108 outputln("<XMI.metamodel xmi.name=\"" + _metamodel + "\" xmi.version=\"1.3\"/>"); 109 outputln("<XMI.documentation>"); 110 outputln("<XMI.exporter>Generated by the ModFact XMI exporter</XMI.exporter>"); 111 outputln("</XMI.documentation>"); 112 outputln("</XMI.header>"); 113 } 114 115 119 public void xmiContentTemplate(Object _root_package) { 120 _logger.log(Level.FINE, "XMI Content generation ..."); 121 outputln("<XMI.content>"); 122 rootPackageTemplate(_root_package); 123 outputln("</XMI.content>"); 124 } 125 126 130 public abstract void rootPackageTemplate(Object _root_package); 131 132 136 140 protected String getXMIId(Object object) { 141 RefObject refObject = (RefObject)object; 142 String mof_id = refObject.refMofId(); 143 if (_elements.containsKey(mof_id)) 144 return (String ) _elements.get(mof_id); 145 String key = "a" + _element_index; 146 _element_index++; 147 _elements.put(mof_id, key); 148 return key; 149 } 150 151 154 public void generate() throws Exception { 155 157 } 158 159 162 public void setInput(ModelElement[] elt) throws Exception { 163 165 } 166 167 170 public void setLogger(ModFactLogger log) throws Exception { 171 _logger = log; 172 173 } 174 175 } 176 | Popular Tags |