ejbmessagebean.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 736 行 · 第 1/2 页
JAVA
736 行
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Scott Ferguson */package com.caucho.ejb.cfg;import com.caucho.config.ConfigException;import com.caucho.config.program.ContainerProgram;import com.caucho.config.types.JndiBuilder;import com.caucho.ejb.AbstractServer;import com.caucho.ejb.gen.*;import com.caucho.ejb.manager.EjbContainer;import com.caucho.ejb.message.*;import com.caucho.java.gen.JavaClassGenerator;import com.caucho.jca.*;import com.caucho.jca.cfg.*;import com.caucho.util.L10N;import com.caucho.webbeans.component.*;import com.caucho.webbeans.manager.*;import javax.annotation.PostConstruct;import javax.ejb.ActivationConfigProperty;import javax.ejb.MessageDriven;import javax.ejb.TransactionManagement;import javax.ejb.TransactionManagementType;import javax.interceptor.AroundInvoke;import javax.jms.ConnectionFactory;import javax.jms.Destination;import javax.jms.MessageListener;import javax.jms.Session;import javax.resource.spi.*;import javax.naming.NamingException;import javax.webbeans.*;import java.lang.reflect.*;import java.util.logging.Level;import java.util.logging.Logger;/** * Configuration for an ejb entity bean. */public class EjbMessageBean extends EjbBean { private static final Logger log = Logger.getLogger(EjbMessageBean.class.getName()); private static final L10N L = new L10N(EjbMessageBean.class); private ConnectionFactory _connectionFactory; private ActivationSpec _activationSpec; private Destination _destination; private String _messageSelector; private int _acknowledgeMode = Session.AUTO_ACKNOWLEDGE; private String _selector; private String _subscriptionName; private int _consumerMax = -1; private String _messageDestinationLink; private Class _messagingType; private MessageGenerator _messageBean; /** * Creates a new message bean configuration. */ public EjbMessageBean(EjbConfig config, String ejbModuleName) { super(config, ejbModuleName); } /** * Returns the kind of bean. */ @Override public String getEJBKind() { return "message"; } /** * Sets the ejb implementation class. */ @Override public void setEJBClass(Class ejbClass) throws ConfigException { super.setEJBClass(ejbClass); // ejb/0987 /* if (! MessageDrivenBean.class.isAssignableFrom(ejbClass) && ! isAllowPOJO()) throw error(L.l("'{0}' must implement javax.ejb.MessageDrivenBean. Every message-driven bean must implement MessageDrivenBean.", ejbClass.getName())); */ if (Modifier.isAbstract(ejbClass.getModifiers())) throw error(L.l("'{0}' must not be abstract. Every message-driven bean must be a fully-implemented class.", ejbClass.getName())); // ejb 3.0 simplified section 10.1.3 // The name annotation element defaults to the unqualified name of the bean // class. if (getEJBName() == null) { setEJBName(ejbClass.getSimpleName()); } } /** * Creates the old EJB 2.0 message-driven-destination */ public MessageDrivenDestination createMessageDrivenDestination() { return new MessageDrivenDestination(); } /** * Sets the JCA activation spec. */ public void setActivationSpec(ActivationSpec activationSpec) { _activationSpec = activationSpec; } /** * Sets the JMS destination. */ public void setDestination(Destination destination) throws ConfigException { _destination = destination; } /** * Sets the JMS destination. */ public void setDestinationValue(Destination destination) { _destination = destination; } public void setMessagingType(Class messagingType) { if (messagingType != Object.class) _messagingType = messagingType; } /** * Returns the destination. */ public Destination getDestination() { return _destination; } /** * @deprecated for compat with TCK */ public void setMappedName(String mappedName) throws ConfigException { // XXX: // setDestination(destination); } /** * Sets the JMS destination type. */ public void setMessageDestinationType(String type) throws ConfigException, NamingException { } /** * Sets the JMS destination link */ public void setMessageDestinationLink(String messageDestinationLink) throws ConfigException, NamingException { _messageDestinationLink = messageDestinationLink; } /** * Sets the connection factory. */ public void setConnectionFactory(JndiBuilder factory) throws ConfigException, NamingException { if (! (factory.getObject() instanceof ConnectionFactory)) throw new ConfigException(L.l("'{0}' needs to implement javax.jms.ConnectionFactory.", factory.getObject())); _connectionFactory = (ConnectionFactory) factory.getObject(); } /** * Sets the connection factory. */ public void setConnectionFactoryValue(ConnectionFactory factory) { _connectionFactory = factory; } /** * Returns the destination. */ public ConnectionFactory getConnectionFactory() { return _connectionFactory; } /** * Returns the acknowledge mode. */ public int getAcknowledgeMode() { return _acknowledgeMode; } /** * Set the acknowledge mode. */ public void setAcknowledgeMode(int acknowledgeMode) { _acknowledgeMode = acknowledgeMode; } /** * Returns the message selector */ public String getSelector() { return _selector; } /** * Set the message selector. */ public void setSelector(String selector) { _selector = selector; } /** * Returns the durable subscription name */ public String getSubscriptionName() { return _subscriptionName; } /** * Set the message selector. */ public void setSubscriptionName(String subscriptionName) { _subscriptionName = subscriptionName; } /** * Set true if the container handles transactions. */ public void setTransactionType(String type) throws ConfigException { if (type.equals("Container")) { setContainerTransaction(true); } else if (type.equals("Bean")) { setContainerTransaction(false); } else throw new ConfigException(L.l("'{0}' is an unknown transaction-type. transaction-type must be 'Bean' or 'Container'.", type)); } public void setSecurityIdentity(SecurityIdentity identity) { } /** * Adds the activation config. */ public ActivationConfig createActivationConfig() { return new ActivationConfig(); } public void setResourceAdapter(String name) { ResourceArchive ra = ResourceArchiveManager.findResourceArchive(name); if (ra == null) throw new ConfigException(L.l("'{0}' is an unknown resource-adapter")); } private void addActivationConfigProperty(String name, Object value) { if ("destination".equals(name)) { if (value instanceof Destination) setDestination((Destination) value); else { WebBeansContainer webBeans = WebBeansContainer.create(); Destination dest = webBeans.getObject(Destination.class, String.valueOf(value)); setDestination(dest); } } else if ("messageSelector".equals(name)) { _messageSelector = (String) value; } else log.log(Level.FINE, L.l("activation-config-property '{0}' is unknown, ignored", name)); } /** * Sets the number of message consumers. */ public void setMessageConsumerMax(int consumerMax) throws ConfigException { _consumerMax = consumerMax; } /** * Initialize */ @PostConstruct @Override public void init() throws ConfigException { if (_messagingType != null) { } else if (_activationSpec != null) { String specName = _activationSpec.getClass().getName(); ResourceArchive ra = ResourceArchiveManager.findResourceArchive(specName); if (ra == null) { throw new ConfigException(L.l("'{0}' is an unknown activation-spec. Make sure the JCA adapter is deployed in a .rar file", specName));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?