KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > ejb > DDCreator


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.taskdefs.optional.ejb;
19
20 import java.io.File JavaDoc;
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.DirectoryScanner;
23 import org.apache.tools.ant.taskdefs.Java;
24 import org.apache.tools.ant.taskdefs.MatchingTask;
25 import org.apache.tools.ant.types.Commandline;
26 import org.apache.tools.ant.types.Path;
27 import org.apache.tools.ant.util.FileUtils;
28
29 /**
30  * Builds a serialized deployment descriptor given a text file description of the
31  * descriptor in the format supported by WebLogic.
32  *
33  * This ant task is a front end for the weblogic DDCreator tool.
34  *
35  */

36 public class DDCreator extends MatchingTask {
37     /**
38      * The root directory of the tree containing the textual deployment descriptors. The actual
39      * deployment descriptor files are selected using include and exclude constructs
40      * on the EJBC task, as supported by the MatchingTask superclass.
41      */

42     private File JavaDoc descriptorDirectory;
43
44     /**
45      * The directory where generated serialised deployment descriptors are placed.
46      */

47     private File JavaDoc generatedFilesDirectory;
48
49     /**
50      * The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
51      * classes necessary fro DDCreator <b>and</b> the implementation classes of the
52      * home and remote interfaces.
53      */

54     private String JavaDoc classpath;
55
56     /**
57      * Do the work.
58      *
59      * The work is actually done by creating a helper task. This approach allows
60      * the classpath of the helper task to be set. Since the weblogic tools require
61      * the class files of the project's home and remote interfaces to be available in
62      * the classpath, this also avoids having to start ant with the class path of the
63      * project it is building.
64      *
65      * @exception BuildException if something goes wrong with the build
66      */

67     public void execute() throws BuildException {
68         if (descriptorDirectory == null
69             || !descriptorDirectory.isDirectory()) {
70             throw new BuildException("descriptors directory "
71                 + descriptorDirectory.getPath() + " is not valid");
72         }
73         if (generatedFilesDirectory == null
74             || !generatedFilesDirectory.isDirectory()) {
75             throw new BuildException("dest directory "
76                 + generatedFilesDirectory.getPath() + " is not valid");
77         }
78
79         String JavaDoc args = descriptorDirectory + " " + generatedFilesDirectory;
80
81         // get all the files in the descriptor directory
82
DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory);
83
84         String JavaDoc[] files = ds.getIncludedFiles();
85
86         for (int i = 0; i < files.length; ++i) {
87             args += " " + files[i];
88         }
89
90         String JavaDoc systemClassPath = System.getProperty("java.class.path");
91         String JavaDoc execClassPath = FileUtils.translatePath(systemClassPath + ":" + classpath);
92         Java ddCreatorTask = new Java(this);
93         ddCreatorTask.setFork(true);
94         ddCreatorTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.DDCreatorHelper");
95         Commandline.Argument arguments = ddCreatorTask.createArg();
96         arguments.setLine(args);
97         ddCreatorTask.setClasspath(new Path(getProject(), execClassPath));
98         if (ddCreatorTask.executeJava() != 0) {
99             throw new BuildException("Execution of ddcreator helper failed");
100         }
101     }
102
103     /**
104      * Set the directory from where the text descriptions of the deployment descriptors are
105      * to be read.
106      *
107      * @param dirName the name of the directory containing the text deployment descriptor files.
108      */

109     public void setDescriptors(String JavaDoc dirName) {
110         descriptorDirectory = new File JavaDoc(dirName);
111     }
112
113     /**
114      * Set the directory into which the serialized deployment descriptors are to
115      * be written.
116      *
117      * @param dirName the name of the directory into which the serialised deployment
118      * descriptors are written.
119      */

120     public void setDest(String JavaDoc dirName) {
121         generatedFilesDirectory = new File JavaDoc(dirName);
122     }
123
124     /**
125      * Set the classpath to be used for this compilation.
126      *
127      * @param s the classpath to use for the ddcreator tool.
128      */

129     public void setClasspath(String JavaDoc s) {
130         this.classpath = FileUtils.translatePath(s);
131     }
132 }
133
Popular Tags