KickJava   Java API By Example, From Geeks To Geeks.

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


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.ToolBoxInfo;
28 import org.enhydra.tool.common.PathHandle;
29 import org.enhydra.tool.common.ToolException;
30
31 // Forte imports
32
import org.openide.loaders.DataFolder;
33 import org.openide.loaders.DataObject;
34 import org.openide.nodes.Node;
35 import org.openide.nodes.Children;
36 import org.openide.filesystems.FileSystem;
37 import org.openide.filesystems.FileStateInvalidException;
38 import org.openide.loaders.DataShadow;
39 import org.openide.filesystems.FileObject;
40 import org.openide.loaders.MultiDataObject;
41 import org.openide.loaders.ExecSupport;
42 import org.openide.loaders.DataObjectNotFoundException;
43 import org.openide.TopManager;
44 import org.openide.execution.NbClassPath;
45
46 import org.netbeans.modules.text.TXTDataObject;
47
48 // AddinCore
49
import org.enhydra.kelp.common.Constants;
50 import org.enhydra.kelp.common.PathUtil;
51 import org.enhydra.kelp.common.node.OtterDocumentNode;
52 import org.enhydra.kelp.common.node.OtterFileNode;
53 import org.enhydra.kelp.common.node.OtterNode;
54 import org.enhydra.kelp.common.node.OtterTextFileNode;
55 import org.enhydra.kelp.common.node.OtterTemplateNode;
56 import org.enhydra.kelp.common.node.OtterProject;
57 import org.enhydra.kelp.common.node.OtterNodeFactory;
58 import org.enhydra.kelp.common.node.PropertyKeys;
59 import org.enhydra.kelp.common.PropUtil;
60 import org.enhydra.kelp.common.deployer.RunParameters;
61
62 import org.enhydra.kelp.forte.XMLCSettings;
63 import org.enhydra.kelp.forte.DeploySettings;
64 import org.enhydra.kelp.forte.DodsSettings;
65 import org.enhydra.kelp.forte.services.KelpExecutor;
66
67 import org.enhydra.tool.common.ToolException;
68
69 // Standard imports
70
import java.io.File JavaDoc;
71 import java.io.IOException JavaDoc;
72 import java.util.Vector JavaDoc;
73 import java.lang.reflect.Method JavaDoc;
74 import java.util.Enumeration JavaDoc;
75 import java.util.StringTokenizer JavaDoc;
76 import java.util.NoSuchElementException JavaDoc;
77
78 //dr NetBeans imports
79
import org.openide.NotifyDescriptor;
80
81 /**
82  * Class declaration
83  *
84  *
85  * @author
86  */

87 public class ForteProject extends OtterProject {
88
89 //dr
90
// private Node nativeProject = null;
91
// private ForteNodeFactory factory = null;
92
public Node nativeProject = null;
93     public ForteNodeFactory factory = null;
94
95     private static final String JavaDoc SOURCE_PATH_ARRAY = "project.sourcepath.array";
96
97     /**
98      * Constructor declaration
99      *
100      *
101      * @param project
102      */

103     public ForteProject () {
104         nativeProject = TopManager.getDefault().getPlaces().nodes().projectDesktop();
105         factory = new ForteNodeFactory();
106     }
107
108     public ForteProject(Node target)
109     {
110         nativeProject = target;
111         factory = new ForteNodeFactory();
112     }
113
114     public OtterNodeFactory getNodeFactory() {
115         return factory;
116     }
117
118     public String JavaDoc getGenerateToDirectory() {
119     return getClassOutputPath();
120     }
121
122     public String JavaDoc getRootPath()
123     {
124         return XMLCSettings.getDefault().getRoot();
125     }
126
127     public String JavaDoc getDefaultRoot()
128     {
129         String JavaDoc root = null;
130         Children kids = nativeProject.getChildren();
131         if (kids == null)
132             return null;
133         Enumeration JavaDoc nodes = kids.nodes();
134
135         while (nodes.hasMoreElements())
136         {
137             Node nextNode = (Node)nodes.nextElement();
138             DataObject dob = (DataObject)nextNode.getCookie(DataObject.class);
139             if (dob instanceof DataShadow)
140                dob = ((DataShadow)dob).getOriginal();
141             if (dob instanceof DataFolder)
142             {
143                FileObject file = dob.getPrimaryFile();
144                if (file != null)
145                {
146                     String JavaDoc fileName = file.getPackageName(File.separatorChar);
147                     FileSystem fs = null;
148                     StringBuffer JavaDoc buf = null;
149                     try {
150                         fs = file.getFileSystem();
151                     } catch (FileStateInvalidException e) {
152                         System.err.println(e);
153                     }
154                     if (fs != null)
155                     {
156                         buf = new StringBuffer JavaDoc(fs.getSystemName());
157                         if ((fileName != null) && (fileName.length() > 0))
158                         {
159                              buf.append(File.separatorChar).append(fileName);
160                         }
161                         root = buf.toString();
162                         break;
163                     }
164                  }
165              }
166
167         }
168         if ((root != null) && (root.length() > 0))
169            return root;
170        else
171            return null;
172     }
173
174     public FileObject getRootFolder()
175     {
176         FileSystem[] fs = getFileSystems();
177         FileObject root = null;
178         String JavaDoc path = getRootPath();
179         for (int i = 0; i < fs.length; i++)
180         {
181             FileObject sysRoot = fs[i].getRoot();
182             String JavaDoc name = fs[i].getSystemName();
183             if (name.equals(path))
184                 root = sysRoot;
185             else if (path.startsWith(name))
186                 root = sysRoot.getFileObject(path.substring(name.length() + 1));
187             if (root != null)
188                 break;
189         }
190
191         return root;
192     }
193
194     public boolean inProject(String JavaDoc path)
195     {
196         FileSystem[] fs = getFileSystems();
197         FileObject target = null;
198         for (int i = 0; i < fs.length; i++)
199         {
200             FileObject sysRoot = fs[i].getRoot();
201             String JavaDoc name = fs[i].getSystemName();
202             if (name.equals(path))
203                 target = sysRoot;
204             else if (path.startsWith(name))
205                 target = sysRoot.getFileObject(path.substring(name.length() + 1));
206             if (target != null)
207                 return true;
208         }
209         return false;
210     }
211
212     public Object JavaDoc getNativeNode()
213     {
214         return nativeProject;
215     }
216
217     public void setNativeNode(Object JavaDoc node)
218     {
219         nativeProject = (Node)node;
220     }
221
222     public OtterProject getProject()
223     {
224         return this; //unless we support nested projects
225
}
226
227     public OtterNode getParent()
228     {
229         return null; //unless we support nested projects
230
}
231
232     public FileSystem[] getFileSystems()
233     {
234         Vector JavaDoc systems = new Vector JavaDoc();
235
236         Children kids = nativeProject.getChildren();
237         Enumeration JavaDoc nodes = kids.nodes();
238         while (nodes.hasMoreElements())
239         {
240             Node nextNode = (Node)nodes.nextElement();
241             DataObject dob = (DataObject)nextNode.getCookie(DataObject.class);
242             if (dob instanceof DataShadow)
243                 dob = ((DataShadow)dob).getOriginal();
244             if (dob instanceof DataFolder)
245             {
246                 FileObject file = dob.getPrimaryFile();
247                 try {
248                     FileSystem fs = file.getFileSystem();
249                     systems.add(fs);
250                 }catch (FileStateInvalidException e) {
251                     System.err.println(e);
252                 }
253             }
254         }
255
256         return (FileSystem[])systems.toArray(new FileSystem[0]);
257
258     }
259
260
261     public void save()
262     {
263     }
264
265     public String JavaDoc getCodeGenDefaultDestination()
266     {
267         //for now - get the parent of first directory in the project
268
String JavaDoc dest = new String JavaDoc();
269         File JavaDoc file = null;
270
271         file = new File JavaDoc(getRootPath());
272         dest = file.getParent();
273
274         return dest;
275     }
276
277     /**
278      * Find and return first .policy node found in project.
279      */

280     public OtterTextFileNode getFirstPolicy()
281     {
282         PolicyNodeReader reader = new PolicyNodeReader();
283         return reader.getFirstNode(nativeProject);
284     }
285
286     /**
287      * Get working directory for project run.
288      */

289     public String JavaDoc getWorkingPath()
290     {
291         String JavaDoc path = new String JavaDoc();
292
293         path = getProperty(PropertyKeys.NAME_WORKING_DIR);
294         if (path == null || path.length() == 0)
295             path = getRootPath();
296         return path;
297     }
298
299     /**
300      * Set working directory for project run.
301      */

302     public void setWorkingPath(String JavaDoc path)
303     {
304        setProperty(PropertyKeys.NAME_WORKING_DIR, path);
305     }
306
307     public void configureRunClass()
308     {
309         String JavaDoc easRoot = ToolBoxInfo.getEnhydraRoot();
310         String JavaDoc srcDir = XMLCSettings.getDefault().getSource();
311         char sep = File.separatorChar;
312         char psep = File.pathSeparatorChar;
313         RunParameters rp = new RunParameters(this);
314
315         FileObject root = getRootFolder();
316         FileObject src = root.getFileObject(srcDir);
317         if (src == null)
318         {
319             System.out.println("can't get source dir");
320             return;
321         }
322         src.refresh();
323         FileObject file = src.getFileObject("StartServer", "java");
324         if (file == null)
325         {
326             return;
327         }
328         MultiDataObject dob = null;
329         try {
330                 dob = (MultiDataObject)DataObject.find(file);
331         } catch (DataObjectNotFoundException e) {
332             System.err.println(e);
333             return;
334         }
335
336         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
337         KelpExecutor runExec = new KelpExecutor();
338         //DACHA add 17.05.2003
339
buf.append(' ');
340         buf.append(rp.getVMParameters());
341         buf.append(' ');
342         //END DACHA
343
buf.append("-cp \"");
344         buf.append(getSourcePath());
345         buf.append(psep);
346         buf.append(easRoot);
347         buf.append(sep);
348         buf.append("lib");
349         buf.append(sep);
350         buf.append("build");
351         buf.append(sep);
352         buf.append("toolbox.jar");
353         buf.append('\"');
354         buf.append(' ');
355         buf.append(rp.getTCcpArg());
356         buf.append(' ');
357         buf.append(rp.getPolicyArg());
358         buf.append(' ');
359         buf.append(rp.getBootArg());
360         buf.append(" StartServer ");
361         buf.append(rp.getAppParameters());
362
363         runExec.setRunOption(buf.toString());
364         try {
365             ExecSupport.setExecutor(dob.getPrimaryEntry(), runExec);
366         } catch (IOException JavaDoc e) {
367             System.err.println(e);
368         }
369
370     }
371
372     /**
373      * Return all web.xml nodes.
374      */

375     public OtterTextFileNode[] getAllDeploymentDescs()
376     {
377         DeploymentNodeReader reader = new DeploymentNodeReader();
378         return reader.getNodes(nativeProject);
379     }
380
381     /**
382      * Return all nodes that ends with an extension in
383      * the provided extension list.
384      *
385      * @param extensions
386      */

387     public OtterFileNode[] findFileNodesByType(String JavaDoc[] extensions)
388     {
389         NodeReader reader = new NodeReader(extensions);
390         return reader.getNodes(nativeProject);
391     }
392     /**
393      * Get all templates contained in the input directory.
394      */

395     public OtterFileNode[] getAllInput()
396     {
397         String JavaDoc[] ext = new String JavaDoc[0];
398         OtterFileNode[] input = new OtterFileNode[0];
399         OtterFileNode[] nodes = new OtterFileNode[0];
400         Vector JavaDoc nodeVector = new Vector JavaDoc();
401         PathHandle inputPath = null;
402         PathHandle cursorPath = null;
403
404         inputPath = PathHandle.createPathHandle(getDeployInputPath());
405         if (isDeployInputFilter()) {
406             ext = new String JavaDoc[1];
407             ext[0] = Constants.TYPE_IN;
408         }
409         nodes = findFileNodesByType(ext);
410         for (int i = 0; i < nodes.length; i++) {
411             cursorPath = PathHandle.createPathHandle(nodes[i].getFilePath());
412             if (inputPath.parentOf(cursorPath)) {
413                 nodeVector.addElement(nodes[i]);
414             }
415         }
416         input = new OtterFileNode[nodeVector.size()];
417         input = (OtterFileNode[]) nodeVector.toArray(input);
418         nodeVector.clear();
419         return input;
420     }
421
422     /**
423      * Get all document nodes in the project.
424      */

425     public OtterDocumentNode[] getAllDocuments()
426     {
427         DocumentNodeReader reader = new DocumentNodeReader();
428         return reader.getNodes(this);
429
430     }
431
432     /**
433      * Return the IDE implementation of the project node.
434      */

435     public Object JavaDoc getNativeProject()
436     {
437         return nativeProject;
438     }
439
440     /**
441      * Does IDE allow for integrated build.
442      */

443     public boolean isOpenBuild()
444     {
445         return false; //for now
446
}
447
448     /**
449      * Method declaration
450      *
451      * @return
452      */

453     public String JavaDoc getClassOutputPath()
454     {
455         return getSourcePath();
456     }
457
458     public void setClassOutputPath(String JavaDoc p)
459     {
460
461     }
462
463     //
464
public boolean isDefaultProject()
465     {
466         return false;
467     }
468
469     /**
470      * Method declaration
471      *
472      * @return
473      */

474     public String JavaDoc getSourcePath()
475     {
476         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
477         String JavaDoc src = XMLCSettings.getDefault().getSource();
478         buf.append(getRootPath()).append(File.separatorChar).append(src);
479 /*
480         buf.append(getRootPath()).append(File.separatorChar).append(src).append(File.separatorChar);
481 */

482         return buf.toString() ;
483     }
484     /**
485      * Method declaration
486      *
487      * @return
488      */

489     public String JavaDoc[] getSourcePathArray()
490     {
491         String JavaDoc in = (String JavaDoc)XMLCSettings.getDefault().propertyValue(SOURCE_PATH_ARRAY);
492         if (in != null && in.length() > 0)
493             return PropUtil.listToArray(in, new String JavaDoc[0]);
494         else
495             return new String JavaDoc[] {getRootPath()};
496
497 /* Children kids = nativeProject.getChildren();
498         Node nodes[] = kids.getNodes();
499         String paths[] = new String[nodes.length];
500         for (int i = 0; i < nodes.length; i++)
501         {
502             DataObject dob = (DataObject)nodes[i].getCookie(DataObject.class);
503             if (dob instanceof DataShadow)
504                 dob = ((DataShadow)dob).getOriginal();
505             if (dob instanceof DataFolder)
506             {
507                 FileObject file = dob.getPrimaryFile();
508                 try {
509                     FileSystem fs = file.getFileSystem();
510                     paths[i] = fs.getDisplayName();
511                 } catch (FileStateInvalidException e) {
512                     System.err.println(e);
513                 }
514             }
515
516         }
517         return paths;*/

518     }
519
520     /**
521      * Method declaration
522      *
523      * @param pathAsArray
524      */

525     public void setSourcePathArray(String JavaDoc[] pathAsArray)
526     {
527         String JavaDoc out = PropUtil.arrayToList(pathAsArray);
528         XMLCSettings.getDefault().setProperty(SOURCE_PATH_ARRAY, out);
529     }
530
531     /**
532      * Method declaration
533      *
534      *
535      * @return
536      */

537     public String JavaDoc getClassPath()
538     {
539         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
540
541         //I think there's a better way to do this, but....
542
//here are the paths added by user via the filesystem:
543
Enumeration JavaDoc fss = TopManager.getDefault().getRepository().getFileSystems();
544         while (fss.hasMoreElements ())
545         {
546             FileSystem fs = (FileSystem) fss.nextElement ();
547             buf = buf.append(fs.getSystemName());
548             buf = buf.append(File.pathSeparatorChar);
549         }
550         //these are on the ide classpath and they are available to the project - which seems wierd
551
buf.append(NbClassPath.createClassPath().getClassPath());
552         return buf.toString();
553     }
554
555     public boolean cpContains(String JavaDoc target)
556     {
557         StringTokenizer JavaDoc tokenizer= new StringTokenizer JavaDoc(getClassPath(), File.pathSeparator);
558         String JavaDoc cur = null;
559         while (tokenizer.hasMoreTokens())
560         {
561             try{
562                 cur = tokenizer.nextToken();
563             } catch (NoSuchElementException JavaDoc e) {
564                 break;
565             }
566
567             if (cur.equals(target))
568                 return true;
569         }
570         return false;
571     }
572     /**
573      * Method declaration
574      *
575      * @param property
576      *
577      * @return
578      */

579     public String JavaDoc getProperty(String JavaDoc property)
580     {
581         if (property.startsWith("enhydra.xmlc"))
582             return XMLCSettings.getDefault().propertyValue(property);
583         else
584             return DeploySettings.getDefault().propertyValue(property);
585     }
586
587     /**
588      * Method declaration
589      *
590      * @param property
591      * @param value
592      */

593     public void setProperty(String JavaDoc property, String JavaDoc value)
594     {
595         if (property.startsWith("enhydra.xmlc"))
596             XMLCSettings.getDefault().setProperty(property, value);
597         else
598             DeploySettings.getDefault().setProperty(property, value);
599     }
600
601     /**
602      * Method declaration
603      *
604      * @param property
605      * @param value
606      */

607     public void setProperty(String JavaDoc property, int value)
608     {
609         setProperty(property, Integer.toString(value));
610     }
611
612     // override OtterProject
613
public boolean isDeployStartupJavaReadOnly() {
614        return true;
615     }
616
617
618
619    class DeploymentNodeReader {
620         private Vector JavaDoc nodeVector = new Vector JavaDoc();
621
622     /**
623      * Constructor declaration
624      *
625      */

626         protected DeploymentNodeReader() {}
627
628         /**
629          * Method declaration
630          *
631          *
632          * @param nativeProject
633          *
634          * @return
635         */

636        protected OtterTemplateNode[] getNodes(Node nativeProject) {
637             OtterTemplateNode[] nodes = new OtterTemplateNode[0];
638
639             Node project = nativeProject;
640             nodeVector.clear();
641
642             FileObject root = getRootFolder();
643             if (root != null)
644                 readFiles(root);
645             nodes = new OtterTemplateNode[nodeVector.size()];
646             nodes = (OtterTemplateNode[])nodeVector.toArray(nodes);
647             nodeVector.clear();
648             return nodes;
649         }
650
651         /**
652          * Method declaration
653          *
654          *
655          * @param container
656          */

657         private void readFiles(FileObject container) {
658
659             FileObject[] children = container.getChildren();
660             for (int i = 0; i < children.length; i++)
661             {
662                 if (children[i].isData())
663                 {
664                     String JavaDoc ext = children[i].getExt();
665                     if (((ext.equals(Constants.FILE_WEB_XML))
666                            || (ext.equals(Constants.FILE_EJB_JAR_XML))))
667                     {
668                         ForteTemplateNode node = null;
669                         try{
670                             DataObject dob = DataObject.find(children[i]);
671                             if (dob instanceof DeployDataObject) //just to be sure
672
try {
673                                     node = new ForteTemplateNode((DeployDataObject)dob);
674                                 } catch (ToolException e) {
675                                    System.err.println(e);
676                                 }
677                                 if (node != null)
678                                   nodeVector.add(node);
679                             }
680                         catch(DataObjectNotFoundException e) {
681                                 System.err.println(e);
682                             }
683
684                     }
685
686                 }
687                 else if (children[i].isFolder())
688                     readFiles(children[i]);
689
690             }
691         }
692
693     }
694
695     class DocumentNodeReader {
696         private Vector JavaDoc nodeVector = new Vector JavaDoc();
697         private Node project = null;
698         private String JavaDoc[] docTypes = new String JavaDoc[0];
699
700         /**
701          * Constructor declaration
702          *
703          */

704         protected DocumentNodeReader() {}
705
706         /**
707          * Method declaration
708          *
709          *
710          * @param nativeProject
711          *
712          * @return
713          */

714         protected OtterDocumentNode[] getNodes(OtterProject p) {
715             OtterDocumentNode[] nodes = new OtterDocumentNode[0];
716             project = (Node)p.getNativeNode();
717             docTypes = p.getDocTypes();
718             nodeVector.clear();
719             FileObject root = getRootFolder();
720             if (root != null)
721                 readFiles(root);
722             nodes = new OtterDocumentNode[nodeVector.size()];
723             nodes = (OtterDocumentNode[]) nodeVector.toArray(nodes);
724             nodeVector.clear();
725             return nodes;
726         }
727
728         /**
729          * Method declaration
730          *
731          *
732          * @param container
733          */

734         private void readFiles(FileObject container) {
735
736             FileObject[] children = container.getChildren();
737             for (int i = 0; i < children.length; i++)
738             {
739                 if (children[i].isData())
740                 {
741                     if (isTarget(children[i].getExt()))
742                     {
743                         try
744                         {
745                             DataObject dob = DataObject.find(children[i]);
746                             if (dob instanceof XMLCDataObject) //just to be sure
747
nodeVector.add(new ForteDocumentNode((XMLCDataObject)dob));
748                         }
749                         catch(DataObjectNotFoundException e) {
750                             System.err.println(e);
751                         }
752                     }
753
754                 }
755                 else if (children[i].isFolder())
756                     readFiles(children[i]);
757
758             }
759         }
760
761         protected boolean isTarget(String JavaDoc ext)
762         {
763              for (int j = 0; j < docTypes.length; j++)
764              {
765                  if (ext.equals(docTypes[j]))
766                     return true;
767              }
768              return false;
769         }
770
771     }
772
773     class NodeReader {
774         private Vector JavaDoc nodeVector = new Vector JavaDoc();
775         private String JavaDoc[] extensions = new String JavaDoc[0];
776
777         /**
778          * Constructor declaration
779          *
780          *
781          * @param exts
782          */

783         protected NodeReader(String JavaDoc[] exts) {
784            extensions = exts;
785         }
786
787         /**
788         * Method declaration
789         *
790         *
791         * @param nativeProject
792          *
793          * @return
794          */

795         protected OtterFileNode[] getNodes(Node nativeProject) {
796             OtterFileNode[] nodes = new OtterFileNode[0];
797             Node project = nativeProject;
798             nodeVector.clear();
799             FileObject root = getRootFolder();
800             if (root != null)
801                 readFiles(root);
802             nodes = new OtterFileNode[nodeVector.size()];
803             nodes = (OtterFileNode[]) nodeVector.toArray(nodes);
804             nodeVector.clear();
805             return nodes;
806         }
807
808         /**
809          * Method declaration
810          *
811          *
812          * @param container
813          */

814         private void readFiles(FileObject container) {
815             FileObject[] children = container.getChildren();
816             for (int i = 0; i < children.length; i++)
817             {
818                 if (children[i].isData())
819                 {
820                     if (isTarget(children[i].getExt()) || (extensions.length == 0))
821                     {
822                         DataObject dob = null;
823                         try
824                         {
825                             dob = DataObject.find(children[i]);
826                         }
827                         catch(DataObjectNotFoundException e) {
828                             System.err.println(e);
829                         }
830
831                         if (dob instanceof XMLCDataObject)
832                             nodeVector.add(new ForteDocumentNode((XMLCDataObject)dob));
833                         else if (dob instanceof DeployDataObject)
834                         {
835                             try{
836                                 nodeVector.add(new ForteTemplateNode((DeployDataObject)dob));
837                             } catch (ToolException e){
838                                 System.err.println(e);
839                             }
840                         }
841
842                         else if (dob instanceof TXTDataObject)
843                             nodeVector.add(new ForteTextFileNode((TXTDataObject)dob));
844                         else
845                             nodeVector.add(new ForteNode(dob));
846
847                     }
848
849                 }
850                 else if (children[i].isFolder())
851                     readFiles(children[i]);
852
853             }
854         }
855
856         protected boolean isTarget(String JavaDoc ext)
857         {
858              for (int j = 0; j < extensions.length; j++)
859              {
860                  if (ext.equals(extensions[j]))
861                     return true;
862              }
863              return false;
864         }
865     }
866
867    class PolicyNodeReader {
868         private OtterTextFileNode node = null;
869
870         /**
871          * Method declaration
872          *
873          *
874          * @param nativeProject
875          *
876          * @return
877          */

878         protected OtterTextFileNode getFirstNode(Node nativeProject) {
879             TXTDataObject target = null;
880
881             FileObject root = getRootFolder();
882             if (root != null)
883                 target = recursiveRead(root);
884             if (target != null)
885                 return new ForteTextFileNode(target);
886             else return null;
887         }
888
889         /**
890          * Method declaration
891          *
892          *
893          * @param container
894          */

895         private TXTDataObject recursiveRead(FileObject container) {
896
897             FileObject[] children = container.getChildren();
898
899             for (int i = 0; i < children.length; i++)
900             {
901
902                 if (children[i].isData())
903                 {
904                     if (children[i].getExt().equals(Constants.FILE_JAVA_POLICY))
905                     {
906                         try{
907                             DataObject dob = DataObject.find(children[i]);
908                             return (TXTDataObject)dob;
909                         } catch(DataObjectNotFoundException e) {
910                             System.err.println(e);
911                         }
912                     }
913                 }
914
915                if (children[i].isFolder())
916                    return recursiveRead(children[i]);
917
918
919             }
920             return null;
921         }
922     }
923
924     /**
925     * Method declaration
926     *
927     *
928     * @param container
929     */

930     public void setEnhydraPath() {
931 //Dusan 20.11.02.
932
String JavaDoc enhydraPath = getClassPath();
933         enhydraPath = enhydraPath.substring(0, enhydraPath.indexOf("enhydra.jar")-5);
934         enhydraPath = enhydraPath.substring(enhydraPath.lastIndexOf(";")+1,
935           enhydraPath.length());
936         setProperty(DODS_ENHYDRA_PATH, enhydraPath);
937     }
938
939 }
940
Popular Tags