KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > rmi > ir > IRObjectImpl


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.iiop.rmi.ir;
23
24 import org.omg.CORBA.ORB JavaDoc;
25 import org.omg.CORBA.IRObject JavaDoc;
26 import org.omg.CORBA.IRObjectOperations JavaDoc;
27 import org.omg.CORBA.DefinitionKind JavaDoc;
28 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
29 import org.omg.CORBA.UserException JavaDoc;
30 import org.omg.CORBA.CompletionStatus JavaDoc;
31 import org.omg.PortableServer.POA JavaDoc;
32 import org.omg.PortableServer.Servant JavaDoc;
33 import org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc;
34 import org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc;
35 import org.omg.PortableServer.POAPackage.ObjectAlreadyActive JavaDoc;
36 import org.omg.PortableServer.POAPackage.ObjectNotActive JavaDoc;
37 //import org.omg.PortableServer.POAPackage.ServantNotActive;
38

39 /**
40  * Abstract base class for all IR object implementations.
41  *
42  * @author <a HREF="mailto:osh@sparre.dk">Ole Husgaard</a>
43  * @version $Revision: 37459 $
44  */

45 abstract class IRObjectImpl
46    implements IRObjectOperations JavaDoc
47 {
48    // Constants -----------------------------------------------------
49

50    // Attributes ----------------------------------------------------
51

52    protected RepositoryImpl repository;
53    protected DefinitionKind JavaDoc def_kind;
54    
55
56    // Static --------------------------------------------------------
57

58    private static final org.jboss.logging.Logger logger =
59                org.jboss.logging.Logger.getLogger(IRObjectImpl.class);
60
61    // Constructors --------------------------------------------------
62

63    IRObjectImpl(DefinitionKind JavaDoc def_kind, RepositoryImpl repository)
64    {
65       this.def_kind = def_kind;
66       this.repository = repository;
67    }
68
69    // Public --------------------------------------------------------
70

71    // IRObjectOperations implementation -----------------------------
72

73    public DefinitionKind JavaDoc def_kind()
74    {
75       logger.trace("IRObjectImpl.def_kind() entered.");
76       return def_kind;
77    }
78
79    public void destroy()
80    {
81       throw new BAD_INV_ORDER JavaDoc("Cannot destroy RMI/IIOP mapping.", 2,
82                               CompletionStatus.COMPLETED_NO);
83    }
84
85    // LocalIRObject implementation ----------------------------------
86

87    abstract public IRObject JavaDoc getReference();
88
89    public void allDone()
90       throws IRConstructionException
91    {
92       getReference();
93    }
94
95    /**
96     * Unexport this object.
97     */

98    public void shutdown()
99    {
100       POA JavaDoc poa = getPOA();
101
102       try {
103          poa.deactivate_object(poa.reference_to_id(getReference()));
104       } catch (UserException JavaDoc ex) {
105          logger.warn("Could not deactivate IR object", ex);
106       }
107    }
108
109    public RepositoryImpl getRepository()
110    {
111       return repository;
112    }
113
114    // Package protected ---------------------------------------------
115

116    // Protected -----------------------------------------------------
117

118    /**
119     * Return the ORB for this IRObject.
120     */

121    protected ORB JavaDoc getORB()
122    {
123       return repository.orb;
124    }
125
126    /**
127     * Return the POA for this IRObject.
128     */

129    protected POA JavaDoc getPOA()
130    {
131       return repository.poa;
132    }
133
134    /**
135     * Return the POA object ID of this IR object.
136     */

137    protected abstract byte[] getObjectId();
138
139    /**
140     * Convert a servant to a reference.
141     */

142    protected org.omg.CORBA.Object JavaDoc servantToReference(Servant JavaDoc servant)
143    {
144       byte[] id = getObjectId();
145
146       try {
147 // repository.poa.activate_object(servant);
148
// return repository.poa.servant_to_reference(servant);
149

150 // repository.poa.activate_object_with_id(getObjectId(), servant);
151
// return repository.poa.id_to_reference(getObjectId());
152

153          logger.debug("#### IRObject.srv2ref: id=[" + new String JavaDoc(id) + "]");
154          repository.poa.activate_object_with_id(id, servant);
155          org.omg.CORBA.Object JavaDoc ref = repository.poa.id_to_reference(id);
156          logger.debug("#### IRObject.srv2ref: returning ref.");
157          //return repository.poa.id_to_reference(id);
158
return ref;
159       } catch (WrongPolicy JavaDoc ex) {
160          logger.debug("Exception converting CORBA servant to reference", ex);
161       } catch (ServantAlreadyActive JavaDoc ex) {
162          logger.debug("Exception converting CORBA servant to reference", ex);
163       } catch (ObjectAlreadyActive JavaDoc ex) {
164          logger.debug("Exception converting CORBA servant to reference", ex);
165       } catch (ObjectNotActive JavaDoc ex) {
166          logger.debug("Exception converting CORBA servant to reference", ex);
167 // } catch (ServantNotActive ex) {
168
// logger.debug("Exception converting CORBA servant to reference", ex);
169
}
170       return null;
171    }
172
173    // Private -------------------------------------------------------
174

175    // Inner classes -------------------------------------------------
176
}
177
Popular Tags