001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.ejb.cfg;
031:
032: import java.util.*;
033: import java.util.logging.*;
034:
035: import javax.annotation.*;
036: import javax.jms.*;
037:
038: import com.caucho.config.*;
039: import com.caucho.config.types.*;
040: import com.caucho.ejb.manager.*;
041: import com.caucho.webbeans.cfg.*;
042:
043: import com.caucho.util.*;
044:
045: /**
046: * ejb-stateful-bean configuration
047: */
048: public class StatefulBeanConfig extends AbstractBeanConfig {
049: private static final L10N L = new L10N(StatefulBeanConfig.class);
050: private static final Logger log = Logger
051: .getLogger(StatefulBeanConfig.class.getName());
052:
053: public StatefulBeanConfig() {
054: }
055:
056: public StatefulBeanConfig(WbComponentConfig beanConfig) {
057: setClass(beanConfig.getClassType());
058:
059: // XXX:
060: //if (beanConfig.getComponentType() != null)
061: // setComponentType(beanConfig.getComponentType());
062:
063: if (beanConfig.getName() != null)
064: setName(beanConfig.getName());
065:
066: // XXX:
067: // setScope(beanConfig.getScope());
068:
069: if (beanConfig.getInit() != null)
070: setInit(beanConfig.getInit());
071: }
072:
073: @PostConstruct
074: public void init() {
075: if (getInstanceClass() == null)
076: throw new ConfigException(
077: L
078: .l("ejb-stateful-bean requires a 'class' attribute"));
079:
080: EjbContainer ejbContainer = EjbContainer.create();
081: EjbConfigManager configManager = ejbContainer
082: .getConfigManager();
083:
084: EjbStatefulBean bean = new EjbStatefulBean(configManager,
085: "config");
086: bean.setEJBClass(getInstanceClass());
087:
088: String name = getName();
089:
090: if (name == null)
091: name = getJndiName();
092:
093: if (name == null)
094: name = getInstanceClass().getSimpleName();
095:
096: bean.setEJBName(name);
097:
098: if (getInit() != null)
099: bean.setInit(getInit());
100:
101: configManager.setBeanConfig(name, bean);
102:
103: // XXX: timing?
104: configManager.start();
105: }
106: }
|