1 25 26 package org.objectweb.jonas_ejb.lib; 27 28 import java.io.File ; 29 import java.lang.reflect.Method ; 30 import java.util.StringTokenizer ; 31 32 import javax.security.jacc.EJBMethodPermission ; 33 34 46 public class BeanNaming { 47 48 51 public static String getPackageName(String name) { 52 if (name == null) { return null; } 53 int idx = name.lastIndexOf('.'); 54 return (idx == -1 ? "" : name.substring(0, idx)); 55 } 56 57 66 public static String getClassName(String packageName, String name) { 67 return (packageName.length() == 0) ? name : packageName + "." + name; 68 } 69 70 73 public static String getBaseName(String fullName) { 74 String 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 94 public static String getPath(String fullName) { 95 String pkg = new String (); 96 StringTokenizer stk = new StringTokenizer (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 110 public static String firstToUpperCase(String s) { 111 String value; 112 if (s.length() > 0) { 113 char c = Character.toUpperCase(s.charAt(0)); 114 value = new String (c + s.substring(1)); 115 } else { 116 value = new String (); 117 } 118 return (value); 119 } 120 121 127 public static String getJonasXmlName(String stdXmlName) { 128 129 String jonasXmlName = new String (); 130 File f = new File (stdXmlName); 131 String p = f.getParent(); 132 String 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 146 public static String getParentName(String fileName) { 147 File f = new File (fileName); 148 return f.getParent(); 149 } 150 151 160 public static String getSignature(String ejbName, Method method) { 161 162 Class clazz = method.getDeclaringClass(); 163 String methItf = ""; 164 165 if (javax.ejb.EJBHome .class.isAssignableFrom(clazz)) { 166 methItf = "Home"; 167 } else if (javax.ejb.EJBObject .class.isAssignableFrom(clazz)) { 168 methItf = "Remote"; 169 } else if (javax.ejb.EJBLocalHome .class.isAssignableFrom(clazz)) { 170 methItf = "LocalHome"; 171 } else if (javax.ejb.EJBLocalObject .class.isAssignableFrom(clazz)) { 172 methItf = "Local"; 173 } else if (java.rmi.Remote .class.isAssignableFrom(clazz)) { 174 methItf = "ServiceEndpoint"; 175 } 176 177 return new EJBMethodPermission (ejbName, methItf, method).getActions(); 178 } 179 } 180 181 | Popular Tags |