KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > dynamicany > DynValueBoxImpl


1 /*
2  * @(#)DynValueBoxImpl.java 1.8 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.dynamicany;
9
10 import org.omg.CORBA.TypeCode JavaDoc;
11 import org.omg.CORBA.TCKind JavaDoc;
12 import org.omg.CORBA.Any JavaDoc;
13 import org.omg.CORBA.TypeCodePackage.BadKind JavaDoc;
14 import org.omg.CORBA.TypeCodePackage.Bounds JavaDoc;
15 import org.omg.DynamicAny.*;
16 import org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc;
17 import org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc;
18 import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode JavaDoc;
19
20 import com.sun.corba.se.spi.orb.ORB ;
21 import com.sun.corba.se.spi.logging.CORBALogDomains ;
22 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
23
24 public class DynValueBoxImpl extends DynValueCommonImpl implements DynValueBox
25 {
26     //
27
// Constructors
28
//
29

30     private DynValueBoxImpl() {
31         this(null, (Any JavaDoc)null, false);
32     }
33
34     protected DynValueBoxImpl(ORB orb, Any JavaDoc any, boolean copyValue) {
35         super(orb, any, copyValue);
36     }
37
38     protected DynValueBoxImpl(ORB orb, TypeCode JavaDoc typeCode) {
39         super(orb, typeCode);
40     }
41
42     //
43
// DynValueBox methods
44
//
45

46     public Any JavaDoc get_boxed_value()
47         throws org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc
48     {
49         if (isNull) {
50             throw new InvalidValue JavaDoc();
51         }
52         checkInitAny();
53         return any;
54     }
55
56     public void set_boxed_value(org.omg.CORBA.Any JavaDoc boxed)
57         throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc
58     {
59         if ( ! isNull && ! boxed.type().equal(this.type())) {
60             throw new TypeMismatch JavaDoc();
61         }
62         clearData();
63         any = boxed;
64         representations = REPRESENTATION_ANY;
65         index = 0;
66         isNull = false;
67     }
68
69     public DynAny get_boxed_value_as_dyn_any()
70         throws org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc
71     {
72         if (isNull) {
73             throw new InvalidValue JavaDoc();
74         }
75         checkInitComponents();
76         return components[0];
77     }
78
79     public void set_boxed_value_as_dyn_any(DynAny boxed)
80         throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc
81     {
82         if ( ! isNull && ! boxed.type().equal(this.type())) {
83             throw new TypeMismatch JavaDoc();
84         }
85         clearData();
86         components = new DynAny[] {boxed};
87         representations = REPRESENTATION_COMPONENTS;
88         index = 0;
89         isNull = false;
90     }
91
92     protected boolean initializeComponentsFromAny() {
93         try {
94             components = new DynAny[] {DynAnyUtil.createMostDerivedDynAny(any, orb, false)};
95         } catch (InconsistentTypeCode JavaDoc ictc) {
96             return false; // impossible
97
}
98         return true;
99     }
100
101     protected boolean initializeComponentsFromTypeCode() {
102         try {
103             any = DynAnyUtil.createDefaultAnyOfType(any.type(), orb);
104             components = new DynAny[] {DynAnyUtil.createMostDerivedDynAny(any, orb, false)};
105         } catch (InconsistentTypeCode JavaDoc ictc) {
106             return false; // impossible
107
}
108         return true;
109     }
110
111     protected boolean initializeAnyFromComponents() {
112         any = getAny(components[0]);
113         return true;
114     }
115 }
116
Popular Tags