/[classpath]/classpath/javax/rmi/CORBA/Stub.java
ViewVC logotype

Diff of /classpath/javax/rmi/CORBA/Stub.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3.2.2 by gnu_andrew, Tue Aug 2 20:12:36 2005 UTC revision 1.3.2.3 by gnu_andrew, Wed Nov 2 00:43:40 2005 UTC
# Line 1  Line 1 
1  /* Stub.java --  /* Stub.java --
2     Copyright (C) 2002, 2004 Free Software Foundation, Inc.     Copyright (C) 2004, 2004, 2005 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 39  exception statement from your version. * Line 39  exception statement from your version. *
39  package javax.rmi.CORBA;  package javax.rmi.CORBA;
40    
41  import gnu.javax.rmi.CORBA.DelegateFactory;  import gnu.javax.rmi.CORBA.DelegateFactory;
42  import gnu.javax.rmi.CORBA.GetDelegateInstanceException;  import gnu.javax.rmi.CORBA.StubDelegateImpl;
43    
44  import java.io.IOException;  import java.io.IOException;
45  import java.io.ObjectInputStream;  import java.io.ObjectInputStream;
# Line 47  import java.io.ObjectOutputStream; Line 47  import java.io.ObjectOutputStream;
47  import java.io.Serializable;  import java.io.Serializable;
48  import java.rmi.RemoteException;  import java.rmi.RemoteException;
49    
50  public abstract class Stub extends ObjectImpl  import javax.rmi.PortableRemoteObject;
51    
52    import org.omg.CORBA.ORB;
53    import org.omg.CORBA_2_3.portable.ObjectImpl;
54    
55    /**
56     * A Stub descendants provide access to the object on the client side. This base
57     * class implements methods, required for remote or local invocation using CORBA
58     * mechanisms. The most of the functionality is forwarded to the stub delegate.
59     * This delegate can be altered by setting the system property
60     * "javax.rmi.CORBA.StubClass" to the name of the alternative class that must
61     * implement {@link StubDelegate}. Hence Stub contains two delegates, one for
62     * Stub-related operations and another inherited from the ObjectImpl.
63     *
64     * @specnote GNU Classpath uses separate delegate per each Stub. The delegate
65     * holds information about the ORB and other data, specific for the each Stub.
66     *
67     * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
68     */
69    public abstract class Stub
70      extends ObjectImpl
71    implements Serializable    implements Serializable
72  {  {
73    /**    /**
# Line 55  public abstract class Stub extends Objec Line 75  public abstract class Stub extends Objec
75     */     */
76    private static final long serialVersionUID = 1087775603798577179L;    private static final long serialVersionUID = 1087775603798577179L;
77    
78    private transient StubDelegate delegate;    /**
79                       * The hashcode, computed once (expensive operation).
80    protected Stub()     */
81    {    transient int m_hash = Integer.MIN_VALUE;
82      try  
83        {    /**
84          delegate = (StubDelegate)DelegateFactory.getInstance("Stub");     * The stringified reference, computed once (expensive operation).
85        }     */
86      catch(GetDelegateInstanceException e)    transient String m_ior;
87        {  
88          delegate = null;    /**
89        }     * The ORB, where the stub is connected on the client side.
90    }     */
91      transient ORB m_orb;
92    
93      /**
94       * The associated delegate, responsible for the major of the functionality of
95       * this stub.
96       */
97      static StubDelegate delegate = (StubDelegate) DelegateFactory.getInstance(DelegateFactory.STUB);
98    
99      /**
100       * Returns the same hashcode for all stubs that point to the same remote
101       * object.
102       */
103    public int hashCode()    public int hashCode()
104    {    {
105      if(delegate != null)      if (m_hash == Integer.MIN_VALUE)
106        return delegate.hashCode(this);        m_hash = delegate.hashCode(this);
107      else      // This should finally result to the IOR comparison.
108        return 0;      return m_hash;
109    }    }
110    
111    public boolean equals(Object obj)    /**
112       * The stubs are equal if they point to the same remote object.
113       */
114      public boolean equals(java.lang.Object obj)
115    {    {
116      if(delegate != null)      return delegate.equals(this, obj);
       return delegate.equals(this, obj);  
     else  
       return false;  
117    }    }
118    
119      /**
120       * Get the string representation of this Stub.
121       *
122       * @return the CORBA IOR reference.
123       */
124    public String toString()    public String toString()
125    {    {
126      String s = null;      if (m_ior == null)
127      if(delegate != null)        m_ior = delegate.toString(this);
128        s = delegate.toString(this);      return m_ior;
     if(s == null)  
       s = super.toString();  
     return s;  
129    }    }
130    
131    // XXX javax.rmi.ORB -> org.omg.CORBA.ORB    /**
132    public void connect(javax.rmi.ORB orb)     * <p>
133       * Finds the suitable {@link Tie} for this Stub and connects it to the given
134       * ORB. The tie is found by the name pattern. If the found tie is derived from
135       * {@link org.omg.CORBA.PortableServer.Servant}, it is connected to the root
136       * POA, also activating it (if not already active).
137       * </p>
138       * <p>
139       * This method does not allow to specify, to which POA the found Tie must be
140       * connected and requires to use the deprecated method {@link ORB#connect}.
141       * Many useful POA features remain unaccessible. A better alternative it might
142       * be to generate a {@link org.omg.CORBA.PortableServer.Servant} - derived Tie
143       * (-poa key in rmic) and connect it to POA in one of the many ways, listed in
144       * the description of the {@link orb.omg.PortableServer} package). The
145       * obtained CORBA object can be narrowed into stub using
146       * {@link PortableRemoteObject#narrow}.
147       * </p>
148       * <p>
149       * It is frequently easier to call {@link PortableRemoteObject#connect} rather
150       * than this method.
151       * </p>
152       *
153       * @param orb the ORB where the Stub must be connected.
154       *
155       * @throws RemoteException if the stub is already connected to some other ORB.
156       * If the stub is already connected to the ORB that was passed as parameter,
157       * the method returns without action.
158       *
159       * @throws BAD_PARAM if the name of this stub does not match the stub name
160       * pattern, "_*_Stub" or if the Tie class, "_*Impl_Tie", does not exists or an
161       * instance of this class cannot be instantiated.
162       */
163      public void connect(ORB orb)
164      throws RemoteException      throws RemoteException
165    {    {
166      if(delegate != null)      if (m_orb != null && orb != null)
167        delegate.connect(this, orb);        {
168            if (m_orb.equals(orb))
169              throw new RemoteException("Stub " + this
170                + " is connected to another ORB, " + orb);
171            else
172              return;
173          }
174        m_orb = orb;
175        delegate.connect(this, orb);
176    }    }
177    
178    /**    /**
179     * The following two routines are required by serialized form of Java API doc.     * Required by serialized form of Java API doc.
180     */     */
181    private void readObject(ObjectInputStream stream)    private void readObject(ObjectInputStream input)
182      throws IOException, ClassNotFoundException      throws IOException, ClassNotFoundException
183    {    {
184      if(delegate != null)      if (delegate instanceof StubDelegateImpl)
185        delegate.readObject(this, stream);        ((StubDelegateImpl) delegate).readObject(this, input, m_orb);
186        else
187          delegate.readObject(this, input);
188    }    }
189    
190    private void writeObject(ObjectOutputStream stream)    /**
191       * Required by serialized form of Java API doc.
192       */
193      private void writeObject(ObjectOutputStream output)
194      throws IOException      throws IOException
195    {    {
196      if(delegate != null)      // The m_orb in this case may be either known or not.
197        delegate.writeObject(this, stream);      if (delegate instanceof StubDelegateImpl)
198    }        ((StubDelegateImpl) delegate).writeObject(this, output, m_orb);
199        else
200    
201  }        delegate.writeObject(this, output);
202      }
203    }

Legend:
Removed from v.1.3.2.2  
changed lines
  Added in v.1.3.2.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26