001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: BeanNaming.java 5445 2004-09-17 08:25:02Z joaninh $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.lib;
025:
026: import java.io.File;
027: import java.lang.reflect.Method;
028: import java.util.StringTokenizer;
029:
030: import javax.security.jacc.EJBMethodPermission;
031:
032: /**
033: * This class is made for hiding Naming convention in all JOnAS framework. <br>
034: * (Among other things, names of the implementation classes of the Enterprise
035: * Bean's Home and Enterprise Bean Remote interfaces generated by the GenIC
036: * tools.) <br>
037: * It is used by the EJB generation tools and framework
038: *
039: * @author Helene Joanin
040: * @author Joe Gittings has proposed to code method signature in order to avoid same signature for inherited methods
041: * @author Christophe Ney [cney@batisseurs.com]
042: * @author Sebastien Chassande-Barrioz
043: */
044: public class BeanNaming {
045:
046: /**
047: * returns the name of the package of the given full name
048: */
049: public static String getPackageName(String name) {
050: if (name == null) {
051: return null;
052: }
053: int idx = name.lastIndexOf('.');
054: return (idx == -1 ? "" : name.substring(0, idx));
055: }
056:
057: /**
058: * return full name of a class for given package and class names
059: *
060: * @param packageName
061: * possibly empty package name
062: * @param name
063: * class name
064: * @return fully qualified class name
065: */
066: public static String getClassName(String packageName, String name) {
067: return (packageName.length() == 0) ? name : packageName + "."
068: + name;
069: }
070:
071: /**
072: * returns the basename of the given full name
073: */
074: public static String getBaseName(String fullName) {
075: String baseName = null;
076: if (fullName != null) {
077: int idx = fullName.lastIndexOf('.');
078: int len = fullName.length();
079: if (idx == -1) {
080: baseName = fullName;
081: } else {
082: if (idx != (len - 1)) {
083: baseName = fullName.substring(idx + 1, len);
084: } else {
085: baseName = "";
086: }
087: }
088: }
089: return baseName;
090: }
091:
092: /**
093: * returns the full path of the file name. mainly replace '.' by '/'.
094: */
095: public static String getPath(String fullName) {
096: String pkg = new String();
097: StringTokenizer stk = new StringTokenizer(fullName, ".");
098: int nb = stk.countTokens();
099: for (int i = 0; i < nb; i++) {
100: pkg = pkg.concat(stk.nextToken());
101: if (i < nb - 1) {
102: pkg = pkg + File.separatorChar;
103: }
104: }
105: return pkg;
106: }
107:
108: /**
109: * returns the given string with the first character converted to upper case
110: */
111: public static String firstToUpperCase(String s) {
112: String value;
113: if (s.length() > 0) {
114: char c = Character.toUpperCase(s.charAt(0));
115: value = new String(c + s.substring(1));
116: } else {
117: value = new String();
118: }
119: return (value);
120: }
121:
122: /**
123: * returns the name of the JOnAS specific deployment descriptor file's name
124: * corresponding to the given standard deployment descriptor file's name.
125: * (ex: returns "jonas-XXX.xml" for "XXX.xml" and "../../jonas-XXX.xml" for
126: * "../../XXX.xml")
127: */
128: public static String getJonasXmlName(String stdXmlName) {
129:
130: String jonasXmlName = new String();
131: File f = new File(stdXmlName);
132: String p = f.getParent();
133: String n = f.getName();
134: if (p != null) {
135: jonasXmlName = jonasXmlName.concat(p);
136: jonasXmlName = jonasXmlName.concat(File.separator);
137: }
138: jonasXmlName = jonasXmlName.concat("jonas-");
139: jonasXmlName = jonasXmlName.concat(n);
140:
141: return (jonasXmlName);
142: }
143:
144: /**
145: * returns the name of the parent directory
146: */
147: public static String getParentName(String fileName) {
148: File f = new File(fileName);
149: return f.getParent();
150: }
151:
152: /**
153: * Gets a string that represents the signature of a method
154: *
155: * @param ejbName
156: * name of the ejb
157: * @param method
158: * Method on which the signature is required
159: * @return string that represents the signature of a method
160: */
161: public static String getSignature(String ejbName, Method method) {
162:
163: Class clazz = method.getDeclaringClass();
164: String methItf = "";
165:
166: if (javax.ejb.EJBHome.class.isAssignableFrom(clazz)) {
167: methItf = "Home";
168: } else if (javax.ejb.EJBObject.class.isAssignableFrom(clazz)) {
169: methItf = "Remote";
170: } else if (javax.ejb.EJBLocalHome.class.isAssignableFrom(clazz)) {
171: methItf = "LocalHome";
172: } else if (javax.ejb.EJBLocalObject.class
173: .isAssignableFrom(clazz)) {
174: methItf = "Local";
175: } else if (java.rmi.Remote.class.isAssignableFrom(clazz)) {
176: methItf = "ServiceEndpoint";
177: }
178:
179: return new EJBMethodPermission(ejbName, methItf, method)
180: .getActions();
181: }
182: }
|