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.protocol;
031:
032: import com.caucho.ejb.AbstractServer;
033: import com.caucho.iiop.IiopRemoteService;
034:
035: import java.rmi.NoSuchObjectException;
036: import java.rmi.Remote;
037: import java.util.ArrayList;
038: import java.util.logging.Level;
039: import java.util.logging.Logger;
040:
041: public class EjbIiopRemoteService extends IiopRemoteService {
042: private static final Logger log = Logger
043: .getLogger(EjbIiopRemoteService.class.getName());
044:
045: private AbstractServer _server;
046:
047: private Class _remoteInterface;
048:
049: private boolean _isEJB3;
050:
051: public EjbIiopRemoteService(AbstractServer server) {
052: _server = server;
053: }
054:
055: public EjbIiopRemoteService(AbstractServer server,
056: Class remoteInterface) {
057: _server = server;
058: _remoteInterface = remoteInterface;
059: }
060:
061: /**
062: * Returns true for 3.0 when multiple 2.1/3.0 interfaces are available.
063: */
064: public boolean isEJB3() {
065: return _isEJB3;
066: }
067:
068: /**
069: * Uses the 3.0 remote interface when multiple 2.1/3.0 interfaces are available.
070: */
071: public void setEJB3(boolean isEJB3) {
072: _isEJB3 = isEJB3;
073: }
074:
075: /**
076: * Returns the context class loader.
077: */
078: public ClassLoader getClassLoader() {
079: return _server.getClassLoader();
080: }
081:
082: /**
083: * Returns the home API class.
084: */
085: public ArrayList<Class> getHomeAPI() {
086: if (_server.getRemoteHomeClass() != null) {
087: ArrayList<Class> list = new ArrayList<Class>();
088: list.add(_server.getRemoteHomeClass());
089:
090: return list;
091: } else if (getRemoteInterface() != null) {
092: ArrayList<Class> list = new ArrayList<Class>();
093: list.add(getRemoteInterface());
094:
095: return list;
096: } else
097: return _server.getRemoteApiList();
098: }
099:
100: /**
101: * Returns the object API class.
102: */
103: public ArrayList<Class> getObjectAPI() {
104: if ((!_isEJB3) && (_server.getRemote21() != null)) {
105: ArrayList<Class> list = new ArrayList<Class>();
106: list.add(_server.getRemote21());
107:
108: return list;
109: }
110:
111: return _server.getRemoteApiList();
112: }
113:
114: /**
115: * Returns the invoked API class.
116: */
117: @Override
118: public Class getRemoteInterface() {
119: return _remoteInterface;
120: }
121:
122: /**
123: * Returns the home object.
124: */
125: public Object getHome() {
126: Object obj = _server.getRemoteObject(_server
127: .getRemoteHomeClass(), "iiop");
128:
129: if (obj != null)
130: return obj;
131:
132: return _server.getRemoteObject(_remoteInterface, "iiop");
133: }
134:
135: /**
136: * Returns the object interface.
137: */
138: public Object getObject(String local) throws NoSuchObjectException {
139: // Move this logic to the ejb SessionServer after refactoring the 2.1 / 3.0 remote interfaces.
140: try {
141: // XXX TCK: ejb30/.../remove return _server.getEJBObject(local);
142: return _server.getRemoteObject(local);
143: } catch (javax.ejb.NoSuchEJBException e) {
144: // XXX TCK: ejb30/.../remove/removeBean2
145: if ((_remoteInterface == null && !_isEJB3)
146: || (_remoteInterface != null && Remote.class
147: .isAssignableFrom(_remoteInterface))) {
148: throw new NoSuchObjectException("no matching object: "
149: + local);
150: }
151:
152: throw e;
153: } catch (RuntimeException e) {
154: throw e;
155: } catch (Exception e) {
156: log.log(Level.FINE, e.toString(), e);
157:
158: return null;
159: }
160: }
161:
162: public String toString() {
163: return "EjbIiopRemoteService[" + _server + "]";
164: }
165: }
|