KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jbuilder > node > PrimeNode


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22 package org.enhydra.kelp.jbuilder.node;
23
24 // ToolBox imports
25
import org.enhydra.tool.common.PathHandle;
26
27 // JBuilder imports
28
import com.borland.jbuilder.node.JBProject;
29 import com.borland.primetime.node.FileNode;
30 import com.borland.primetime.node.Node;
31 import com.borland.primetime.vfs.Url;
32
33 // Kelp imports
34
import org.enhydra.kelp.common.Constants;
35 import org.enhydra.kelp.common.PathUtil;
36 import org.enhydra.kelp.common.PropUtil;
37 import org.enhydra.kelp.common.node.PropertyKeys;
38 import org.enhydra.kelp.common.node.OtterNode;
39 import org.enhydra.kelp.common.node.OtterFileNode;
40 import org.enhydra.kelp.common.node.OtterProject;
41
42 // Standard imports
43
import java.io.File JavaDoc;
44 import javax.swing.SwingUtilities JavaDoc;
45
46 /**
47  * Class declaration
48  *
49  *
50  * @author Paul Mahar
51  */

52 public class PrimeNode implements OtterFileNode {
53     private Node nativeNode = null;
54     private Throwable JavaDoc exception = null;
55
56     /**
57      * Constructor declaration
58      *
59      */

60     public PrimeNode() {}
61
62     /**
63      * Constructor declaration
64      *
65      * @param node
66      */

67     public PrimeNode(Node n) {
68         nativeNode = n;
69     }
70
71     public PrimeNode(OtterNode otterNode, String JavaDoc path) {
72         JBProject nativeProject = null;
73         Node containerNode = null;
74
75         if (otterNode.getProject().getNativeProject() instanceof JBProject) {
76             nativeProject =
77                 (JBProject) otterNode.getProject().getNativeProject();
78         }
79         if (otterNode.getNativeNode() instanceof Node) {
80             containerNode = (Node) otterNode.getNativeNode();
81         }
82         if (nativeProject != null && containerNode != null) {
83             Url url = null;
84             Node found = null;
85
86             url = new Url(new File JavaDoc(path));
87             found = nativeProject.findNode(url);
88             if (found == null) {
89                 Node newNode = null;
90
91                 newNode = nativeProject.getNode(url);
92                 setNativeNode(newNode);
93                 SwingUtilities.invokeLater(new ParentSetter(containerNode));
94             } else {
95                 setNativeNode(found);
96             }
97         }
98     }
99
100
101     public OtterProject getProject() {
102         return (new PrimeProject((JBProject) nativeNode.getProject()));
103     }
104
105     /**
106      * Method declaration
107      *
108      * @return
109      */

110     public String JavaDoc getFilePath() {
111         File JavaDoc out = null;
112
113         if (nativeNode != null) {
114             if (nativeNode instanceof FileNode) {
115                 FileNode fileNode;
116
117                 fileNode = (FileNode) nativeNode;
118                 out = fileNode.getUrl().getFileObject();
119             }
120         }
121         return PathHandle.createPathString(out);
122     }
123
124     public String JavaDoc getXMLCOptionFilePath() {
125         String JavaDoc path = new String JavaDoc();
126         File JavaDoc file = null;
127         PathHandle handle = null;
128
129         file =
130             PathUtil.getFileRelativeToProject(this,
131                                               PropertyKeys.NAME_XMLC_OPTION_FILEPATH);
132         handle = PathHandle.createPathHandle(file);
133         if (handle.isFile() && handle.hasExtension(Constants.TYPE_XMLC)) {
134             path = handle.getPath();
135         }
136         return path;
137     }
138
139     public void setXMLCOptionFilePath(String JavaDoc n) {
140         PathHandle handle = null;
141         String JavaDoc relFilename = new String JavaDoc();
142
143         handle = PathHandle.createPathHandle(n);
144         if (handle.isFile() && handle.hasExtension(Constants.TYPE_XMLC)) {
145             relFilename = PathUtil.compressPathRelativeToProject(this,
146                     handle.getPath());
147         }
148         setProperty(PropertyKeys.NAME_XMLC_OPTION_FILEPATH, relFilename);
149     }
150
151     public String JavaDoc getXMLCParameters() {
152         String JavaDoc out = new String JavaDoc();
153
154         out = getProperty(PropertyKeys.NAME_XMLC_PARAMETERS);
155         out = PropUtil.cleanXMLCParameters(out);
156         return out;
157     }
158
159     public void setXMLCParameters(String JavaDoc in) {
160         String JavaDoc out = new String JavaDoc();
161
162         out = PropUtil.cleanXMLCParameters(in);
163         setProperty(PropertyKeys.NAME_XMLC_PARAMETERS, out);
164     }
165
166     /**
167      * Method declaration
168      *
169      *
170      * @param property
171      *
172      * @return
173      */

174     public String JavaDoc getProperty(String JavaDoc property) {
175         String JavaDoc out = null;
176
177         if (nativeNode != null) {
178             out = nativeNode.getProperty(property);
179         }
180         return out;
181     }
182
183     /**
184      * Method declaration
185      *
186      *
187      * @param property
188      * @param value
189      */

190     public void setProperty(String JavaDoc property, String JavaDoc value) {
191         if (nativeNode != null) {
192             nativeNode.setProperty(property, value);
193         }
194     }
195
196     public void setProperty(String JavaDoc property, int i) {
197         String JavaDoc value = Integer.toString(i);
198
199         setProperty(property, value);
200     }
201
202     /**
203      * Method declaration
204      *
205      *
206      * @return
207      */

208     public Object JavaDoc getNativeNode() {
209         return nativeNode;
210     }
211
212     /**
213      * Method declaration
214      *
215      *
216      * @param n
217      */

218     public void setNativeNode(Object JavaDoc n) {
219         nativeNode = (Node) n;
220     }
221
222     public OtterNode getParent() {
223         OtterNode parent = null;
224         Node nativeParent = null;
225
226         nativeParent = nativeNode.getParent();
227         if (nativeParent instanceof JBProject) {
228             parent = getProject();
229         } else {
230             parent = new PrimeNode(nativeParent);
231         }
232         return parent;
233     }
234
235     public boolean isSelected() {
236         String JavaDoc in = getProperty(PropertyKeys.NAME_SELECTED);
237
238         return PropUtil.stringToBoolean(in, false);
239     }
240
241     public void setSelected(boolean b) {
242         setProperty(PropertyKeys.NAME_SELECTED, PropUtil.booleanToString(b));
243     }
244
245     /**
246      * Save Exception information for reporting. This lets exceptions from
247      * multiple nodes to be reported in a batch.
248      *
249      * @param e
250      * An exception that occured while invoking XMLC.
251      */

252     public void setException(Throwable JavaDoc e) {
253         exception = e;
254     }
255
256     /**
257      * Get an exception that occured when invoking XMLC. Null if the node
258      * has not been compiled or was compiled without error.
259      */

260     public Throwable JavaDoc getException() {
261         return exception;
262     }
263
264     public void save() {
265         FileNode fileNode = null;
266
267         if (getNativeNode() instanceof FileNode) {
268             fileNode = (FileNode) getNativeNode();
269             try {
270                 fileNode.save();
271             } catch (Exception JavaDoc e) {
272                 e.printStackTrace();
273             }
274         }
275     }
276
277     protected class ParentSetter implements Runnable JavaDoc {
278         private Node conNode = null;
279
280         protected ParentSetter(Node con) {
281             conNode = con;
282         }
283
284         synchronized public void run() {
285             Node nativeNode = null;
286             Node nativeParent = null;
287             JBProject nativeProject = null;
288
289             nativeNode = (Node) getNativeNode();
290             nativeNode.setParent(conNode);
291             nativeProject = (JBProject) getProject().getNativeProject();
292             nativeNode.check();
293             nativeProject.fireChildrenChanged(nativeNode);
294         }
295
296     }
297 }
298
Popular Tags