View Javadoc

1   /*   Copyright (C) 2003 Finalist IT Group
2    *
3    *   This file is part of JAG - the Java J2EE Application Generator
4    *
5    *   JAG is free software; you can redistribute it and/or modify
6    *   it under the terms of the GNU General Public License as published by
7    *   the Free Software Foundation; either version 2 of the License, or
8    *   (at your option) any later version.
9    *   JAG is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *   You should have received a copy of the GNU General Public License
14   *   along with JAG; if not, write to the Free Software
15   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   */
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  /***
30   *
31   * @author  hillie
32   */
33  public class Root extends DefaultMutableTreeNode implements JagBean {
34     /*** Creates new form BeanForm */
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     /*** This method is called from within the constructor to
72      * initialize the form.
73      * WARNING: Do NOT modify this code. The content of this method is
74      * always regenerated by the Form Editor.
75      */
76      private void initComponents() {//GEN-BEGIN:initComponents
77          panel = new javax.swing.JPanel();
78  
79          panel.setLayout(null);
80  
81      }//GEN-END:initComponents
82  
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    /*** Getter for property rootPackage.
104     * @return Value of property rootPackage.
105     *
106     */
107    public String getRootPackage() {
108       return app.getRootPackage();
109    }
110 
111 
112    /*** Setter for property rootPackage.
113     * @param rootPackage New value of property rootPackage.
114     *
115     */
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    /*** return all Session EJBs. */
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    /*** return all Session EJBs. */
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    /*** return all Entity EJBs. */
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    /*** return all Session EJBs. */
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           //      if (child.toString().indexOf("Entity -") != -1)
179                   refs.add(childRef);
180             }
181          }
182       }
183       return refs;
184    }
185 
186 
187     // Variables declaration - do not modify//GEN-BEGIN:variables
188     private javax.swing.JPanel panel;
189     // End of variables declaration//GEN-END:variables
190 
191 }