KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > ddgenerator > sun > EjbModule


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * $Id: EjbModule.java,v 1.5 2005/12/25 04:27:36 tcfujii Exp $
26  */

27
28 package com.sun.enterprise.ddgenerator.sun;
29
30 import java.util.*;
31 import java.io.File JavaDoc;
32
33 import com.sun.enterprise.deployment.*;
34 import com.sun.enterprise.deployment.io.DescriptorConstants;
35 import com.sun.enterprise.util.io.FileUtils;
36
37 import com.sun.enterprise.deployment.archivist.*;
38 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
39 import com.sun.enterprise.deployment.interfaces.*;
40
41 /**
42  * Class description
43  *
44  * @author Sreenivas Munnangi
45  */

46
47 public class EjbModule implements DDGenerator {
48
49     private EjbBundleDescriptor ejbBundleDescriptor = null;
50     private String JavaDoc applicationDirectory = null;
51
52     public EjbModule () {
53     }
54
55     public EjbModule (EjbBundleDescriptor ejbBundleDescriptor, String JavaDoc applicationDirectory) {
56     this.ejbBundleDescriptor = ejbBundleDescriptor;
57     this.applicationDirectory = applicationDirectory;
58     }
59
60     public void setApplicationDirectory(String JavaDoc applicationDirectory) {
61     this.applicationDirectory = applicationDirectory;
62     }
63
64     public void setDescriptor(com.sun.enterprise.deployment.Descriptor descriptor) {
65     this.ejbBundleDescriptor = (com.sun.enterprise.deployment.EjbBundleDescriptor) descriptor;
66     }
67
68     public void generate() {
69     if (ejbBundleDescriptor == null) return;
70
71     java.util.Set JavaDoc ejbDescriptors = ejbBundleDescriptor.getEjbs();
72
73     for (Iterator it = ejbDescriptors.iterator(); it.hasNext();) {
74         EjbDescriptor ejbDescriptor = (EjbDescriptor) it.next();
75         String JavaDoc jndiName = ejbDescriptor.getJndiName();
76         if ((jndiName == null) || (jndiName.length() <1)) {
77             String JavaDoc homeName = ejbDescriptor.getHomeClassName();
78             ejbDescriptor.setJndiName(homeName);
79         }
80     }
81
82     }
83
84     public boolean hasSunDescriptor() {
85     
86     File JavaDoc file = getSunDescriptorFile();
87
88     if (file == null) return false;
89
90     if (file.exists()) {
91         return true;
92     }
93
94     return false;
95     }
96
97     public void backupSunDescriptor() {
98
99     File JavaDoc file = getSunDescriptorFile();
100
101     if (file == null) return;
102
103     if (file.exists()) {
104         try {
105         FileUtils.copy(file, new File JavaDoc(file.getAbsolutePath() + ".bak"));
106         } catch (java.io.IOException JavaDoc ioe) {
107         }
108     }
109
110     }
111
112
113     private File JavaDoc getSunDescriptorFile () {
114     
115     File JavaDoc file = null;
116
117     String JavaDoc archiveUri = ejbBundleDescriptor.getModuleDescriptor().getArchiveUri();
118
119     String JavaDoc friendlyFileName = FileUtils.makeFriendlyFilename(archiveUri);
120
121     String JavaDoc sunXmlFileName = (applicationDirectory + File.separator +
122                  friendlyFileName + File.separator +
123                  com.sun.enterprise.deployment.io.DescriptorConstants.S1AS_EJB_DD_ENTRY);
124
125     file = new File JavaDoc(sunXmlFileName);
126
127     return file;
128     }
129
130     public static void main (String JavaDoc args[]) {
131
132         System.out.println("Ejb");
133
134     String JavaDoc appDir = "/home/sreeni/TEMP/stateless-converterEjb_1";
135
136         System.out.println("Press enter to continue ...");
137     try {
138         System.in.read();
139     } catch (java.io.IOException JavaDoc ioe) {
140     }
141
142     FileArchive in = new FileArchive();
143
144     try {
145         in.open(appDir);
146     } catch (java.io.IOException JavaDoc ioe) {
147     }
148
149
150     EjbArchivist ejbArchivist = new EjbArchivist();
151     ejbArchivist.setXMLValidation(false);
152     ejbArchivist.setClassLoader(null);
153
154     com.sun.enterprise.deployment.Application application = null;
155     try {
156         application = (com.sun.enterprise.deployment.Application)
157             ApplicationArchivist.openArchive(ejbArchivist, in, true);
158     } catch (java.io.IOException JavaDoc ioe) {
159     } catch (org.xml.sax.SAXParseException JavaDoc saxpe) {
160     }
161
162     com.sun.enterprise.ddgenerator.sun.Application app =
163         new com.sun.enterprise.ddgenerator.sun.Application(application, appDir);
164
165     app.generate();
166     }
167
168 }
169
Popular Tags