ejbbean.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,224 行 · 第 1/4 页
JAVA
2,224 行
} else { interceptor = _ejbConfig.getInterceptor(className); interceptor.init(); addInterceptor(interceptor); } } } */ } private Interceptor configureInterceptor(Class type) throws ConfigException { try { Interceptor interceptor = new Interceptor(); interceptor.setInterceptorClass(type.getName()); interceptor.init(); return interceptor; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } } /** * Creates the views. */ protected void createViews21() throws ConfigException { /* if (_remoteHome != null) { _remoteHomeView = createHomeView(_remoteHome, "RemoteHome"); _remoteHomeView.introspect(); } if (_remote != null) { ArrayList<ApiClass> list = new ArrayList<ApiClass>(); list.add(_remote); _remoteView = createRemoteObjectView(list, "Remote", "21"); _remoteView.introspect(); } if (_remote21 != null) { ArrayList<ApiClass> list = new ArrayList<ApiClass>(); list.add(_remote21); _remoteView21 = createRemoteObjectView(list, "Remote", "21"); _remoteView21.introspect(); } else if (_remoteList.size() > 0) { ArrayList<ApiClass> list = new ArrayList<ApiClass>(); list.addAll(_remoteList); list.remove(_remote21); if (list.size() > 0) { _remoteView = createRemoteObjectView(list, "Remote", ""); _remoteView.introspect(); } } if (_localHome != null) { _localHomeView = createHomeView(_localHome, "LocalHome"); _localHomeView.introspect(); } if (_local21 != null) { ArrayList<ApiClass> list = new ArrayList<ApiClass>(); list.add(_local21); _localView21 = createObjectView(list, "Local", "21"); _localView21.introspect(); } if (_localList.size() > 0) { ArrayList<ApiClass> list = new ArrayList<ApiClass>(); list.addAll(_localList); list.remove(_local21); if (list.size() > 0) { _localView = createObjectView(list, "Local", ""); _localView.introspect(); } } */ } /** * Generates the class. */ public void generate(JavaClassGenerator javaGen, boolean isAutoCompile) throws Exception { String fullClassName = _bean.getFullClassName(); if (javaGen.preload(fullClassName) != null) { } else if (isAutoCompile) { javaGen.generate(_bean); /* GenClass genClass = assembleGenerator(fullClassName); if (genClass != null) javaGen.generate(genClass); */ } } /** * Deploys the bean. */ public AbstractServer deployServer(EjbContainer ejbContainer, JavaClassGenerator javaGen) throws ClassNotFoundException, ConfigException { throw new UnsupportedOperationException(); } /** * Validates the remote interface. */ protected void validateRemote(ApiClass objectClass) throws ConfigException { ApiClass beanClass = getEJBClassWrapper(); String beanName = beanClass.getName(); String objectName = objectClass.getName(); if (! objectClass.isPublic()) throw error(L.l("'{0}' must be public", objectName)); if (! objectClass.isInterface()) throw error(L.l("'{0}' must be an interface", objectName)); for (ApiMethod method : objectClass.getMethods()) { String name = method.getName(); Class []param = method.getParameterTypes(); Class retType = method.getReturnType(); if (method.getDeclaringClass().isAssignableFrom(EJBObject.class)) continue; if (method.getDeclaringClass().isAssignableFrom(EJBLocalObject.class)) continue; if (EJBObject.class.isAssignableFrom(objectClass.getJavaClass())) validateException(method, java.rmi.RemoteException.class); if (name.startsWith("ejb")) { throw error(L.l("'{0}' forbidden in {1}. Local or remote interfaces may not define ejbXXX methods.", getFullMethodName(method), objectName)); } Class returnType = method.getReturnType(); if (EJBObject.class.isAssignableFrom(objectClass.getJavaClass()) && (EJBLocalObject.class.isAssignableFrom(returnType) || EJBLocalHome.class.isAssignableFrom(returnType))) { throw error(L.l("'{0}' must not return '{1}' in {2}. Remote methods must not return local interfaces.", getFullMethodName(method), getShortClassName(returnType), objectClass.getName())); } ApiMethod implMethod = validateRemoteImplMethod(method.getName(), param, method, objectClass); if (! returnType.equals(implMethod.getReturnType())) { throw error(L.l("{0}: '{1}' must return {2} to match {3}.{4}. Business methods must return the same type as the interface.", method.getDeclaringClass().getName(), getFullMethodName(method), implMethod.getReturnType().getName(), getShortClassName(implMethod.getDeclaringClass()), getFullMethodName(implMethod))); } validateExceptions(method, implMethod.getExceptionTypes()); } } /** * Check that a method exists, is public, not abstract. * * @param methodName the name of the method to check for * @param args the expected method parameters * * @return the matching method */ private ApiMethod validateRemoteImplMethod(String methodName, Class []param, ApiMethod sourceMethod, ApiClass sourceClass) throws ConfigException { ApiMethod method = null; ApiClass beanClass = getEJBClassWrapper(); method = getMethod(beanClass, methodName, param); if (method == null && sourceMethod != null) { throw error(L.l("{0}: '{1}' expected to match {2}.{3}", beanClass.getName(), getFullMethodName(methodName, param), getShortClassName(sourceMethod.getDeclaringClass()), getFullMethodName(sourceMethod))); } else if (method == null) { throw error(L.l("{0}: '{1}' expected", beanClass.getName(), getFullMethodName(methodName, param))); } /* else if (Modifier.isAbstract(method.getModifiers()) && getBeanManagedPersistence()) { throw error(L.l("{0}: '{1}' must not be abstract", beanClass.getName(), getFullMethodName(methodName, param))); } */ else if (! method.isPublic()) { throw error(L.l("{0}: '{1}' must be public", beanClass.getName(), getFullMethodName(methodName, param))); } if (method.isStatic()) { throw error(L.l("{0}: '{1}' must not be static", beanClass.getName(), getFullMethodName(methodName, param))); } if (method.isFinal()) { throw error(L.l("{0}: '{1}' must not be final.", beanClass.getName(), getFullMethodName(methodName, param), beanClass.getName())); } return method; } protected ApiMethod validateNonFinalMethod(String methodName, Class []param, boolean isOptional) throws ConfigException { if (isOptional && getMethod(_ejbClass, methodName, param) == null) return null; else return validateNonFinalMethod(methodName, param); } protected ApiMethod validateNonFinalMethod(String methodName, Class []param) throws ConfigException { return validateNonFinalMethod(methodName, param, null, null); } protected ApiMethod validateNonFinalMethod(String methodName, Class []param, ApiMethod sourceMethod, ApiClass sourceClass) throws ConfigException { return validateNonFinalMethod(methodName, param, sourceMethod, sourceClass, false); } /** * Check that a method exists, is public, not abstract, and not final. * * @param methodName the name of the method to check for * @param args the expected method parameters * * @return the matching method */ protected ApiMethod validateNonFinalMethod(String methodName, Class []param, ApiMethod sourceMethod, ApiClass sourceClass, boolean isOptional) throws ConfigException { ApiMethod method = validateMethod(methodName, param, sourceMethod, sourceClass, isOptional); if (method == null && isOptional) return null; if (method.isFinal()) throw error(L.l("{0}: '{1}' must not be final", _ejbClass.getName(), getFullMethodName(method))); if (method.isStatic()) throw error(L.l("{0}: '{1}' must not be static", _ejbClass.getName(), getFullMethodName(method))); return method; } protected ApiMethod validateMethod(String methodName, Class []param) throws ConfigException { return validateMethod(methodName, param, null, null); } /** * Check that a method exists, is public and is not abstract. * * @param methodName the name of the method to check for * @param args the expected method parameters * * @return the matching method */ protected ApiMethod validateMethod(String methodName, Class []param, ApiMethod sourceMethod, ApiClass sourceClass) throws ConfigException { return validateMethod(methodName, param, sourceMethod, sourceClass, false); } /** * Check that a method exists, is public and is not abstract. * * @param methodName the name of the method to check for * @param args the expected method parameters * * @return the matching method */ protected ApiMethod validateMethod(String methodName, Class []param, ApiMethod sourceMethod, ApiClass sourceClass, boolean isOptional) throws ConfigException { ApiMethod method = null; method = getMethod(_ejbClass, methodName, param); if (method == null && isOptional) return null; if (method == null && sourceMethod != null) { throw error(L.l("{0}: missing '{1}' needed to match {2}.{3}", _ejbClass.getName(), getFullMethodName(methodName, param), sourceClass.getSimpleName(), getFullMethodName(sourceMethod))); } else if (method == null) { throw error(L.l("{0}: expected '{1}'", _ejbClass.getName(), getFullMethodName(methodName, param))); } Class declaringClass = method.getDeclaringClass(); if (method.isAbstract()) { if (method.getDeclaringClass().getName().equals("javax.ejb.EntityBean")) throw error(L.l("{0}: '{1}' must not be abstract. Entity beans must implement the methods in EntityBean.", _ejbClass.getName(), getFullMethodName(methodName, param))); else if (method.getDeclaringClass().getName().equals("javax.ejb.SessionBean")) throw error(L.l("{0}: '{1}' must not be abstract. Session beans must implement the methods in SessionBean.", _ejbClass.getName(), getFullMethodName(methodName, param))); else if (sourceMethod != null) throw error(L.l("{0}: '{1}' must not be abstract. All methods from '{2}' must be implemented in the bean.", _ejbClass.getName(), getFullMethodName(methodName, param), sourceClass.getName())); else throw error(L.l("{0}: '{1}' must not be abstract. Business methods must be implemented.", _ejbClass.getName(), getFullMethodName(methodName, param))); } else if (! method.isPublic()) { throw error(L.l("{0}: '{1}' must be public. Business method implementations must be public.", _ejbClass.getName(), getFullMethodName(methodName, param))); } if (method.isStatic()) { throw error(L.l("{0}: '{1}' must not be static. Business method implementations must not be static.", _ejbClass.getName(), getFullMethodName(method))); } return method; } public String getSkeletonName() { String className = getEJBClass().getName(); int p = className.lastIndexOf('.'); if (p > 0) className = className.substring(p + 1); String ejbName = getEJBName(); String fullClassName = "_ejb." + ejbName + "." + className + "__EJB"; return JavaClassGenerator.cleanClassName(fullClassName); } /** * Assembles the generator. */ public GenClass assembleGenerator(String fullClassName) throws NoSuchMethodException, ConfigException { throw new UnsupportedOperationException(); } /** * Introspects the bean's methods. */ public void assembleBeanMethods() throws ConfigException { if (getEJBClassWrapper() == null) return; // find API methods matching an implementation method for (ApiMethod method : getEJBClassWrapper().getMethods()) { EjbBaseMethod ejbMethod = null; String name = method.getName(); if (name.startsWith("ejb")) { ejbMethod = introspectEJBMethod(method); if (ejbMethod != null) _methodMap.put(ejbMethod.getMethod().getFullName(), ejbMethod); } else validateImplMethod(method); } } /** * Introspects an ejb method. */ protected EjbBaseMethod introspectEJBMethod(ApiMethod method) throws ConfigException { return null; } /** * Validates an implementation method. */ protected void validateImplMethod(ApiMethod method) throws ConfigException { } public CallChain getTransactionChain(CallChain next, ApiMethod apiMethod, ApiMethod implMethod, String prefix) { return TransactionChain.create(next, getTransactionAttribute(implMethod, prefix), apiMethod, implMethod, isEJB3(), _ejbConfig.getApplicationExceptions()); } public CallChain getSecurityChain(CallChain next, ApiMethod method, String prefix) { EjbMethodPattern ejbMethod = getMethodPattern(method, prefix); ArrayList<String> roles = null; if (ejbMethod != null) roles = ejbMethod.getRoles(); if (roles == null) { ejbMethod = getMethodPattern(null, prefix); if (ejbMethod != null) roles = ejbMethod.getRoles(); } if (roles == null) { ejbMethod = getMethodPattern(method, null); if (ejbMethod != null) roles = ejbMethod.getRoles(); } if (roles == null) { ejbMethod = getMethodPattern(null, null); if (ejbMethod != null) roles = ejbMethod.getRoles(); } /* if (roles != null) return new UserInRoleChain(next, roles); else return next; */ return next; } /** * Check that a method is public. * * @return the matching method */ protected void validatePublicMethod(ApiMethod method) throws ConfigException { if (! method.isPublic()) { throw error(L.l("{0}: '{1}' must be public.", _ejbClass.getName(), getFullMethodName(method))); } else if (method.isStatic()) { throw error(L.l("{0}: '{1}' must not be static.", _ejbClass.getName(), getFullMethodName(method))); } } /** * True if we've already handled the method. */ /* static boolean isOld(ApiMethod []methods, ApiMethod method, int index) { for (int i = 0; i < index; i++) { if (isEquiv(methods[i], method)) return true; } return false; } */ public static boolean isEquiv(ApiMethod oldMethod, ApiMethod method) { if (! oldMethod.getName().equals(method.getName())) return false;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?