DynValueBoxImpl.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
42public class DynValueBoxImpl extends DynValueCommonImpl implements DynValueBox
43{
44    //
45    // Constructors
46    //
47
48    private DynValueBoxImpl() {
49        this(null, (Any)null, false);
50    }
51
52    protected DynValueBoxImpl(ORB orb, Any any, boolean copyValue) {
53        super(orb, any, copyValue);
54    }
55
56    protected DynValueBoxImpl(ORB orb, TypeCode typeCode) {
57        super(orb, typeCode);
58    }
59
60    //
61    // DynValueBox methods
62    //
63
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
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
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
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
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
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
129    protected boolean initializeAnyFromComponents() {
130        any = getAny(components[0]);
131        return true;
132    }
133}
134