ejbmessagebean.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 736 行 · 第 1/2 页
JAVA
736 行
} try { _activationSpec.validate(); } catch (Exception e) { throw error(e); } MessageListenerConfig listener = ra.getMessageListener(specName); _messagingType = listener.getMessageListenerType(); } else if (MessageListener.class.isAssignableFrom(getEJBClass())) { _messagingType = MessageListener.class; } else throw error(L.l("'{0}' must implement javax.jms.MessageListener or specify {1}.", getEJBClass().getName(), isAllowPOJO() ? "messaging-type" : "messageListenerInterface")); super.init(); ApiMethod ejbCreate = getEJBClassWrapper().getMethod("ejbCreate", new Class[0]); if (ejbCreate != null) { if (! ejbCreate.isPublic() && ! ejbCreate.isProtected()) throw error(L.l("{0}: ejbCreate method must be public or protected.", getEJBClass().getName())); } // J2EEManagedObject.register(new com.caucho.management.j2ee.MessageDrivenBean(this)); } protected void introspect() { _messageBean.setApi(new ApiClass(_messagingType)); super.introspect(); MessageDriven messageDriven = (MessageDriven) getEJBClass().getAnnotation(MessageDriven.class); if (messageDriven != null) { ActivationConfigProperty []activationConfig = messageDriven.activationConfig(); if (activationConfig != null) { for (ActivationConfigProperty prop : activationConfig) { addActivationConfigProperty(prop.propertyName(), prop.propertyValue()); } } Class type = messageDriven.messageListenerInterface(); if (type != null && ! Object.class.equals(type)) _messagingType = type; } } /** * Creates the bean generator for the session bean. */ @Override protected BeanGenerator createBeanGenerator() { _messageBean = new MessageGenerator(getEJBName(), getEJBClassWrapper()); return _messageBean; } /** * Obtain and apply initialization from annotations. */ @Override public void initIntrospect() throws ConfigException { // ejb/0fbm super.initIntrospect(); ApiClass type = getEJBClassWrapper(); // ejb/0j40 if (! type.isAnnotationPresent(MessageDriven.class) && ! type.isAnnotationPresent(MessageDriven.class) && ! isAllowPOJO()) return; // XXX: annotations in super classes? javax.ejb.MessageDriven messageDriven = type.getAnnotation(javax.ejb.MessageDriven.class); if (messageDriven != null) { ActivationConfigProperty[] properties = messageDriven.activationConfig(); if (properties != null) { for (ActivationConfigProperty property : properties) addActivationConfigProperty(property.propertyName(), property.propertyValue()); } Class messageListenerInterface = messageDriven.messageListenerInterface(); if (messageListenerInterface != null) setMessagingType(messageListenerInterface); TransactionManagement transaction = type.getAnnotation(TransactionManagement.class); if (transaction == null) setTransactionType("Container"); else if (TransactionManagementType.BEAN.equals(transaction.value())) setTransactionType("Bean"); else setTransactionType("Container"); configureMethods(type); } } private void configureMethods(ApiClass type) throws ConfigException { for (ApiMethod method : type.getMethods()) { AroundInvoke aroundInvoke = method.getAnnotation(AroundInvoke.class); // ejb/0fbl if (aroundInvoke != null) { setAroundInvokeMethodName(method.getName()); // XXX: needs to check invalid duplicated @AroundInvoke methods. break; } } } /** * Deploys the bean. */ @Override public AbstractServer deployServer(EjbContainer ejbManager, JavaClassGenerator javaGen) throws ClassNotFoundException { if (_activationSpec != null) return deployActivationSpecServer(ejbManager, javaGen); else return deployJmsServer(ejbManager, javaGen); } private AbstractServer deployJmsServer(EjbContainer ejbManager, JavaClassGenerator javaGen) throws ClassNotFoundException { ConnectionFactory factory; Destination destination = null; if (_connectionFactory != null) factory = _connectionFactory; else factory = getEjbContainer().getJmsConnectionFactory(); if (factory == null) { WebBeansContainer webBeans = WebBeansContainer.create(); factory = webBeans.getObject(ConnectionFactory.class); } if (_destination != null) destination = _destination; else if (_messageDestinationLink != null) { MessageDestination dest; dest = getConfig().getMessageDestination(_messageDestinationLink); if (dest != null) destination = dest.getResolvedDestination(); } if (destination == null) throw new ConfigException(L.l("ejb-message-bean '{0}' does not have a configured JMS destination or activation-spec", getEJBName())); if (factory == null) throw new ConfigException(L.l("ejb-message-bean '{0}' does not have a configured JMS connection factory", getEJBName())); JmsResourceAdapter ra = new JmsResourceAdapter(getEJBName(), factory, destination); JmsActivationSpec spec = new JmsActivationSpec(); ra.setAcknowledgeMode(_acknowledgeMode); ra.setMessageSelector(_messageSelector); ra.setSubscriptionName(_subscriptionName); if (_consumerMax > 0) ra.setConsumerMax(_consumerMax); else ra.setConsumerMax(getEjbContainer().getMessageConsumerMax()); return deployMessageServer(ejbManager, javaGen, ra, spec); } /** * Deploys the bean. */ public AbstractServer deployActivationSpecServer(EjbContainer ejbManager, JavaClassGenerator javaGen) throws ClassNotFoundException { if (_activationSpec == null) throw new ConfigException(L.l("ActivationSpec is required for ActivationSpecServer")); String specType = _activationSpec.getClass().getName(); ResourceArchive raCfg = ResourceArchiveManager.findResourceArchive(specType); if (raCfg == null) throw error(L.l("'{0}' is an unknown activation-spec. Make sure the .rar file for the driver is properly installed.", specType)); Class raClass = raCfg.getResourceAdapterClass(); if (raClass == null) throw error(L.l("resource-adapter class does not exist for activation-spec '{0}'. Make sure the .rar file for the driver is properly installed.", raClass.getName())); WebBeansContainer webBeans = WebBeansContainer.create(); ComponentFactory raFactory = webBeans.resolveByType(raClass); if (raFactory == null) { throw error(L.l("resource-adapter '{0}' must be configured in a <connector> tag.", raClass.getName())); } ResourceAdapter ra = (ResourceAdapter) raFactory.get(); if (ra == null) throw new NullPointerException(); return deployMessageServer(ejbManager, javaGen, ra, _activationSpec); } /** * Deploys the bean. */ public AbstractServer deployMessageServer(EjbContainer ejbManager, JavaClassGenerator javaGen, ResourceAdapter ra, ActivationSpec spec) throws ClassNotFoundException { MessageServer server; try { if (spec == null) throw new ConfigException(L.l("ActivationSpec is required for MessageServer")); if (ra == null) throw new ConfigException(L.l("ResourceAdapter is required for ActivationSpecServer")); server = new MessageServer(ejbManager); server.setConfigLocation(getFilename(), getLine()); server.setModuleName(getEJBModuleName()); server.setEJBName(getEJBName()); server.setMappedName(getMappedName()); server.setId(getEJBModuleName() + "#" + getMappedName()); server.setContainerTransaction(isContainerTransaction()); server.setEjbClass(getEJBClass()); Class contextImplClass = javaGen.loadClass(getSkeletonName()); server.setContextImplClass(contextImplClass); server.setActivationSpec(spec); server.setResourceAdapter(ra); // server.setMessageListenerType(_messagingType); Class beanClass = javaGen.loadClass(getEJBClass().getName()); Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(server.getClassLoader()); ContainerProgram initContainer = getInitProgram(); server.setInitProgram(initContainer); if (getServerProgram() != null) getServerProgram().configure(server); } finally { thread.setContextClassLoader(oldLoader); } } catch (Exception e) { throw error(e); } return server; } public class ActivationConfig { public void addActivationConfigProperty(ActivationConfigPropertyConfig prop) throws NamingException { String name = prop.getActivationConfigPropertyName(); String value = prop.getActivationConfigPropertyValue(); EjbMessageBean.this.addActivationConfigProperty(name, value); } } public static class ActivationConfigPropertyConfig { String _name; String _value; public void setActivationConfigPropertyName(String name) { _name = name; } public String getActivationConfigPropertyName() { return _name; } public void setActivationConfigPropertyValue(String value) { _value = value; } public String getActivationConfigPropertyValue() { return _value; } } public class MessageDrivenDestination { public void setDestinationType(String value) throws ConfigException, NamingException { setMessageDestinationType(value); } public void setSubscriptionDurability(String durability) { } public void setJndiName(JndiBuilder destination) throws ConfigException, NamingException { setDestination((Destination) destination.getObject()); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?