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: public class DynValueBoxImpl extends DynValueCommonImpl implements
043: DynValueBox {
044: //
045: // Constructors
046: //
047:
048: private DynValueBoxImpl() {
049: this (null, (Any) null, false);
050: }
051:
052: protected DynValueBoxImpl(ORB orb, Any any, boolean copyValue) {
053: super (orb, any, copyValue);
054: }
055:
056: protected DynValueBoxImpl(ORB orb, TypeCode typeCode) {
057: super (orb, typeCode);
058: }
059:
060: //
061: // DynValueBox methods
062: //
063:
064: public Any get_boxed_value()
065: throws org.omg.DynamicAny.DynAnyPackage.InvalidValue {
066: if (isNull) {
067: throw new InvalidValue();
068: }
069: checkInitAny();
070: return any;
071: }
072:
073: public void set_boxed_value(org.omg.CORBA.Any boxed)
074: throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch {
075: if (!isNull && !boxed.type().equal(this .type())) {
076: throw new TypeMismatch();
077: }
078: clearData();
079: any = boxed;
080: representations = REPRESENTATION_ANY;
081: index = 0;
082: isNull = false;
083: }
084:
085: public DynAny get_boxed_value_as_dyn_any()
086: throws org.omg.DynamicAny.DynAnyPackage.InvalidValue {
087: if (isNull) {
088: throw new InvalidValue();
089: }
090: checkInitComponents();
091: return components[0];
092: }
093:
094: public void set_boxed_value_as_dyn_any(DynAny boxed)
095: throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch {
096: if (!isNull && !boxed.type().equal(this .type())) {
097: throw new TypeMismatch();
098: }
099: clearData();
100: components = new DynAny[] { boxed };
101: representations = REPRESENTATION_COMPONENTS;
102: index = 0;
103: isNull = false;
104: }
105:
106: protected boolean initializeComponentsFromAny() {
107: try {
108: components = new DynAny[] { DynAnyUtil
109: .createMostDerivedDynAny(any, orb, false) };
110: } catch (InconsistentTypeCode ictc) {
111: return false; // impossible
112: }
113: return true;
114: }
115:
116: protected boolean initializeComponentsFromTypeCode() {
117: try {
118: any = DynAnyUtil.createDefaultAnyOfType(any.type(), orb);
119: components = new DynAny[] { DynAnyUtil
120: .createMostDerivedDynAny(any, orb, false) };
121: } catch (InconsistentTypeCode ictc) {
122: return false; // impossible
123: }
124: return true;
125: }
126:
127: protected boolean initializeAnyFromComponents() {
128: any = getAny(components[0]);
129: return true;
130: }
131: }
|