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.metadata;
031:
032: import com.caucho.loader.EnvironmentBean;
033: import com.caucho.config.ConfigException;
034: import com.caucho.config.program.ContainerProgram;
035: import com.caucho.ejb.manager.EjbContainer;
036: import com.caucho.util.L10N;
037: import com.caucho.util.Log;
038:
039: import javax.annotation.PostConstruct;
040: import javax.ejb.*;
041: import java.util.ArrayList;
042: import java.util.logging.Logger;
043:
044: /**
045: * Configuration for a new bean based on metadata.
046: */
047: public class Bean implements EnvironmentBean {
048: private static final L10N L = new L10N(Bean.class);
049: private static final Logger log = Log.open(Bean.class);
050:
051: private EjbContainer _ejbContainer;
052:
053: private ClassLoader _tempClassLoader;
054:
055: private Class _type;
056: private String _name;
057:
058: private ArrayList<ContainerProgram> _initList = new ArrayList<ContainerProgram>();
059:
060: public Bean(EjbContainer ejbContainer) {
061: _ejbContainer = ejbContainer;
062:
063: _tempClassLoader = ejbContainer.getIntrospectionClassLoader();
064: }
065:
066: public ClassLoader getClassLoader() {
067: return _tempClassLoader;
068: }
069:
070: protected String getEJBModuleName() {
071: // XXX: s/b what?
072: return "introspected";
073: }
074:
075: /**
076: * Sets the name.
077: */
078: public void setName(String name) {
079: _name = name;
080: }
081:
082: /**
083: * Sets the type.
084: */
085: public void setType(Class type) throws ConfigException {
086: _type = type;
087: _ejbContainer.getConfigManager().addIntrospectableClass(
088: _type.getName());
089: }
090:
091: /**
092: * Adds an init.
093: */
094: public void addInit(ContainerProgram init) {
095: _initList.add(init);
096: }
097:
098: /**
099: * Initializes the bean.
100: */
101: @PostConstruct
102: public void init() throws ConfigException {
103: if (_type == null)
104: throw new ConfigException(L
105: .l("type is a required attribute of <bean>"));
106: }
107: }
|