001: /* Copyright (C) 2003 Finalist IT Group
002: *
003: * This file is part of JAG - the Java J2EE Application Generator
004: *
005: * JAG is free software; you can redistribute it and/or modify
006: * it under the terms of the GNU General Public License as published by
007: * the Free Software Foundation; either version 2 of the License, or
008: * (at your option) any later version.
009: * JAG is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: * You should have received a copy of the GNU General Public License
014: * along with JAG; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
016: */
017:
018: package com.finalist.jaggenerator.modules;
019:
020: import com.finalist.jaggenerator.modules.JagBean;
021:
022: import java.util.*;
023: import javax.swing.*;
024: import javax.swing.tree.*;
025: import javax.xml.parsers.*;
026:
027: import org.w3c.dom.*;
028:
029: /**
030: *
031: * @author hillie
032: */
033: public class Root extends DefaultMutableTreeNode implements JagBean {
034: /** Creates new form BeanForm */
035:
036: public Config config = null;
037: public App app = null;
038: public Paths paths = null;
039: public Datasource datasource = null;
040:
041: public Root() {
042: initComponents();
043: add(config = new Config());
044: add(app = new App());
045: add(paths = new Paths());
046: add(datasource = new Datasource());
047: }
048:
049: public Root(Document doc) {
050: NodeList nl = doc.getElementsByTagName("config");
051: add(config = new Config((Element) nl.item(0)));
052: nl = doc.getElementsByTagName("module");
053: for (int i = 0; i < nl.getLength(); i++) {
054: Element el = (Element) nl.item(i);
055: String name = el.getAttribute("name");
056: if (name.equals("app")) {
057: app = new App(el);
058: add(app);
059: this .setRootPackage(app.getRootPackage());
060: }
061: if (name.equals("paths"))
062: add(paths = new Paths(el));
063: if (name.equals("datasource"))
064: add(datasource = new Datasource(el));
065: if (name.equals("session"))
066: add(new Session(el));
067: if (name.equals("entity"))
068: add(new Entity(el));
069: }
070: }
071:
072: /** This method is called from within the constructor to
073: * initialize the form.
074: * WARNING: Do NOT modify this code. The content of this method is
075: * always regenerated by the Form Editor.
076: */
077: private void initComponents() {//GEN-BEGIN:initComponents
078: panel = new javax.swing.JPanel();
079:
080: panel.setLayout(null);
081:
082: }//GEN-END:initComponents
083:
084: public String toString() {
085: return "JAG Application";
086: }
087:
088: public JPanel getPanel() {
089: return new JPanel();
090: }
091:
092: public void getXML(Element el) throws ParserConfigurationException {
093: Enumeration children = children();
094: while (children.hasMoreElements()) {
095: JagBean child = (JagBean) children.nextElement();
096: child.getXML(el);
097: }
098: }
099:
100: /** Getter for property rootPackage.
101: * @return Value of property rootPackage.
102: *
103: */
104: public String getRootPackage() {
105: return app.getRootPackage();
106: }
107:
108: /** Setter for property rootPackage.
109: * @param rootPackage New value of property rootPackage.
110: *
111: */
112: public void setRootPackage(String rootPackage) {
113:
114: app.rootPackageText.setText(rootPackage);
115: }
116:
117: public String getRefName() {
118: return null;
119: }
120:
121: /** return all Session EJBs. */
122: public ArrayList getSessionEjbs() {
123: ArrayList refs = new ArrayList();
124: for (int i = 0; i < getChildCount(); i++) {
125: JagBean child = (JagBean) getChildAt(i);
126: if (child instanceof Session) {
127: refs.add(child);
128: }
129: }
130: return refs;
131: }
132:
133: /** return all Session EJBs. */
134: public void setSessionEjbs(ArrayList sessions) {
135: for (int i = 0; i < sessions.size(); i++) {
136: Session child = (Session) sessions.get(i);
137: add(child);
138: }
139: }
140:
141: /** return all Entity EJBs. */
142: public ArrayList getEntityEjbs() {
143: ArrayList refs = new ArrayList();
144: for (int i = 0; i < getChildCount(); i++) {
145: JagBean child = (JagBean) getChildAt(i);
146: if (child instanceof Entity) {
147: refs.add(child);
148: }
149: }
150: return refs;
151: }
152:
153: /** return all Session EJBs. */
154: public void setEntityEjbs(ArrayList entities) {
155: for (int i = 0; i < entities.size(); i++) {
156: Entity child = (Entity) entities.get(i);
157: add(child);
158: }
159: }
160:
161: public ArrayList getRefs() {
162: ArrayList refs = new ArrayList();
163: for (int i = 0; i < getChildCount(); i++) {
164: JagBean child = (JagBean) getChildAt(i);
165:
166: if (child instanceof Entity) {
167: String childRef = child.getRefName();
168:
169: if (childRef != null) {
170: // if (child.toString().indexOf("Entity -") != -1)
171: refs.add(childRef);
172: }
173: }
174: }
175: return refs;
176: }
177:
178: // Variables declaration - do not modify//GEN-BEGIN:variables
179: private javax.swing.JPanel panel;
180: // End of variables declaration//GEN-END:variables
181:
182: }
|