1 7 8 package com.sun.corba.se.impl.dynamicany; 9 10 import org.omg.CORBA.TypeCode ; 11 import org.omg.CORBA.Any ; 12 import org.omg.CORBA.NO_IMPLEMENT ; 13 import org.omg.CORBA.TypeCodePackage.BadKind ; 14 import org.omg.CORBA.TypeCodePackage.Bounds ; 15 import org.omg.DynamicAny.*; 16 import org.omg.DynamicAny.DynAnyPackage.TypeMismatch ; 17 import org.omg.DynamicAny.DynAnyPackage.InvalidValue ; 18 import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode ; 19 20 import com.sun.corba.se.spi.orb.ORB ; 21 import com.sun.corba.se.spi.logging.CORBALogDomains ; 22 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 23 24 abstract class DynAnyCollectionImpl extends DynAnyConstructedImpl 25 { 26 30 Any [] anys = null; 32 33 37 private DynAnyCollectionImpl() { 38 this(null, (Any )null, false); 39 } 40 41 protected DynAnyCollectionImpl(ORB orb, Any any, boolean copyValue) { 42 super(orb, any, copyValue); 43 } 44 45 protected DynAnyCollectionImpl(ORB orb, TypeCode typeCode) { 46 super(orb, typeCode); 47 } 48 49 53 protected void createDefaultComponentAt(int i, TypeCode contentType) { 54 try { 55 components[i] = DynAnyUtil.createMostDerivedDynAny(contentType, orb); 56 } catch (InconsistentTypeCode itc) { } 58 anys[i] = getAny(components[i]); 60 } 61 62 protected TypeCode getContentType() { 63 try { 64 return any.type().content_type(); 65 } catch (BadKind badKind) { return null; 67 } 68 } 69 70 protected int getBound() { 75 try { 76 return any.type().length(); 77 } catch (BadKind badKind) { return 0; 79 } 80 } 81 82 86 88 92 public org.omg.CORBA.Any [] get_elements () { 93 if (status == STATUS_DESTROYED) { 94 throw wrapper.dynAnyDestroyed() ; 95 } 96 return (checkInitComponents() ? anys : null); 97 } 98 99 protected abstract void checkValue(Object [] value) 100 throws org.omg.DynamicAny.DynAnyPackage.InvalidValue ; 101 102 public void set_elements (org.omg.CORBA.Any [] value) 109 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch , 110 org.omg.DynamicAny.DynAnyPackage.InvalidValue 111 { 112 if (status == STATUS_DESTROYED) { 113 throw wrapper.dynAnyDestroyed() ; 114 } 115 checkValue(value); 116 117 components = new DynAny[value.length]; 118 anys = value; 119 120 TypeCode expectedTypeCode = getContentType(); 122 for (int i=0; i<value.length; i++) { 123 if (value[i] != null) { 124 if (! value[i].type().equal(expectedTypeCode)) { 125 clearData(); 126 throw new TypeMismatch (); 128 } 129 try { 130 components[i] = DynAnyUtil.createMostDerivedDynAny(value[i], orb, false); 132 } catch (InconsistentTypeCode itc) { 134 throw new InvalidValue (); 135 } 136 } else { 137 clearData(); 138 throw new InvalidValue (); 140 } 141 } 142 index = (value.length == 0 ? NO_INDEX : 0); 143 representations = REPRESENTATION_COMPONENTS; 145 } 146 147 public org.omg.DynamicAny.DynAny [] get_elements_as_dyn_any () { 148 if (status == STATUS_DESTROYED) { 149 throw wrapper.dynAnyDestroyed() ; 150 } 151 return (checkInitComponents() ? components : null); 152 } 153 154 public void set_elements_as_dyn_any (org.omg.DynamicAny.DynAny [] value) 156 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch , 157 org.omg.DynamicAny.DynAnyPackage.InvalidValue 158 { 159 if (status == STATUS_DESTROYED) { 160 throw wrapper.dynAnyDestroyed() ; 161 } 162 checkValue(value); 163 164 components = (value == null ? emptyComponents : value); 165 anys = new Any [value.length]; 166 167 TypeCode expectedTypeCode = getContentType(); 169 for (int i=0; i<value.length; i++) { 170 if (value[i] != null) { 171 if (! value[i].type().equal(expectedTypeCode)) { 172 clearData(); 173 throw new TypeMismatch (); 175 } 176 anys[i] = getAny(value[i]); 177 } else { 178 clearData(); 179 throw new InvalidValue (); 181 } 182 } 183 index = (value.length == 0 ? NO_INDEX : 0); 184 representations = REPRESENTATION_COMPONENTS; 186 } 187 } 188 | Popular Tags |