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.config.types;
031:
032: import com.caucho.config.ConfigException;
033: import com.caucho.naming.*;
034: import com.caucho.loader.*;
035: import com.caucho.util.L10N;
036:
037: import javax.annotation.PostConstruct;
038: import javax.naming.*;
039: import javax.rmi.PortableRemoteObject;
040: import java.util.ArrayList;
041: import java.util.Hashtable;
042: import java.util.logging.Logger;
043:
044: /**
045: * Configuration for the ejb-ref.
046: *
047: * An ejb-ref is used to make an ejb available within the environment
048: * in which the ejb-ref is declared.
049: */
050: public class EjbRefContext {
051: private static final EnvironmentLocal<EjbRefContext> _local = new EnvironmentLocal<EjbRefContext>();
052:
053: private ArrayList<EjbRef> _ejbRefList = new ArrayList<EjbRef>();
054:
055: private EjbRefContext() {
056: }
057:
058: public static EjbRefContext getLocal() {
059: return _local.get();
060: }
061:
062: public static EjbRefContext createLocal() {
063: EjbRefContext local = _local.getLevel();
064:
065: if (local == null) {
066: local = new EjbRefContext();
067: _local.set(local);
068: }
069:
070: return local;
071: }
072:
073: void add(EjbRef ejbRef) {
074: _ejbRefList.add(ejbRef);
075: }
076:
077: public Object findByType(Class type) {
078: for (int i = 0; i < _ejbRefList.size(); i++) {
079: Object value = _ejbRefList.get(i).getByType(type);
080:
081: if (value != null) {
082: // XXX: should also save on success
083: return value;
084: }
085: }
086:
087: return null;
088: }
089:
090: public Object findByBeanName(String ownerClassName,
091: String fieldName, Class fieldType) throws NamingException {
092: // ejb/0fbe
093: String expected = ownerClassName + "/" + fieldName;
094:
095: for (int i = 0; i < _ejbRefList.size(); i++) {
096: String ejbRefName = _ejbRefList.get(i).getEjbRefName();
097:
098: if (expected.equals(ejbRefName))
099: return _ejbRefList.get(i).createObject(null);
100: }
101:
102: return null;
103: }
104:
105: public String toString() {
106: return "EjbRefContext[]";
107: }
108: }
|