001: /*
002: * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.corba.se.impl.dynamicany;
027:
028: import org.omg.CORBA.TypeCode;
029: import org.omg.CORBA.TCKind;
030: import org.omg.CORBA.Any;
031: import org.omg.CORBA.TypeCodePackage.BadKind;
032: import org.omg.CORBA.TypeCodePackage.Bounds;
033: import org.omg.DynamicAny.*;
034: import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
035: import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
036: import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
037:
038: import com.sun.corba.se.spi.orb.ORB;
039: import com.sun.corba.se.spi.logging.CORBALogDomains;
040: import com.sun.corba.se.impl.logging.ORBUtilSystemException;
041:
042: abstract class DynValueCommonImpl extends DynAnyComplexImpl implements
043: DynValueCommon {
044: //
045: // Constructors
046: //
047:
048: protected boolean isNull;
049:
050: private DynValueCommonImpl() {
051: this (null, (Any) null, false);
052: isNull = true;
053: }
054:
055: protected DynValueCommonImpl(ORB orb, Any any, boolean copyValue) {
056: super (orb, any, copyValue);
057: isNull = checkInitComponents();
058: }
059:
060: protected DynValueCommonImpl(ORB orb, TypeCode typeCode) {
061: super (orb, typeCode);
062: isNull = true;
063: }
064:
065: //
066: // DynValueCommon methods
067: //
068:
069: // Returns TRUE if this object represents a null valuetype
070: public boolean is_null() {
071: return isNull;
072: }
073:
074: // Changes the representation to a null valuetype.
075: public void set_to_null() {
076: isNull = true;
077: clearData();
078: }
079:
080: // If this object represents a null valuetype then this operation
081: // replaces it with a newly constructed value with its components
082: // initialized to default values as in DynAnyFactory::create_dyn_any_from_type_code.
083: // If this object represents a non-null valuetype, then this operation has no effect.
084: public void set_to_value() {
085: if (isNull) {
086: isNull = false;
087: // the rest is done lazily
088: }
089: // else: there is nothing to do
090: }
091:
092: //
093: // Methods differing from DynStruct
094: //
095:
096: // Required to raise InvalidValue if this is a null value type.
097: public org.omg.DynamicAny.NameValuePair[] get_members()
098: throws org.omg.DynamicAny.DynAnyPackage.InvalidValue {
099: if (status == STATUS_DESTROYED) {
100: throw wrapper.dynAnyDestroyed();
101: }
102: if (isNull) {
103: throw new InvalidValue();
104: }
105: checkInitComponents();
106: return nameValuePairs;
107: }
108:
109: // Required to raise InvalidValue if this is a null value type.
110: public org.omg.DynamicAny.NameDynAnyPair[] get_members_as_dyn_any()
111: throws org.omg.DynamicAny.DynAnyPackage.InvalidValue {
112: if (status == STATUS_DESTROYED) {
113: throw wrapper.dynAnyDestroyed();
114: }
115: if (isNull) {
116: throw new InvalidValue();
117: }
118: checkInitComponents();
119: return nameDynAnyPairs;
120: }
121:
122: //
123: // Overridden methods
124: //
125:
126: // Overridden to change to non-null status.
127: public void set_members(org.omg.DynamicAny.NameValuePair[] value)
128: throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
129: org.omg.DynamicAny.DynAnyPackage.InvalidValue {
130: super .set_members(value);
131: // If we didn't get an exception then this must be a valid non-null value
132: isNull = false;
133: }
134:
135: // Overridden to change to non-null status.
136: public void set_members_as_dyn_any(
137: org.omg.DynamicAny.NameDynAnyPair[] value)
138: throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
139: org.omg.DynamicAny.DynAnyPackage.InvalidValue {
140: super .set_members_as_dyn_any(value);
141: // If we didn't get an exception then this must be a valid non-null value
142: isNull = false;
143: }
144: }
|