KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > forte > node > ForteNode


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  * Lisa Reese
21  *
22  */

23
24 package org.enhydra.kelp.forte.node;
25
26 // ToolBox imports
27
import org.enhydra.tool.common.PathHandle;
28
29 // Forte imports
30
//import com.borland.jbuilder.node.JBProject; ?????
31
import org.openide.loaders.DataNode;
32 import org.openide.nodes.Node;
33 import org.openide.nodes.FilterNode;
34 import org.openide.cookies.ProjectCookie;
35 import org.openide.loaders.DataObject;
36 import org.openide.loaders.DataObjectNotFoundException;
37 import org.openide.loaders.DataShadow;
38 import org.openide.loaders.DataFolder;
39 import org.openide.filesystems.FileSystem;
40 import org.openide.filesystems.FileObject;
41 import org.openide.filesystems.FileStateInvalidException;
42 import org.openide.filesystems.LocalFileSystem;
43
44 // AddinCore
45
import org.enhydra.kelp.common.Constants;
46 import org.enhydra.kelp.common.PathUtil;
47 import org.enhydra.kelp.common.PropUtil;
48 import org.enhydra.kelp.common.node.PropertyKeys;
49 import org.enhydra.kelp.common.node.OtterNode;
50 import org.enhydra.kelp.common.node.OtterFileNode;
51 import org.enhydra.kelp.common.node.OtterProject;
52
53 import org.enhydra.kelp.forte.XMLCSettings;
54 import org.enhydra.kelp.forte.DeploySettings;
55
56 // Standard imports
57
import java.io.File JavaDoc;
58 import javax.swing.SwingUtilities JavaDoc;
59 import java.util.Enumeration JavaDoc;
60 import java.util.StringTokenizer JavaDoc;
61 import java.net.URL JavaDoc;
62 import java.net.MalformedURLException JavaDoc;
63 /**
64  *
65  * @author rees0234
66  * @version
67  */

68 public class ForteNode implements OtterFileNode
69 {
70     protected DataObject nativeNode = null;
71     private Throwable JavaDoc exception = null;
72     
73     /**
74      * Constructor declaration
75      *
76      * @param n
77      */

78     public ForteNode(DataObject dob)
79     {
80         nativeNode = dob;
81     }
82     
83     /**
84      * Constructor declaration
85      *
86      * @param otterNode
87      * @param path
88      */

89     public ForteNode(OtterNode parent, String JavaDoc path) //this is default for files
90
{
91         setNativeNode(FindData(path));
92     }
93     
94     protected DataObject FindData(String JavaDoc path)
95     {//not thrilled with this one....
96
DataObject data = null;
97         FileObject file = null;
98         
99         FileSystem fs = null;
100         try {
101             fs = ((ForteProject)getProject()).getRootFolder().getFileSystem();
102         } catch (FileStateInvalidException e){
103             System.err.println(e);
104         }
105         String JavaDoc adjPath = path;
106         String JavaDoc sysVal = fs.getSystemName();
107         if (path.startsWith(sysVal))
108             adjPath = path.substring(sysVal.length()+ 1);
109         file = fs.findResource(adjPath);
110         if (file != null)
111             try
112             {
113                 data = DataObject.find(file);
114             }catch (DataObjectNotFoundException e)
115             {
116                 System.err.println(e);
117             }
118             return data;
119     }
120     
121     
122     public OtterProject getProject()
123     {
124         return new ForteProject();
125     }
126     
127     /**
128      * Method declaration
129      *
130      * @return
131      */

132     public String JavaDoc getFilePath()
133     {
134         if ((nativeNode != null))
135         {
136             if (nativeNode instanceof DataShadow)
137                 nativeNode = ((DataShadow)nativeNode).getOriginal();
138             if (nativeNode != null)
139             {
140                 FileSystem fs = null;
141                 StringBuffer JavaDoc res = new StringBuffer JavaDoc();
142                 FileObject file = nativeNode.getPrimaryFile();
143                 try
144                 {
145                     fs = file.getFileSystem();
146                 } catch (FileStateInvalidException e)
147                 {
148                     System.err.println(e);
149                     return "invalid";
150                 }
151                 
152                 res.append(fs.getSystemName());
153                 
154                 String JavaDoc pack = new String JavaDoc();
155                 
156                 if (nativeNode instanceof DataFolder)
157                 {
158                     pack = file.getPackageName(File.separatorChar);
159                     
160                 }
161                 else
162                 {
163                     pack = file.getPackageNameExt(File.separatorChar, '.');
164                 }
165                 if (pack.length() > 0)
166                 {
167                     res.append(File.separatorChar);
168                     res.append(pack);
169                 }
170                 
171                 return res.toString();
172             }
173             
174         }
175         
176         return null; //should only return null on Project node
177
}
178     
179     public String JavaDoc getXMLCOptionFilePath()
180     {
181         //this does not make sense for base node...only for XMLC-oriented nodes
182
return null;
183     }
184     
185     public void setXMLCOptionFilePath(String JavaDoc n)
186     {
187         //this does not make sense for base node...only for XMLC-oriented nodes
188
}
189     
190     public String JavaDoc getXMLCParameters()
191     {
192         //this does not make sense for base node...only for XMLC-oriented nodes
193
return null;
194     }
195     
196     public void setXMLCParameters(String JavaDoc in)
197     {
198         
199         //this does not make sense for base node...only for XMLC-oriented nodes
200
}
201     
202     /**
203      * Method declaration
204      *
205      *
206      * @param property
207      *
208      * @return
209      */

210     public String JavaDoc getProperty(String JavaDoc property)
211     {
212         String JavaDoc path = PathUtil.compressPathRelativeToProject(this, getFilePath());
213         
214         if (property.startsWith("enhydra.xmlc"))
215             return XMLCSettings.getDefault().getNodeProperty(path + property);
216         else
217             return DeploySettings.getDefault().getNodeProperty(path + property);
218     }
219     
220     /**
221      * Method declaration
222      *
223      * @param property
224      * @param i
225      */

226     public void setProperty(String JavaDoc property, String JavaDoc value)
227     {
228         String JavaDoc path = PathUtil.compressPathRelativeToProject(this, getFilePath());
229         if (property.startsWith("enhydra.xmlc"))
230             XMLCSettings.getDefault().setNodeProperty(path + property, value);
231         else
232             DeploySettings.getDefault().setNodeProperty(path + property, value);
233     }
234     /**
235      * Method declaration
236      *
237      *
238      * @param property
239      * @param value
240      */

241     
242     public void setProperty(String JavaDoc property, int i)
243     {
244         String JavaDoc value = Integer.toString(i);
245         
246         setProperty(property, value);
247     }
248     
249     /**
250      * Method declaration
251      *
252      *
253      * @return
254      */

255     public Object JavaDoc getNativeNode()
256     {
257         return nativeNode;
258     }
259     
260     /**
261      * Method declaration
262      *
263      *
264      * @param n
265      */

266     public void setNativeNode(Object JavaDoc n)
267     {
268         nativeNode = (DataObject) n;
269     }
270     
271     public OtterNode getParent()
272     {
273         DataFolder nativeParent = null;
274         
275         nativeParent = nativeNode.getFolder();
276         if (nativeParent == null) //it its null, it is root of filesystem, which means parent must be project
277
{
278             return new ForteProject();
279         }
280         else
281         {
282             return new ForteFolderNode(nativeParent);
283         }
284     }
285     
286     public boolean isSelected()
287     {
288         return false;
289     }
290     
291     public void setSelected(boolean b)
292     {
293         System.out.println("wrong setSelected");
294     }
295     
296     /**
297      * Save Exception information for reporting. This lets exceptions from
298      * multiple nodes to be reported in a batch.
299      *
300      * @param e
301      * An exception that occured while invoking XMLC.
302      */

303     public void setException(Throwable JavaDoc e)
304     {
305         exception = e;
306     }
307     
308     /**
309      * Get an exception that occured when invoking XMLC. Null if the node
310      * has not been compiled or was compiled without error.
311      */

312     public Throwable JavaDoc getException()
313     {
314         return exception;
315     }
316     
317     public void save()
318     {
319         //this should be handled by loader ?
320
}
321     
322     
323 }
324
Popular Tags