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.burlap;
031:
032: import com.caucho.ejb.RemoteExceptionWrapper;
033: import com.caucho.ejb.protocol.AbstractHomeHandle;
034:
035: import javax.ejb.EJBHome;
036: import java.rmi.RemoteException;
037:
038: /**
039: * Implementation for a home handle.
040: */
041: public class BurlapHomeHandle extends AbstractHomeHandle {
042: private String _url;
043: private transient EJBHome _home;
044:
045: /**
046: * Null arg constructor for serialization.
047: */
048: public BurlapHomeHandle() {
049: }
050:
051: /**
052: * Creates a new HomeHandle.
053: *
054: * @param url the url for the bean
055: */
056: public BurlapHomeHandle(String url) {
057: _url = url;
058: }
059:
060: /**
061: * Creates a new HomeHandle.
062: *
063: * @param url the url for the bean
064: */
065: public BurlapHomeHandle(EJBHome home, String url) {
066: _url = url;
067:
068: _home = home;
069: }
070:
071: /**
072: * Returns the handle's server id.
073: */
074: public String getServerId() {
075: return _url;
076: }
077:
078: /**
079: * Returns the EJBHome object associated with the handle.
080: */
081: public EJBHome getEJBHome() throws RemoteException {
082: if (_home == null) {
083: try {
084: _home = BurlapClientContainer.find(_url).getHomeStub();
085: } catch (Exception e) {
086: throw RemoteExceptionWrapper.create(e);
087: }
088: }
089:
090: return _home;
091: }
092:
093: /**
094: * Returns the URL for a particular protocol.
095: */
096: public String getURL(String protocol) {
097: return _url;
098: }
099:
100: /**
101: * Returns the full URL
102: */
103: public String getURL() {
104: return _url;
105: }
106:
107: /**
108: * Returns true if the test handle refers to the same object.
109: * In this implementation, the handles are identical iff the urls
110: * are identical.
111: */
112: public boolean equals(Object b) {
113: if (!(b instanceof BurlapHomeHandle))
114: return false;
115:
116: BurlapHomeHandle handle = (BurlapHomeHandle) b;
117:
118: return _url.equals(handle._url);
119: }
120:
121: /**
122: * The handle's hashcode is the same as the url's hashcode
123: */
124: public int hashCode() {
125: return _url.hashCode();
126: }
127:
128: /**
129: * The printed representation of the handle is the url.
130: */
131: public String toString() {
132: return _url;
133: }
134: }
|