00001 00026 package org.objectweb.jonas_ejb.lib; 00027 00028 import java.io.File; 00029 import java.lang.reflect.Method; 00030 import java.util.StringTokenizer; 00031 00032 import javax.security.jacc.EJBMethodPermission; 00033 00046 public class BeanNaming { 00047 00051 public static String getPackageName(String name) { 00052 if (name == null) { return null; } 00053 int idx = name.lastIndexOf('.'); 00054 return (idx == -1 ? "" : name.substring(0, idx)); 00055 } 00056 00066 public static String getClassName(String packageName, String name) { 00067 return (packageName.length() == 0) ? name : packageName + "." + name; 00068 } 00069 00073 public static String getBaseName(String fullName) { 00074 String baseName = null; 00075 if (fullName != null) { 00076 int idx = fullName.lastIndexOf('.'); 00077 int len = fullName.length(); 00078 if (idx == -1) { 00079 baseName = fullName; 00080 } else { 00081 if (idx != (len - 1)) { 00082 baseName = fullName.substring(idx + 1, len); 00083 } else { 00084 baseName = ""; 00085 } 00086 } 00087 } 00088 return baseName; 00089 } 00090 00094 public static String getPath(String fullName) { 00095 String pkg = new String(); 00096 StringTokenizer stk = new StringTokenizer(fullName, "."); 00097 int nb = stk.countTokens(); 00098 for (int i = 0; i < nb; i++) { 00099 pkg = pkg.concat(stk.nextToken()); 00100 if (i < nb - 1) { 00101 pkg = pkg + File.separatorChar; 00102 } 00103 } 00104 return pkg; 00105 } 00106 00110 public static String firstToUpperCase(String s) { 00111 String value; 00112 if (s.length() > 0) { 00113 char c = Character.toUpperCase(s.charAt(0)); 00114 value = new String(c + s.substring(1)); 00115 } else { 00116 value = new String(); 00117 } 00118 return (value); 00119 } 00120 00127 public static String getJonasXmlName(String stdXmlName) { 00128 00129 String jonasXmlName = new String(); 00130 File f = new File(stdXmlName); 00131 String p = f.getParent(); 00132 String n = f.getName(); 00133 if (p != null) { 00134 jonasXmlName = jonasXmlName.concat(p); 00135 jonasXmlName = jonasXmlName.concat(File.separator); 00136 } 00137 jonasXmlName = jonasXmlName.concat("jonas-"); 00138 jonasXmlName = jonasXmlName.concat(n); 00139 00140 return (jonasXmlName); 00141 } 00142 00146 public static String getParentName(String fileName) { 00147 File f = new File(fileName); 00148 return f.getParent(); 00149 } 00150 00160 public static String getSignature(String ejbName, Method method) { 00161 00162 Class clazz = method.getDeclaringClass(); 00163 String methItf = ""; 00164 00165 if (javax.ejb.EJBHome.class.isAssignableFrom(clazz)) { 00166 methItf = "Home"; 00167 } else if (javax.ejb.EJBObject.class.isAssignableFrom(clazz)) { 00168 methItf = "Remote"; 00169 } else if (javax.ejb.EJBLocalHome.class.isAssignableFrom(clazz)) { 00170 methItf = "LocalHome"; 00171 } else if (javax.ejb.EJBLocalObject.class.isAssignableFrom(clazz)) { 00172 methItf = "Local"; 00173 } else if (java.rmi.Remote.class.isAssignableFrom(clazz)) { 00174 methItf = "ServiceEndpoint"; 00175 } 00176 00177 return new EJBMethodPermission(ejbName, methItf, method).getActions(); 00178 } 00179 } 00180