KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > codegen > GeneratedNames


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 package com.sun.ejb.codegen;
24
25 import java.io.File JavaDoc;
26 import com.sun.enterprise.deployment.EjbDescriptor;
27
28 /**
29  * Helper class for ejbc generated class names.
30  *
31  * @author Nazrul Islam
32  * @since JDK 1.4
33  */

34 public class GeneratedNames {
35
36     /**
37      * Initializes the generated names based on the given
38      * deployment descriptor.
39      *
40      * @param desc deployment descriptor
41      */

42     public GeneratedNames(EjbDescriptor desc) {
43         // Set the file names for generated Home/Remote impl/tie/stubs
44

45         // set EJBOBject Impl
46
ejbObjectImplClass =
47             desc.getEJBObjectImplClassName().replace('.',
48                                 File.separatorChar) + ".class";
49        
50         // set EJBHome Impl
51
homeImplClass =
52             desc.getRemoteHomeImplClassName().replace('.',
53                                     File.separatorChar) + ".class";
54
55         // Set EJBHome/EJBObject stub filenames
56
homeStubClass =
57             getStubName(desc.getHomeClassName()).replace('.',
58                                     File.separatorChar) + ".class";
59         remoteStubClass =
60             getStubName(desc.getRemoteClassName()).replace('.',
61                                     File.separatorChar) + ".class";
62     }
63      
64     /**
65      * Returns the stub classname for the given interface name
66      *
67      * @param fullName fully qualified name of the ejb home and obj impl
68      */

69     public static String JavaDoc getStubName(String JavaDoc fullName) {
70
71         String JavaDoc className = fullName;
72         String JavaDoc packageName = "";
73
74         int lastDot = fullName.lastIndexOf('.');
75         if (lastDot != -1) {
76             className = fullName.substring(lastDot+1, fullName.length());
77             packageName = fullName.substring(0, lastDot+1);
78         }
79
80         String JavaDoc stubName = packageName + "_" + className + "_Stub";
81
82         if(isSpecialPackage(fullName))
83             stubName = ORG_OMG_STUB_PREFIX + stubName;
84
85         return stubName;
86     }
87
88     public String JavaDoc getEjbObjectImplClass() {
89         return ejbObjectImplClass;
90     }
91
92     public String JavaDoc getHomeImplClass() {
93         return homeImplClass;
94     }
95
96     public String JavaDoc getHomeStubClass() {
97         return homeStubClass;
98     }
99
100     public String JavaDoc getRemoteStubClass() {
101         return remoteStubClass;
102     }
103
104     private static boolean isSpecialPackage(String JavaDoc name)
105     {
106         // these package names are magic. RMIC puts any home/remote stubs
107
// into a different directory in these cases.
108
// 4845896 bnevins, April 2003
109

110         // this is really an error. But we have enough errors. Let's be forgiving
111
// and not allow a NPE out of here...
112
if(name == null)
113             return false;
114         
115         // Licensee bug 4959550
116
// if(name.startsWith("com.sun.") || name.startsWith("javax."))
117
if(name.startsWith("javax."))
118             return true;
119         
120         return false;
121     }
122
123     // ---- INSTANCE VARIABLES - PRIVATE ---------------------------------
124
private String JavaDoc homeImplClass;
125     private String JavaDoc homeStubClass;
126     private String JavaDoc remoteStubClass;
127     private String JavaDoc ejbObjectImplClass;
128
129     private static final String JavaDoc ORG_OMG_STUB_PREFIX = "org.omg.stub.";
130 }
131
Popular Tags