1 23 package org.enhydra.kelp.jbuilder.node; 24 25 import org.enhydra.tool.ToolBoxInfo; 27 import org.enhydra.tool.common.PathHandle; 28 import org.enhydra.tool.common.ToolException; 29 30 import com.borland.jbuilder.node.JBProject; 32 import com.borland.jbuilder.node.HTMLFileNode; 33 import com.borland.jbuilder.paths.PathSet; 34 import com.borland.jbuilder.paths.PathSetManager; 35 import com.borland.jbuilder.paths.ProjectPathSet; 36 import com.borland.primetime.ide.Browser; 37 import com.borland.primetime.node.Node; 38 import com.borland.primetime.node.Project; 39 import com.borland.primetime.node.FileNode; 40 import com.borland.primetime.node.TextFileNode; 41 import com.borland.primetime.vfs.Url; 42 import com.borland.jbuilder.paths.PathSetManager; 43 44 45 import org.enhydra.kelp.common.Constants; 47 import org.enhydra.kelp.common.PathUtil; 48 import org.enhydra.kelp.common.deployer.RunParameters; 49 import org.enhydra.kelp.common.node.OtterDocumentNode; 50 import org.enhydra.kelp.common.node.OtterFileNode; 51 import org.enhydra.kelp.common.node.OtterNode; 52 import org.enhydra.kelp.common.node.OtterTextFileNode; 53 import org.enhydra.kelp.common.node.OtterProject; 54 import org.enhydra.kelp.common.node.OtterNodeFactory; 55 import org.enhydra.kelp.common.node.PropertyKeys; 56 57 import java.io.File ; 59 import java.util.ArrayList ; 60 import java.lang.reflect.Method ; 61 62 64 70 public class PrimeProject extends OtterProject { 71 private JBProject nativeProject = null; 72 private PrimeNodeFactory factory = null; 73 74 80 public PrimeProject(JBProject p) { 81 nativeProject = p; 82 factory = new PrimeNodeFactory(); 83 } 85 86 public boolean isDefaultProject() { 87 boolean def = false; 88 89 if (getNativeProject() == null) { 90 91 } else { 93 def = Browser.getDefaultProject().equals(getNativeProject()); 94 } 95 return def; 96 } 97 98 public String getCodeGenDefaultDestination() { 99 PathHandle ph = null; 100 File file = null; 101 102 file = new File (getRootPath()); 103 if (file.getParentFile() == null) { 104 ph = PathHandle.createPathHandle(file); 105 } else { 106 ph = PathHandle.createPathHandle(file.getParentFile()); 107 } 108 return ph.getPath(); 109 } 110 111 117 public OtterTextFileNode getFirstPolicy() { 118 PolicyNodeReader reader = new PolicyNodeReader(); 119 120 return reader.getFirstNode(nativeProject); 121 } 122 123 public String getWorkingPath() { 124 String path = new String (); 125 File file = null; 126 127 path = getRootPath(); 128 path = nativeProject.getProperty(PropertyKeys.NAME_WORKING_DIR, path); 129 if (path.indexOf("%|") == 1) { StringBuffer buf = new StringBuffer (); 131 132 buf.append(path.charAt(0)); 133 buf.append(':'); 134 buf.append(path.substring(3)); 135 path = buf.toString(); 136 } 137 path = PathUtil.expandPathRelativeToProject(this, path); 138 path = PathHandle.createPathString(path); 139 return path; 140 } 141 142 public void setWorkingPath(String inPath) { 143 PathHandle handle = null; 144 ProjectPathSet pathSet = null; 145 Method setWD = null; 146 Method save = null; 147 Class [] paramClasses = new Class [0]; 148 Url[] paramValues = new Url[0]; 149 150 handle = PathHandle.createPathHandle(inPath); 151 pathSet = nativeProject.getPaths(); 152 try { 153 paramValues = new Url[1]; 154 paramValues[0] = new Url(handle.getFile()); 155 paramClasses = new Class [1]; 156 paramClasses[0] = paramValues[0].getClass(); 157 setWD = pathSet.getClass().getMethod("setWorkingDirectory", 158 paramClasses); setWD.invoke(pathSet, paramValues); 160 paramClasses = new Class [0]; 161 paramValues = new Url[0]; 162 save = pathSet.getClass().getMethod("save", paramClasses); save.invoke(pathSet, paramValues); 164 } catch (Exception e) { 165 166 String compress = new String (); 168 169 compress = PathUtil.compressPathRelativeToProject(this, 170 handle.getPath()); 171 nativeProject.setProperty(PropertyKeys.NAME_WORKING_DIR, 172 compress); 173 } 174 } 175 176 180 public OtterFileNode[] getAllInput() { 181 String [] ext = new String [0]; 182 OtterFileNode[] input = new OtterFileNode[0]; 183 OtterFileNode[] nodes = new OtterFileNode[0]; 184 ArrayList list = new ArrayList (); 185 PathHandle inputPath = null; 186 PathHandle cursorPath = null; 187 188 inputPath = PathHandle.createPathHandle(getDeployInputPath()); 189 if (isDeployInputFilter()) { 190 ext = new String [1]; 191 ext[0] = Constants.TYPE_IN; 192 } 193 nodes = findFileNodesByType(ext); 194 for (int i = 0; i < nodes.length; i++) { 195 cursorPath = PathHandle.createPathHandle(nodes[i].getFilePath()); 196 if (inputPath.parentOf(cursorPath)) { 197 list.add(nodes[i]); 198 } 199 } 200 input = new OtterFileNode[list.size()]; 201 input = (OtterFileNode[]) list.toArray(input); 202 list.clear(); 203 return input; 204 } 205 206 214 public OtterFileNode[] findFileNodesByType(String [] extensions) { 215 NodeReader reader = new NodeReader(extensions); 216 217 return reader.getNodes(nativeProject); 218 } 219 220 226 public OtterTextFileNode[] getAllDeploymentDescs() { 227 DeploymentNodeReader reader = new DeploymentNodeReader(); 228 229 return reader.getNodes(nativeProject); 230 } 231 232 238 public OtterDocumentNode[] getAllDocuments() { 239 DocumentNodeReader reader = new DocumentNodeReader(); 240 241 return reader.getNodes(this); 242 } 243 244 250 public Object getNativeProject() { 251 return nativeProject; 252 } 253 254 260 public void setNativeProject(Object o) { 261 nativeProject = (JBProject) o; 262 } 263 264 270 public Object getNativeNode() { 271 return getNativeProject(); 272 } 273 274 280 public void setNativeNode(Object o) { 281 setNativeProject(o); 282 } 283 284 290 public OtterProject getProject() { 291 return this; 292 } 293 294 public OtterNode getParent() { 295 return null; 296 } 297 298 304 public OtterNodeFactory getNodeFactory() { 305 return factory; 306 } 307 308 314 public boolean isOpenBuild() { 315 return true; 316 } 317 318 324 public String getClassOutputPath() { 325 String out = File.separator + Constants.DIR_CLASSES; 326 327 if (nativeProject != null) { 328 out = nativeProject.getPaths().getOutPath().getFile(); 329 } 330 331 out.replace('\\', File.separatorChar); 333 out.replace('/', File.separatorChar); 334 return out; 335 } 336 337 public void setClassOutputPath(String p) { 338 Url classOut = null; 339 340 classOut = new Url(new File (p)); 341 nativeProject.getPaths().setOutPath(classOut); 342 } 343 344 350 public String getSourcePath() { 351 StringBuffer path = new StringBuffer (); 352 Url urlSet[]; 353 354 if (nativeProject != null) { 355 urlSet = nativeProject.getPaths().getSourcePath(); 356 for (int i = 0; i < urlSet.length; i++) { 357 if (path.length() > 0) { 358 path.append('/'); 359 } 360 if (i > 0) { 361 path.append(';'); 362 } 363 path.append(PathHandle.createPathHandle(urlSet[i].getFile())); 364 } 365 } 366 return path.toString(); 367 } 368 369 375 public void setSourcePathArray(String [] pathAsArray) { 376 Url urlSet[] = new Url[pathAsArray.length]; 377 378 for (int i = 0; i < pathAsArray.length; i++) { 379 urlSet[i] = new Url(new File (pathAsArray[i])); 380 } 381 nativeProject.getPaths().setSourcePath(urlSet); 382 } 383 384 390 public String [] getSourcePathArray() { 391 String [] pathAsArray = null; 392 Url urlSet[]; 393 394 if (nativeProject != null) { 395 urlSet = nativeProject.getPaths().getSourcePath(); 396 pathAsArray = new String [urlSet.length]; 397 for (int i = 0; i < urlSet.length; i++) { 398 pathAsArray[i] = 399 PathHandle.createPathString(urlSet[i].getFile()); 400 } 401 } 402 return pathAsArray; 403 } 404 405 411 public String getClassPath() { 412 PathSet pathSet; 413 Url urlSet[]; 414 String path = null; 415 String libs = null; 416 417 if (nativeProject != null) { 418 libs = getProperty(JBProject.PROPERTY_LIBRARIES); 419 pathSet = PathSetManager.getLibrary(libs); 420 urlSet = pathSet.getFullClassPath(); 421 path = Url.getPath(urlSet); 422 } 423 return path; 424 } 425 426 434 public String getProperty(String property) { 435 String out = null; 436 437 if (nativeProject != null) { 438 out = nativeProject.getProperty(property); 439 } 440 return out; 441 } 442 443 450 public void setProperty(String property, String value) { 451 if (nativeProject != null) { 452 if (property.trim().equalsIgnoreCase(PropertyKeys.NAME_LIBRARIES) 453 && value.trim().equalsIgnoreCase(PropertyKeys.VALUE_ENHYDRA)) { 454 nativeProject.getPaths().putClassOnFullPath(ToolBoxInfo.getEnhydraMainClass()); 455 } else { 456 nativeProject.setProperty(property, value); 457 } 458 } 459 } 460 461 468 public void setProperty(String property, int i) { 469 String value = Integer.toString(i); 470 471 setProperty(property, value); 472 } 473 474 480 public String getRootPath() { 481 PathHandle ph = null; 482 483 ph = 484 PathHandle.createPathHandle(nativeProject.getUrl().getFileObject()); 485 ph = ph.getParent(); 486 return ph.getPath(); 487 } 488 489 495 public char getFileSeparatorChar() { 496 return '/'; 497 } 498 499 503 public void configureRunClass() { 504 RunParameters param = new RunParameters(this); 505 506 nativeProject.setProperty("runtime.0", "RunnableType", "com.borland.jbuilder.runtime.ApplicationRunner"); nativeProject.setProperty("runtime.0", "application.class", ToolBoxInfo.getEnhydraMainClass()); 511 nativeProject.setProperty("runtime.0", 512 "application.parameters", param.getAppParameters()); 514 nativeProject.setProperty("runtime.0", "application.vmparameters", param.getVMParameters()); 518 if (!ToolBoxInfo.isEnhydra3()) { 520 nativeProject.setProperty("runtime.0", "application.vmparameters", param.getVMParameters()); 523 } 524 } 525 526 public void save() { 527 Project project = null; 528 529 if (getNativeNode() instanceof Project) { 530 project = (Project) getNativeNode(); 531 try { 532 project.save(); 533 } catch (Exception e) { 534 e.printStackTrace(); 535 } 536 } 537 } 538 539 545 public void setProjectJavaPath(JBProject jbproj) { 546 String javaPath = 547 ""+PathSetManager.getJDK(jbproj.getProperty("JDK")). 548 getHomePath().getFile(); 549 setProperty(DODS_PROJECT_JAVA_PATH, javaPath); 556 } 557 558 564 public void setEnhydraPath(JBProject jbproj) { 565 String javaPath = 566 PathSetManager.getLibrary("Enhydra").getClassPath()[0].getFile(); 567 javaPath = javaPath.substring(1, javaPath.indexOf("/lib")); 568 setProperty(DODS_ENHYDRA_PATH, javaPath); 569 } 570 571 } 572 573 579 class DeploymentNodeReader { 580 private ArrayList list = new ArrayList (); 581 582 586 protected DeploymentNodeReader() {} 587 588 596 protected OtterTextFileNode[] getNodes(JBProject nativeProject) { 597 OtterTextFileNode[] nodes; 598 599 recursiveRead(nativeProject); 600 nodes = new OtterTextFileNode[list.size()]; 601 for (int i = 0; i < nodes.length; i++) { 602 nodes[i] = (OtterTextFileNode) list.get(i); 603 } 604 return nodes; 605 } 606 607 613 private void recursiveRead(Node container) { 614 String filename = null; 615 Node[] nativeNodes = container.getChildren(); 616 PathHandle current = null; 617 618 for (int i = 0; i < nativeNodes.length; i++) { 619 TextFileNode nativeFile = null; 620 621 if (nativeNodes[i] instanceof TextFileNode) { 622 nativeFile = (TextFileNode) nativeNodes[i]; 623 filename = nativeFile.getUrl().getFile(); 624 current = PathHandle.createPathHandle(filename); 625 if (current.isFile() 626 && (current.endsWith(File.separator + Constants.FILE_WEB_XML) 627 || current.endsWith(File.separator 628 + Constants.FILE_EJB_JAR_XML))) { 629 PrimeTextFileNode primeNode = null; 630 631 primeNode = new PrimeTextFileNode(nativeFile); 632 list.add(primeNode); 633 } 634 } 635 recursiveRead(nativeNodes[i]); 636 } 637 } 638 639 } 640 641 647 class DocumentNodeReader { 648 private ArrayList list = new ArrayList (); 649 private OtterProject otterProject = null; 650 private String [] docTypes = new String [0]; 651 652 656 protected DocumentNodeReader() {} 657 658 666 protected OtterDocumentNode[] getNodes(OtterProject p) { 667 OtterDocumentNode[] nodes = new OtterDocumentNode[0]; 668 669 otterProject = p; 670 docTypes = otterProject.getDocTypes(); 671 list.clear(); 672 recursiveRead((JBProject) otterProject.getNativeProject()); 673 nodes = new OtterDocumentNode[list.size()]; 674 nodes = (OtterDocumentNode[]) list.toArray(nodes); 675 list.clear(); 676 return nodes; 677 } 678 679 685 private void recursiveRead(Node container) { 686 Node[] nativeNodes = container.getChildren(); 687 PathHandle current = null; 688 689 for (int i = 0; i < nativeNodes.length; i++) { 690 FileNode nativeFile = null; 691 692 if (nativeNodes[i] instanceof FileNode) { 693 nativeFile = (FileNode) nativeNodes[i]; 694 current = 695 PathHandle.createPathHandle(nativeFile.getUrl().getFileObject()); 696 if (current.getFile().exists() 697 && current.hasExtension(docTypes)) { 698 OtterDocumentNode docNode = null; 699 700 docNode = new PrimeDocumentNode(nativeFile); 701 list.add(docNode); 702 } 703 } 704 recursiveRead(nativeNodes[i]); 705 } 706 } 707 708 } 709 class NodeReader { 710 private ArrayList list = new ArrayList (); 711 private String [] extensions = new String [0]; 712 713 719 protected NodeReader(String [] exts) { 720 extensions = exts; 721 } 722 723 731 protected OtterFileNode[] getNodes(JBProject nativeProject) { 732 OtterFileNode[] nodes; 733 734 recursiveRead(nativeProject); 735 nodes = new OtterFileNode[list.size()]; 736 for (int i = 0; i < nodes.length; i++) { 737 if (list.get(i) instanceof OtterTextFileNode) { 738 nodes[i] = (OtterTextFileNode) list.get(i); 739 } else { 740 nodes[i] = (OtterFileNode) list.get(i); 741 } 742 } 743 return nodes; 744 } 745 746 752 private void recursiveRead(Node container) { 753 String filename = null; 754 Node[] nativeNodes = container.getChildren(); 755 PathHandle current = null; 756 757 for (int i = 0; i < nativeNodes.length; i++) { 758 FileNode nativeFile = null; 759 760 if (nativeNodes[i] instanceof FileNode) { 761 nativeFile = (FileNode) nativeNodes[i]; 762 filename = nativeFile.getUrl().getFile(); 763 current = PathHandle.createPathHandle(filename); 764 if (current.getFile().exists()) { 765 if (current.hasExtension(extensions) 766 || (extensions.length == 0)) { 767 PrimeNode primeNode = null; 768 769 if (nativeFile instanceof TextFileNode) { 770 primeNode = 771 new PrimeTextFileNode((TextFileNode) nativeFile); 772 } else { 773 primeNode = new PrimeNode(nativeFile); 774 } 775 list.add(primeNode); 776 } 777 } 778 } 779 recursiveRead(nativeNodes[i]); 780 } 781 } 782 783 } 784 785 791 class PolicyNodeReader { 792 private OtterTextFileNode node = null; 793 794 802 protected OtterTextFileNode getFirstNode(JBProject nativeProject) { 803 recursiveRead(nativeProject); 804 return node; 805 } 806 807 813 private void recursiveRead(Node container) { 814 String filename = null; 815 Node[] nativeNodes = container.getChildren(); 816 PathHandle current = null; 817 818 for (int i = 0; i < nativeNodes.length; i++) { 819 TextFileNode nativeFile = null; 820 821 if (nativeNodes[i] instanceof TextFileNode) { 822 nativeFile = (TextFileNode) nativeNodes[i]; 823 filename = nativeFile.getUrl().getFile(); 824 current = PathHandle.createPathHandle(filename); 825 if (current.isFile() 826 && current.endsWith(Constants.FILE_JAVA_POLICY)) { 827 node = new PrimeTextFileNode(nativeFile); 828 break; 829 } 830 } 831 recursiveRead(nativeNodes[i]); 832 } 833 } 834 835 } 836 | Popular Tags |