1 /* 2 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.corba.se.impl.dynamicany; 27 28 import org.omg.CORBA.TypeCode; 29 import org.omg.CORBA.TCKind; 30 import org.omg.CORBA.Any; 31 import org.omg.CORBA.TypeCodePackage.BadKind; 32 import org.omg.CORBA.TypeCodePackage.Bounds; 33 import org.omg.DynamicAny.*; 34 import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; 35 import org.omg.DynamicAny.DynAnyPackage.InvalidValue; 36 import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode; 37 38 import com.sun.corba.se.spi.orb.ORB ; 39 import com.sun.corba.se.spi.logging.CORBALogDomains ; 40 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 41 42 public class DynValueBoxImpl extends DynValueCommonImpl implements DynValueBox 43 { 44 // 45 // Constructors 46 // 47 DynValueBoxImpl()48 private DynValueBoxImpl() { 49 this(null, (Any)null, false); 50 } 51 DynValueBoxImpl(ORB orb, Any any, boolean copyValue)52 protected DynValueBoxImpl(ORB orb, Any any, boolean copyValue) { 53 super(orb, any, copyValue); 54 } 55 DynValueBoxImpl(ORB orb, TypeCode typeCode)56 protected DynValueBoxImpl(ORB orb, TypeCode typeCode) { 57 super(orb, typeCode); 58 } 59 60 // 61 // DynValueBox methods 62 // 63 get_boxed_value()64 public Any get_boxed_value() 65 throws org.omg.DynamicAny.DynAnyPackage.InvalidValue 66 { 67 if (isNull) { 68 throw new InvalidValue(); 69 } 70 checkInitAny(); 71 return any; 72 } 73 set_boxed_value(org.omg.CORBA.Any boxed)74 public void set_boxed_value(org.omg.CORBA.Any boxed) 75 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch 76 { 77 if ( ! isNull && ! boxed.type().equal(this.type())) { 78 throw new TypeMismatch(); 79 } 80 clearData(); 81 any = boxed; 82 representations = REPRESENTATION_ANY; 83 index = 0; 84 isNull = false; 85 } 86 get_boxed_value_as_dyn_any()87 public DynAny get_boxed_value_as_dyn_any() 88 throws org.omg.DynamicAny.DynAnyPackage.InvalidValue 89 { 90 if (isNull) { 91 throw new InvalidValue(); 92 } 93 checkInitComponents(); 94 return components[0]; 95 } 96 set_boxed_value_as_dyn_any(DynAny boxed)97 public void set_boxed_value_as_dyn_any(DynAny boxed) 98 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch 99 { 100 if ( ! isNull && ! boxed.type().equal(this.type())) { 101 throw new TypeMismatch(); 102 } 103 clearData(); 104 components = new DynAny[] {boxed}; 105 representations = REPRESENTATION_COMPONENTS; 106 index = 0; 107 isNull = false; 108 } 109 initializeComponentsFromAny()110 protected boolean initializeComponentsFromAny() { 111 try { 112 components = new DynAny[] {DynAnyUtil.createMostDerivedDynAny(any, orb, false)}; 113 } catch (InconsistentTypeCode ictc) { 114 return false; // impossible 115 } 116 return true; 117 } 118 initializeComponentsFromTypeCode()119 protected boolean initializeComponentsFromTypeCode() { 120 try { 121 any = DynAnyUtil.createDefaultAnyOfType(any.type(), orb); 122 components = new DynAny[] {DynAnyUtil.createMostDerivedDynAny(any, orb, false)}; 123 } catch (InconsistentTypeCode ictc) { 124 return false; // impossible 125 } 126 return true; 127 } 128 initializeAnyFromComponents()129 protected boolean initializeAnyFromComponents() { 130 any = getAny(components[0]); 131 return true; 132 } 133 } 134