1 7 8 package com.sun.corba.se.impl.dynamicany; 9 10 import org.omg.CORBA.Any ; 11 import org.omg.CORBA.TypeCode ; 12 import org.omg.CORBA.TCKind ; 13 import org.omg.CORBA.LocalObject ; 14 import org.omg.CORBA.ORBPackage.InvalidName ; 15 import org.omg.CORBA.portable.OutputStream ; 16 17 import org.omg.DynamicAny.*; 18 import org.omg.DynamicAny.DynAnyPackage.TypeMismatch ; 19 import org.omg.DynamicAny.DynAnyPackage.InvalidValue ; 20 21 import com.sun.corba.se.impl.orbutil.ORBConstants ; 22 23 import com.sun.corba.se.spi.orb.ORB ; 24 import com.sun.corba.se.spi.logging.CORBALogDomains ; 25 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 26 27 abstract class DynAnyImpl extends org.omg.CORBA.LocalObject implements DynAny 28 { 29 protected static final int NO_INDEX = -1; 30 protected static final byte STATUS_DESTROYABLE = 0; 32 protected static final byte STATUS_UNDESTROYABLE = 1; 34 protected static final byte STATUS_DESTROYED = 2; 36 37 41 protected ORB orb = null; 42 protected ORBUtilSystemException wrapper ; 43 44 protected Any any = null; 49 protected byte status = STATUS_DESTROYABLE; 51 protected int index = NO_INDEX; 52 53 57 protected DynAnyImpl() { 58 wrapper = ORBUtilSystemException.get( 59 CORBALogDomains.RPC_PRESENTATION ) ; 60 } 61 62 protected DynAnyImpl(ORB orb, Any any, boolean copyValue) { 63 this.orb = orb; 64 wrapper = ORBUtilSystemException.get( orb, 65 CORBALogDomains.RPC_PRESENTATION ) ; 66 if (copyValue) 67 this.any = DynAnyUtil.copy(any, orb); 68 else 69 this.any = any; 70 index = NO_INDEX; 72 } 73 74 protected DynAnyImpl(ORB orb, TypeCode typeCode) { 75 this.orb = orb; 76 wrapper = ORBUtilSystemException.get( orb, 77 CORBALogDomains.RPC_PRESENTATION ) ; 78 this.any = DynAnyUtil.createDefaultAnyOfType(typeCode, orb); 79 } 80 81 protected DynAnyFactory factory() { 82 try { 83 return (DynAnyFactory)orb.resolve_initial_references( 84 ORBConstants.DYN_ANY_FACTORY_NAME ); 85 } catch (InvalidName in) { 86 throw new RuntimeException ("Unable to find DynAnyFactory"); 87 } 88 } 89 90 protected Any getAny() { 91 return any; 92 } 93 94 protected Any getAny(DynAny dynAny) { 97 if (dynAny instanceof DynAnyImpl) 98 return ((DynAnyImpl)dynAny).getAny(); 99 else 100 return dynAny.to_any(); 105 } 106 107 protected void writeAny(OutputStream out) { 108 any.write_value(out); 110 } 111 112 protected void setStatus(byte newStatus) { 113 status = newStatus; 114 } 115 116 protected void clearData() { 117 any.type(any.type()); 119 } 120 121 125 public org.omg.CORBA.TypeCode type() { 126 if (status == STATUS_DESTROYED) { 127 throw wrapper.dynAnyDestroyed() ; 128 } 129 return any.type(); 130 } 131 132 public void assign (org.omg.DynamicAny.DynAny dyn_any) 134 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch 135 { 136 if (status == STATUS_DESTROYED) { 137 throw wrapper.dynAnyDestroyed() ; 138 } 139 if ((any != null) && (! any.type().equal(dyn_any.type()))) { 140 throw new TypeMismatch (); 141 } 142 any = dyn_any.to_any(); 143 } 144 145 public void from_any (org.omg.CORBA.Any value) 147 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch , 148 org.omg.DynamicAny.DynAnyPackage.InvalidValue 149 { 150 if (status == STATUS_DESTROYED) { 151 throw wrapper.dynAnyDestroyed() ; 152 } 153 if ((any != null) && (! any.type().equal(value.type()))) { 154 throw new TypeMismatch (); 155 } 156 Any tempAny = null; 159 try { 160 tempAny = DynAnyUtil.copy(value, orb); 161 } catch (Exception e) { 162 throw new InvalidValue (); 163 } 164 if ( ! DynAnyUtil.isInitialized(tempAny)) { 165 throw new InvalidValue (); 166 } 167 any = tempAny; 168 } 169 170 public abstract org.omg.CORBA.Any to_any(); 171 public abstract boolean equal (org.omg.DynamicAny.DynAny dyn_any); 172 public abstract void destroy(); 173 public abstract org.omg.DynamicAny.DynAny copy(); 174 175 177 private String [] __ids = { "IDL:omg.org/DynamicAny/DynAny:1.0" }; 178 179 public String [] _ids() { 180 return __ids; 181 } 182 } 183 | Popular Tags |