Frames | No Frames |
1: /* Local_delegate.java -- 2: Copyright (C) 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package gnu.CORBA; 40: 41: import org.omg.CORBA.Context; 42: import org.omg.CORBA.ContextList; 43: import org.omg.CORBA.ExceptionList; 44: import org.omg.CORBA.NO_IMPLEMENT; 45: import org.omg.CORBA.NVList; 46: import org.omg.CORBA.NamedValue; 47: import org.omg.CORBA.ORB; 48: import org.omg.CORBA.Request; 49: import org.omg.CORBA.portable.Delegate; 50: import org.omg.CORBA.portable.ObjectImpl; 51: 52: /** 53: * The delegate, implementing the basic functionality only. This delegate 54: * is set in {@link ORG.connect(org.omg.CORBA.Object)} if ORB 55: * determines that the object is an instance of the 56: * {@link org.omg.CORBA.portable.ObjectImpl} and no other delegate is set. 57: * 58: * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) 59: */ 60: public class SimpleDelegate 61: extends Delegate 62: implements IorProvider 63: { 64: /** 65: * The orb. 66: */ 67: protected final ORB orb; 68: 69: /** 70: * The ior. 71: */ 72: protected IOR ior; 73: 74: public SimpleDelegate(ORB an_orb, IOR an_ior) 75: { 76: orb = an_orb; 77: ior = an_ior; 78: } 79: 80: /** 81: * Set the IOR of this object. The IOR must be newly set if 82: * the server reports that the object has permanently moved to a new 83: * location. 84: * 85: * @param an_ior the new IOR. 86: */ 87: public void setIor(IOR an_ior) 88: { 89: this.ior = an_ior; 90: } 91: 92: /** 93: * Get the IOR of this object. 94: */ 95: public IOR getIor() 96: { 97: return ior; 98: } 99: 100: /** 101: * Not implemented. 102: * 103: * @throws NO_IMPLEMENT, always. 104: */ 105: public Request create_request(org.omg.CORBA.Object target, Context context, 106: String operation, NVList parameters, 107: NamedValue returns 108: ) 109: { 110: throw new NO_IMPLEMENT(); 111: } 112: 113: /** 114: * Not implemented. 115: * 116: * @throws NO_IMPLEMENT, always. 117: */ 118: public Request create_request(org.omg.CORBA.Object target, Context context, 119: String operation, NVList parameters, 120: NamedValue returns, ExceptionList exceptions, 121: ContextList ctx_list 122: ) 123: { 124: throw new NO_IMPLEMENT(); 125: } 126: 127: /** 128: * Not implemented. 129: * 130: * @throws NO_IMPLEMENT, always. 131: */ 132: public org.omg.CORBA.Object duplicate(org.omg.CORBA.Object target) 133: { 134: throw new NO_IMPLEMENT(); 135: } 136: 137: /** 138: * Performs direct comparison ('=='). 139: */ 140: public boolean equals(org.omg.CORBA.Object self, org.omg.CORBA.Object other) 141: { 142: return self == other; 143: } 144: 145: /** 146: * Not implemented. 147: * 148: * @throws NO_IMPLEMENT, always. 149: */ 150: public org.omg.CORBA.Object get_interface_def(org.omg.CORBA.Object target) 151: { 152: throw new NO_IMPLEMENT(); 153: } 154: 155: /** 156: * Return the hashcode (0 <= hashcode < maximum). 157: */ 158: public int hash(org.omg.CORBA.Object target, int maximum) 159: { 160: return target == null ? 0 : target.hashCode() % maximum; 161: } 162: 163: /** 164: * Delegates functionality to java.lang.Object.hashCode(); 165: */ 166: public int hashCode(org.omg.CORBA.Object target) 167: { 168: return target == null ? 0 : target.hashCode(); 169: } 170: 171: /** 172: * Check if this object can be referenced by the given repository id. 173: * 174: * @param target the CORBA object, must be an instance of 175: * {@link org.omg.CORBA.portable.ObjectImpl}. 176: * 177: * @param repositoryIdentifer the repository id. 178: * 179: * @return true if the passed parameter is a repository id of this 180: * CORBA object. 181: */ 182: public boolean is_a(org.omg.CORBA.Object target, String repositoryIdentifer) 183: { 184: if (!(target instanceof ObjectImpl)) 185: throw new NO_IMPLEMENT("Supported only for org.omg.CORBA.portable.ObjectImpl"); 186: 187: ObjectImpl imp = (ObjectImpl) target; 188: String[] ids = imp._ids(); 189: 190: for (int i = 0; i < ids.length; i++) 191: { 192: if (ids [ i ].equals(repositoryIdentifer)) 193: return true; 194: } 195: return false; 196: } 197: 198: /** 199: * Returns true if the objects are the same or have the same delegate set. All 200: * objects in this implementation have a separate delegate. 201: */ 202: public boolean is_equivalent(org.omg.CORBA.Object target, 203: org.omg.CORBA.Object other) 204: { 205: if (target == other) 206: return true; 207: if ((target instanceof ObjectImpl) && other instanceof ObjectImpl) 208: { 209: try 210: { 211: org.omg.CORBA.portable.Delegate a = ((ObjectImpl) target)._get_delegate(); 212: org.omg.CORBA.portable.Delegate b = ((ObjectImpl) other)._get_delegate(); 213: if (a == b) 214: { 215: return true; 216: } 217: else 218: { 219: // We compere the IOR's in this case. 220: if (a instanceof IorProvider && b instanceof IorProvider) 221: { 222: IOR ia = ((IorProvider) a).getIor(); 223: IOR ib = ((IorProvider) b).getIor(); 224: 225: if (ia != null && ib != null) 226: return (ia.equals(ib)); 227: else 228: return ia == ib; 229: } 230: } 231: if (a != null && b != null) 232: { 233: return a.equals(b); 234: } 235: } 236: catch (Exception ex) 237: { 238: // Unable to get one of the delegates. 239: return false; 240: } 241: } 242: return false; 243: } 244: 245: /** 246: * Returns true by default. 247: */ 248: public boolean is_local(org.omg.CORBA.Object self) 249: { 250: return true; 251: } 252: 253: /** 254: * Returns true if the target is null. 255: */ 256: public boolean non_existent(org.omg.CORBA.Object target) 257: { 258: return target == null; 259: } 260: 261: /** 262: * Returns the ORB, passed in constructor, 263: * regardless of the argument. This class requires a single instance 264: * per each object. 265: */ 266: public ORB orb(org.omg.CORBA.Object target) 267: { 268: return orb; 269: } 270: 271: /** 272: * Returns without action. 273: */ 274: public void release(org.omg.CORBA.Object target) 275: { 276: } 277: 278: /** 279: * This method assumes that the target is local and connected to the ORB. 280: */ 281: public Request request(org.omg.CORBA.Object target, String operation) 282: { 283: if (orb instanceof OrbFunctional) 284: { 285: ((OrbFunctional) orb).ensureRunning(); 286: } 287: gnuRequest g = new gnuRequest(); 288: g.setORB(orb); 289: g.setOperation(operation); 290: g.setIor(ior); 291: g.m_target = target; 292: return g; 293: }