1 19 20 package org.netbeans.modules.mdrxml; 21 22 import java.util.*; 23 24 import javax.jmi.reflect.RefPackage; 25 import javax.jmi.model.*; 26 27 import org.openide.TopManager; 28 import org.openide.util.*; 29 import org.openide.modules.ModuleInstall; 30 import org.netbeans.api.mdr.*; 31 import xmlmodel.*; 32 33 public class MDRXMLModule extends ModuleInstall { 34 35 public static final String XML_METAMODEL = "org.netbeans.mof"; 37 public static final String XML_MODEL = "org.netbeans.xmlmodel"; 39 public static final String XML_PACKAGE = "XMLModel"; 41 42 44 public void installed () { 45 restored(); 46 } 47 48 50 public void restored () { 51 RequestProcessor.postRequest( 52 new Runnable () { 53 public void run() { 54 TopManager.getDefault().setStatusText("Restoring metamodel of XML..."); 55 installXML(); 56 TopManager.getDefault().setStatusText(""); 57 } 58 } 59 ); 60 } 61 62 64 public void uninstalled () { 65 } 66 67 70 public boolean closing () { 71 return true; } 73 74 76 public static void installXML() { 77 MDRepository repository = MDRManager.getDefault().getDefaultRepository(); 79 80 82 if (repository.getExtent(XML_MODEL) != null) 84 return; 85 86 ModelPackage xmlMMExtent = (ModelPackage) repository.getExtent(XML_METAMODEL); 88 89 try { 90 if (xmlMMExtent == null) { 91 xmlMMExtent = (ModelPackage) repository.createExtent(XML_METAMODEL); 93 } 94 95 MofPackage xmlMMPackage = findXMLPackage(xmlMMExtent); 97 98 if (xmlMMPackage == null) { 100 XMIReader xmiReader = XMIReader.getDefault(); 102 xmiReader.read(XmlmodelPackage.class.getResource("resources/xmlmodel.xml").toString (), new RefPackage[] {xmlMMExtent}); 103 xmlMMPackage = findXMLPackage(xmlMMExtent); 105 } 106 107 repository.createExtent(XML_MODEL, xmlMMPackage); 109 } catch (CreationFailedException mer) { 110 TopManager.getDefault().getErrorManager().notify (mer); 111 mer.printStackTrace(); 112 } catch (java.io.IOException ioex) { 113 TopManager.getDefault().getErrorManager().notify (ioex); 114 } catch(Exception saex) { 115 TopManager.getDefault().getErrorManager().notify (saex); 116 } 117 } 118 119 private static MofPackage findXMLPackage(ModelPackage extent) { 120 for (Iterator it = extent.getMofPackage().refAllOfClass().iterator(); it.hasNext();) { 121 ModelElement temp = (ModelElement) it.next(); 122 if (temp.getName().equals(XML_PACKAGE)) { 123 return (MofPackage) temp; 124 } 125 } 126 127 return null; 128 } 129 } 130 | Popular Tags |