1 22 package org.enhydra.kelp.jbuilder.node; 23 24 import org.enhydra.tool.common.ToolException; 26 27 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 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 import java.io.File ; 46 47 53 public class PrimeNodeFactory extends OtterNodeFactory { 54 55 64 public OtterFolderNode createFolderNode(OtterNode otterNode, 65 String name) { 66 OtterFolderNode newNode = null; 67 68 newNode = new PrimeFolderNode(otterNode, name); 69 return newNode; 70 } 71 72 81 public OtterJavaFileNode createJavaFileNode(OtterNode otterNode, 82 String file) { 83 OtterJavaFileNode newNode = null; 84 85 newNode = new PrimeJavaFileNode(otterNode, file); 86 return newNode; 87 } 88 89 98 public OtterDocumentNode createDocumentNode(OtterNode otterNode, 99 String file) { 100 OtterDocumentNode newNode = null; 101 102 newNode = new PrimeDocumentNode(otterNode, file); 103 return newNode; 104 } 105 106 115 public OtterImageFileNode createImageFileNode(OtterNode otterNode, 116 String file) { 117 OtterImageFileNode newNode = null; 118 119 newNode = new PrimeImageFileNode(otterNode, file); 120 return newNode; 121 } 122 123 132 public OtterTextFileNode createTextFileNode(OtterNode otterNode, 133 String file) { 134 OtterTextFileNode newNode = null; 135 136 newNode = new PrimeTextFileNode(otterNode, file); 137 return newNode; 138 } 139 140 149 public OtterTemplateNode createTemplateNode(OtterNode otterNode, 150 String file) { 151 OtterTemplateNode newNode = null; 152 153 newNode = new PrimeTemplateNode(otterNode, file); 154 return newNode; 155 } 156 157 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 191 public synchronized OtterJavaFileNode[] replaceGeneratedSource(OtterProject project, 192 OtterNode node, String [] files) { 193 194 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 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 (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 e) { 225 e.printStackTrace(); 226 } 227 javaNodes[i] = createJavaFileNode(node, files[i]); 228 } 229 return javaNodes; 230 } 231 232 } 233 | Popular Tags |