| 1 17 18 package com.finalist.jaggenerator.modules; 19 20 import com.finalist.jaggenerator.modules.JagBean; 21 22 import java.util.*; 23 import javax.swing.*; 24 import javax.swing.tree.*; 25 import javax.xml.parsers.*; 26 27 import org.w3c.dom.*; 28 29 33 public class Root extends DefaultMutableTreeNode implements JagBean { 34 35 36 public Config config = null; 37 public App app = null; 38 public Paths paths = null; 39 public Datasource datasource = null; 40 41 42 public Root() { 43 initComponents(); 44 add(config = new Config()); 45 add(app = new App()); 46 add(paths = new Paths()); 47 add(datasource = new Datasource()); 48 } 49 50 51 public Root(Document doc) { 52 NodeList nl = doc.getElementsByTagName("config"); 53 add(config = new Config((Element) nl.item(0))); 54 nl = doc.getElementsByTagName("module"); 55 for (int i = 0; i < nl.getLength(); i++) { 56 Element el = (Element) nl.item(i); 57 String name = el.getAttribute("name"); 58 if (name.equals("app")) { 59 app = new App(el); 60 add(app); 61 this.setRootPackage(app.getRootPackage()); 62 } 63 if (name.equals("paths")) add(paths = new Paths(el)); 64 if (name.equals("datasource")) add(datasource = new Datasource(el)); 65 if (name.equals("session")) add(new Session(el)); 66 if (name.equals("entity")) add(new Entity(el)); 67 } 68 } 69 70 71 76 private void initComponents() { panel = new javax.swing.JPanel (); 78 79 panel.setLayout(null); 80 81 } 83 84 public String toString() { 85 return "JAG Application"; 86 } 87 88 89 public JPanel getPanel() { 90 return new JPanel(); 91 } 92 93 94 public void getXML(Element el) throws ParserConfigurationException { 95 Enumeration children = children(); 96 while (children.hasMoreElements()) { 97 JagBean child = (JagBean) children.nextElement(); 98 child.getXML(el); 99 } 100 } 101 102 103 107 public String getRootPackage() { 108 return app.getRootPackage(); 109 } 110 111 112 116 public void setRootPackage(String rootPackage) { 117 118 app.rootPackageText.setText(rootPackage); 119 } 120 121 122 public String getRefName() { 123 return null; 124 } 125 126 127 public ArrayList getSessionEjbs() { 128 ArrayList refs = new ArrayList(); 129 for (int i = 0; i < getChildCount(); i++) { 130 JagBean child = (JagBean) getChildAt(i); 131 if (child instanceof Session) { 132 refs.add(child); 133 } 134 } 135 return refs; 136 } 137 138 139 public void setSessionEjbs(ArrayList sessions) { 140 for (int i = 0; i < sessions.size(); i++) { 141 Session child = (Session) sessions.get(i); 142 add(child); 143 } 144 } 145 146 147 148 149 public ArrayList getEntityEjbs() { 150 ArrayList refs = new ArrayList(); 151 for (int i = 0; i < getChildCount(); i++) { 152 JagBean child = (JagBean) getChildAt(i); 153 if (child instanceof Entity) { 154 refs.add(child); 155 } 156 } 157 return refs; 158 } 159 160 161 public void setEntityEjbs(ArrayList entities) { 162 for (int i = 0; i < entities.size(); i++) { 163 Entity child = (Entity) entities.get(i); 164 add(child); 165 } 166 } 167 168 169 public ArrayList getRefs() { 170 ArrayList refs = new ArrayList(); 171 for (int i = 0; i < getChildCount(); i++) { 172 JagBean child = (JagBean) getChildAt(i); 173 174 if (child instanceof Entity) { 175 String childRef = child.getRefName(); 176 177 if (childRef != null) { 178 refs.add(childRef); 180 } 181 } 182 } 183 return refs; 184 } 185 186 187 private javax.swing.JPanel panel; 189 191 } | Popular Tags |