DynValueCommonImpl.java revision 608:7e06bf1dcb09
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 26package com.sun.corba.se.impl.dynamicany; 27 28import org.omg.CORBA.TypeCode; 29import org.omg.CORBA.TCKind; 30import org.omg.CORBA.Any; 31import org.omg.CORBA.TypeCodePackage.BadKind; 32import org.omg.CORBA.TypeCodePackage.Bounds; 33import org.omg.DynamicAny.*; 34import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; 35import org.omg.DynamicAny.DynAnyPackage.InvalidValue; 36import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode; 37 38import com.sun.corba.se.spi.orb.ORB ; 39import com.sun.corba.se.spi.logging.CORBALogDomains ; 40import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 41 42abstract class DynValueCommonImpl extends DynAnyComplexImpl implements DynValueCommon 43{ 44 // 45 // Constructors 46 // 47 48 protected boolean isNull; 49 50 private DynValueCommonImpl() { 51 this(null, (Any)null, false); 52 isNull = true; 53 } 54 55 protected DynValueCommonImpl(ORB orb, Any any, boolean copyValue) { 56 super(orb, any, copyValue); 57 isNull = checkInitComponents(); 58 } 59 60 protected DynValueCommonImpl(ORB orb, TypeCode typeCode) { 61 super(orb, typeCode); 62 isNull = true; 63 } 64 65 // 66 // DynValueCommon methods 67 // 68 69 // Returns TRUE if this object represents a null valuetype 70 public boolean is_null() { 71 return isNull; 72 } 73 74 // Changes the representation to a null valuetype. 75 public void set_to_null() { 76 isNull = true; 77 clearData(); 78 } 79 80 // If this object represents a null valuetype then this operation 81 // replaces it with a newly constructed value with its components 82 // initialized to default values as in DynAnyFactory::create_dyn_any_from_type_code. 83 // If this object represents a non-null valuetype, then this operation has no effect. 84 public void set_to_value() { 85 if (isNull) { 86 isNull = false; 87 // the rest is done lazily 88 } 89 // else: there is nothing to do 90 } 91 92 // 93 // Methods differing from DynStruct 94 // 95 96 // Required to raise InvalidValue if this is a null value type. 97 public org.omg.DynamicAny.NameValuePair[] get_members () 98 throws org.omg.DynamicAny.DynAnyPackage.InvalidValue 99 { 100 if (status == STATUS_DESTROYED) { 101 throw wrapper.dynAnyDestroyed() ; 102 } 103 if (isNull) { 104 throw new InvalidValue(); 105 } 106 checkInitComponents(); 107 return nameValuePairs; 108 } 109 110 // Required to raise InvalidValue if this is a null value type. 111 public org.omg.DynamicAny.NameDynAnyPair[] get_members_as_dyn_any () 112 throws org.omg.DynamicAny.DynAnyPackage.InvalidValue 113 { 114 if (status == STATUS_DESTROYED) { 115 throw wrapper.dynAnyDestroyed() ; 116 } 117 if (isNull) { 118 throw new InvalidValue(); 119 } 120 checkInitComponents(); 121 return nameDynAnyPairs; 122 } 123 124 // 125 // Overridden methods 126 // 127 128 // Overridden to change to non-null status. 129 public void set_members (org.omg.DynamicAny.NameValuePair[] value) 130 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch, 131 org.omg.DynamicAny.DynAnyPackage.InvalidValue 132 { 133 super.set_members(value); 134 // If we didn't get an exception then this must be a valid non-null value 135 isNull = false; 136 } 137 138 // Overridden to change to non-null status. 139 public void set_members_as_dyn_any (org.omg.DynamicAny.NameDynAnyPair[] value) 140 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch, 141 org.omg.DynamicAny.DynAnyPackage.InvalidValue 142 { 143 super.set_members_as_dyn_any(value); 144 // If we didn't get an exception then this must be a valid non-null value 145 isNull = false; 146 } 147} 148