KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > lib > BeanNaming


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: BeanNaming.java,v 1.12 2004/09/17 08:25:02 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.lib;
27
28 import java.io.File JavaDoc;
29 import java.lang.reflect.Method JavaDoc;
30 import java.util.StringTokenizer JavaDoc;
31
32 import javax.security.jacc.EJBMethodPermission JavaDoc;
33
34 /**
35  * This class is made for hiding Naming convention in all JOnAS framework. <br>
36  * (Among other things, names of the implementation classes of the Enterprise
37  * Bean's Home and Enterprise Bean Remote interfaces generated by the GenIC
38  * tools.) <br>
39  * It is used by the EJB generation tools and framework
40  *
41  * @author Helene Joanin
42  * @author Joe Gittings has proposed to code method signature in order to avoid same signature for inherited methods
43  * @author Christophe Ney [cney@batisseurs.com]
44  * @author Sebastien Chassande-Barrioz
45  */

46 public class BeanNaming {
47
48     /**
49      * returns the name of the package of the given full name
50      */

51     public static String JavaDoc getPackageName(String JavaDoc name) {
52         if (name == null) { return null; }
53         int idx = name.lastIndexOf('.');
54         return (idx == -1 ? "" : name.substring(0, idx));
55     }
56
57     /**
58      * return full name of a class for given package and class names
59      *
60      * @param packageName
61      * possibly empty package name
62      * @param name
63      * class name
64      * @return fully qualified class name
65      */

66     public static String JavaDoc getClassName(String JavaDoc packageName, String JavaDoc name) {
67         return (packageName.length() == 0) ? name : packageName + "." + name;
68     }
69
70     /**
71      * returns the basename of the given full name
72      */

73     public static String JavaDoc getBaseName(String JavaDoc fullName) {
74         String JavaDoc baseName = null;
75         if (fullName != null) {
76             int idx = fullName.lastIndexOf('.');
77             int len = fullName.length();
78             if (idx == -1) {
79                 baseName = fullName;
80             } else {
81                 if (idx != (len - 1)) {
82                     baseName = fullName.substring(idx + 1, len);
83                 } else {
84                     baseName = "";
85                 }
86             }
87         }
88         return baseName;
89     }
90
91     /**
92      * returns the full path of the file name. mainly replace '.' by '/'.
93      */

94     public static String JavaDoc getPath(String JavaDoc fullName) {
95         String JavaDoc pkg = new String JavaDoc();
96         StringTokenizer JavaDoc stk = new StringTokenizer JavaDoc(fullName, ".");
97         int nb = stk.countTokens();
98         for (int i = 0; i < nb; i++) {
99             pkg = pkg.concat(stk.nextToken());
100             if (i < nb - 1) {
101                 pkg = pkg + File.separatorChar;
102             }
103         }
104         return pkg;
105     }
106
107     /**
108      * returns the given string with the first character converted to upper case
109      */

110     public static String JavaDoc firstToUpperCase(String JavaDoc s) {
111         String JavaDoc value;
112         if (s.length() > 0) {
113             char c = Character.toUpperCase(s.charAt(0));
114             value = new String JavaDoc(c + s.substring(1));
115         } else {
116             value = new String JavaDoc();
117         }
118         return (value);
119     }
120
121     /**
122      * returns the name of the JOnAS specific deployment descriptor file's name
123      * corresponding to the given standard deployment descriptor file's name.
124      * (ex: returns "jonas-XXX.xml" for "XXX.xml" and "../../jonas-XXX.xml" for
125      * "../../XXX.xml")
126      */

127     public static String JavaDoc getJonasXmlName(String JavaDoc stdXmlName) {
128
129         String JavaDoc jonasXmlName = new String JavaDoc();
130         File JavaDoc f = new File JavaDoc(stdXmlName);
131         String JavaDoc p = f.getParent();
132         String JavaDoc n = f.getName();
133         if (p != null) {
134             jonasXmlName = jonasXmlName.concat(p);
135             jonasXmlName = jonasXmlName.concat(File.separator);
136         }
137         jonasXmlName = jonasXmlName.concat("jonas-");
138         jonasXmlName = jonasXmlName.concat(n);
139
140         return (jonasXmlName);
141     }
142
143     /**
144      * returns the name of the parent directory
145      */

146     public static String JavaDoc getParentName(String JavaDoc fileName) {
147         File JavaDoc f = new File JavaDoc(fileName);
148         return f.getParent();
149     }
150
151     /**
152      * Gets a string that represents the signature of a method
153      *
154      * @param ejbName
155      * name of the ejb
156      * @param method
157      * Method on which the signature is required
158      * @return string that represents the signature of a method
159      */

160     public static String JavaDoc getSignature(String JavaDoc ejbName, Method JavaDoc method) {
161
162         Class JavaDoc clazz = method.getDeclaringClass();
163         String JavaDoc methItf = "";
164
165         if (javax.ejb.EJBHome JavaDoc.class.isAssignableFrom(clazz)) {
166             methItf = "Home";
167         } else if (javax.ejb.EJBObject JavaDoc.class.isAssignableFrom(clazz)) {
168             methItf = "Remote";
169         } else if (javax.ejb.EJBLocalHome JavaDoc.class.isAssignableFrom(clazz)) {
170             methItf = "LocalHome";
171         } else if (javax.ejb.EJBLocalObject JavaDoc.class.isAssignableFrom(clazz)) {
172             methItf = "Local";
173         } else if (java.rmi.Remote JavaDoc.class.isAssignableFrom(clazz)) {
174             methItf = "ServiceEndpoint";
175         }
176
177         return new EJBMethodPermission JavaDoc(ejbName, methItf, method).getActions();
178     }
179 }
180
181
Popular Tags