001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.iiop.rmi.ir;
023:
024: import org.omg.CORBA.ORB;
025: import org.omg.CORBA.IRObject;
026: import org.omg.CORBA.IRObjectOperations;
027: import org.omg.CORBA.DefinitionKind;
028: import org.omg.CORBA.BAD_INV_ORDER;
029: import org.omg.CORBA.UserException;
030: import org.omg.CORBA.CompletionStatus;
031: import org.omg.PortableServer.POA;
032: import org.omg.PortableServer.Servant;
033: import org.omg.PortableServer.POAPackage.WrongPolicy;
034: import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
035: import org.omg.PortableServer.POAPackage.ObjectAlreadyActive;
036: import org.omg.PortableServer.POAPackage.ObjectNotActive;
037:
038: //import org.omg.PortableServer.POAPackage.ServantNotActive;
039:
040: /**
041: * Abstract base class for all IR object implementations.
042: *
043: * @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
044: * @version $Revision: 57194 $
045: */
046: abstract class IRObjectImpl implements IRObjectOperations {
047: // Constants -----------------------------------------------------
048:
049: // Attributes ----------------------------------------------------
050:
051: protected RepositoryImpl repository;
052: protected DefinitionKind def_kind;
053:
054: // Static --------------------------------------------------------
055:
056: private static final org.jboss.logging.Logger logger = org.jboss.logging.Logger
057: .getLogger(IRObjectImpl.class);
058:
059: // Constructors --------------------------------------------------
060:
061: IRObjectImpl(DefinitionKind def_kind, RepositoryImpl repository) {
062: this .def_kind = def_kind;
063: this .repository = repository;
064: }
065:
066: // Public --------------------------------------------------------
067:
068: // IRObjectOperations implementation -----------------------------
069:
070: public DefinitionKind def_kind() {
071: logger.trace("IRObjectImpl.def_kind() entered.");
072: return def_kind;
073: }
074:
075: public void destroy() {
076: throw new BAD_INV_ORDER("Cannot destroy RMI/IIOP mapping.", 2,
077: CompletionStatus.COMPLETED_NO);
078: }
079:
080: // LocalIRObject implementation ----------------------------------
081:
082: abstract public IRObject getReference();
083:
084: public void allDone() throws IRConstructionException {
085: getReference();
086: }
087:
088: /**
089: * Unexport this object.
090: */
091: public void shutdown() {
092: POA poa = getPOA();
093:
094: try {
095: poa.deactivate_object(poa.reference_to_id(getReference()));
096: } catch (UserException ex) {
097: logger.warn("Could not deactivate IR object", ex);
098: }
099: }
100:
101: public RepositoryImpl getRepository() {
102: return repository;
103: }
104:
105: // Package protected ---------------------------------------------
106:
107: // Protected -----------------------------------------------------
108:
109: /**
110: * Return the ORB for this IRObject.
111: */
112: protected ORB getORB() {
113: return repository.orb;
114: }
115:
116: /**
117: * Return the POA for this IRObject.
118: */
119: protected POA getPOA() {
120: return repository.poa;
121: }
122:
123: /**
124: * Return the POA object ID of this IR object.
125: */
126: protected abstract byte[] getObjectId();
127:
128: /**
129: * Convert a servant to a reference.
130: */
131: protected org.omg.CORBA.Object servantToReference(Servant servant) {
132: byte[] id = getObjectId();
133:
134: try {
135: // repository.poa.activate_object(servant);
136: // return repository.poa.servant_to_reference(servant);
137:
138: // repository.poa.activate_object_with_id(getObjectId(), servant);
139: // return repository.poa.id_to_reference(getObjectId());
140:
141: logger.debug("#### IRObject.srv2ref: id=[" + new String(id)
142: + "]");
143: repository.poa.activate_object_with_id(id, servant);
144: org.omg.CORBA.Object ref = repository.poa
145: .id_to_reference(id);
146: logger.debug("#### IRObject.srv2ref: returning ref.");
147: //return repository.poa.id_to_reference(id);
148: return ref;
149: } catch (WrongPolicy ex) {
150: logger.debug(
151: "Exception converting CORBA servant to reference",
152: ex);
153: } catch (ServantAlreadyActive ex) {
154: logger.debug(
155: "Exception converting CORBA servant to reference",
156: ex);
157: } catch (ObjectAlreadyActive ex) {
158: logger.debug(
159: "Exception converting CORBA servant to reference",
160: ex);
161: } catch (ObjectNotActive ex) {
162: logger.debug(
163: "Exception converting CORBA servant to reference",
164: ex);
165: // } catch (ServantNotActive ex) {
166: // logger.debug("Exception converting CORBA servant to reference", ex);
167: }
168: return null;
169: }
170:
171: // Private -------------------------------------------------------
172:
173: // Inner classes -------------------------------------------------
174: }
|