KickJava   Java API By Example, From Geeks To Geeks.

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


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.ToolException;
26
27 // Kelp imports
28
import org.enhydra.kelp.common.node.OtterDocumentNode;
29 import org.enhydra.kelp.common.node.OtterNode;
30 import org.enhydra.kelp.common.node.OtterNodeFactory;
31 import org.enhydra.kelp.common.node.OtterProject;
32 import org.enhydra.kelp.common.node.OtterTemplateNode;
33 import org.enhydra.kelp.common.node.OtterFolderNode;
34 import org.enhydra.kelp.common.node.OtterImageFileNode;
35 import org.enhydra.kelp.common.node.OtterJavaFileNode;
36 import org.enhydra.kelp.common.node.OtterTextFileNode;
37
38 // Primetime imports
39
import com.borland.primetime.node.Node;
40 import com.borland.primetime.node.FileNode;
41 import com.borland.primetime.node.FolderNode;
42 import com.borland.jbuilder.node.JBProject;
43
44 // Standard imports
45
import java.io.File JavaDoc;
46
47 /**
48  * Class declaration
49  *
50  *
51  * @author Paul Mahar
52  */

53 public class PrimeNodeFactory extends OtterNodeFactory {
54
55     /**
56      * Method declaration
57      *
58      *
59      * @param otterNode
60      * @param name
61      *
62      * @return
63      */

64     public OtterFolderNode createFolderNode(OtterNode otterNode,
65                                             String JavaDoc name) {
66         OtterFolderNode newNode = null;
67
68         newNode = new PrimeFolderNode(otterNode, name);
69         return newNode;
70     }
71
72     /**
73      * Method declaration
74      *
75      *
76      * @param otterNode
77      * @param file
78      *
79      * @return
80      */

81     public OtterJavaFileNode createJavaFileNode(OtterNode otterNode,
82                                                 String JavaDoc file) {
83         OtterJavaFileNode newNode = null;
84
85         newNode = new PrimeJavaFileNode(otterNode, file);
86         return newNode;
87     }
88
89     /**
90      * Method declaration
91      *
92      *
93      * @param otterNode
94      * @param file
95      *
96      * @return
97      */

98     public OtterDocumentNode createDocumentNode(OtterNode otterNode,
99                                                 String JavaDoc file) {
100         OtterDocumentNode newNode = null;
101
102         newNode = new PrimeDocumentNode(otterNode, file);
103         return newNode;
104     }
105
106     /**
107      * Method declaration
108      *
109      *
110      * @param otterNode
111      * @param file
112      *
113      * @return
114      */

115     public OtterImageFileNode createImageFileNode(OtterNode otterNode,
116             String JavaDoc file) {
117         OtterImageFileNode newNode = null;
118
119         newNode = new PrimeImageFileNode(otterNode, file);
120         return newNode;
121     }
122
123     /**
124      * Method declaration
125      *
126      *
127      * @param otterNode
128      * @param file
129      *
130      * @return
131      */

132     public OtterTextFileNode createTextFileNode(OtterNode otterNode,
133                                                 String JavaDoc file) {
134         OtterTextFileNode newNode = null;
135
136         newNode = new PrimeTextFileNode(otterNode, file);
137         return newNode;
138     }
139
140     /**
141      * Method declaration
142      *
143      *
144      * @param otterNode
145      * @param file
146      *
147      * @return
148      */

149     public OtterTemplateNode createTemplateNode(OtterNode otterNode,
150                                                 String JavaDoc file) {
151         OtterTemplateNode newNode = null;
152
153         newNode = new PrimeTemplateNode(otterNode, file);
154         return newNode;
155     }
156
157     /**
158      * Method declaration
159      *
160      * @param otterNode
161      *
162      * @return
163      */

164     public OtterTemplateNode getTemplateNode(OtterNode otterNode) {
165         OtterTemplateNode newNode = null;
166
167         if (otterNode.getNativeNode() instanceof FileNode) {
168             FileNode nativeNode = null;
169
170             nativeNode = (FileNode) otterNode.getNativeNode();
171             try {
172               newNode = new PrimeTemplateNode(nativeNode);
173             } catch (ToolException e) {
174               e.printStackTrace();
175               newNode = null;
176             }
177         }
178         return newNode;
179     }
180
181     /**
182      * Method declaration
183      *
184      *
185      * @param project
186      * @param node
187      * @param files
188      *
189      * @return
190      */

191     public synchronized OtterJavaFileNode[] replaceGeneratedSource(OtterProject project,
192             OtterNode node, String JavaDoc[] files) {
193
194         // Remove previously generated sources and then add
195
OtterJavaFileNode[] javaNodes = new OtterJavaFileNode[files.length];
196         JBProject nativeProject =
197             (JBProject) project.getNativeProject();
198         FileNode nativeNode = (FileNode) node.getNativeNode();
199         Node[] child = nativeNode.getChildren();
200         File JavaDoc current = null;
201         boolean keep = false;
202
203         for (int i = 0; i < child.length; i++) {
204             if (child[i] instanceof FileNode) {
205                 FileNode cursor = null;
206
207                 cursor = (FileNode) child[i];
208                 for (int j = 0; j < files.length; j++) {
209                     current = new File JavaDoc(files[j]);
210                     if (cursor.getUrl().getFileObject().getAbsolutePath().equals(current.getAbsolutePath())) {
211                         keep = true;
212                         break;
213                     }
214                 }
215                 if (!keep) {
216                     cursor.setParent(null);
217                     cursor.getUrl().getFileObject().delete();
218                 }
219             }
220         }
221         for (int i = 0; i < files.length; i++) {
222             try {
223                 Thread.sleep(100);
224             } catch (Exception JavaDoc e) {
225                 e.printStackTrace();
226             }
227             javaNodes[i] = createJavaFileNode(node, files[i]);
228         }
229         return javaNodes;
230     }
231
232 }
233
Popular Tags