001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.iiop.any;
031:
032: import org.omg.CORBA.Any;
033: import org.omg.CORBA.TypeCode;
034: import org.omg.CORBA.Principal;
035:
036: import org.omg.CORBA.portable.InputStream;
037: import org.omg.CORBA.portable.OutputStream;
038: import org.omg.CORBA.portable.Streamable;
039:
040: import com.caucho.iiop.IiopReader;
041: import com.caucho.iiop.IiopWriter;
042:
043: /**
044: * Implementation of the IIOP Any
045: */
046: public class AnyImpl extends Any {
047: private TypeCodeFactory _factory;
048:
049: private TypeCode _typeCode;
050: private Object _value;
051:
052: public AnyImpl() {
053: }
054:
055: public AnyImpl(TypeCodeFactory factory) {
056: _factory = factory;
057: }
058:
059: public InputStream create_input_stream() {
060: throw new UnsupportedOperationException();
061: }
062:
063: public OutputStream create_output_stream() {
064: throw new UnsupportedOperationException();
065: }
066:
067: public boolean equal(Any any) {
068: return this == any;
069: }
070:
071: public Any extract_any() {
072: return (Any) _value;
073: }
074:
075: public boolean extract_boolean() {
076: return (Boolean) _value;
077: }
078:
079: public char extract_char() {
080: return (Character) _value;
081: }
082:
083: public double extract_double() {
084: return (Double) _value;
085: }
086:
087: public java.math.BigDecimal extract_fixed() {
088: return (java.math.BigDecimal) _value;
089: }
090:
091: public float extract_float() {
092: return (Float) _value;
093: }
094:
095: public int extract_long() {
096: return (Integer) _value;
097: }
098:
099: public long extract_longlong() {
100: return (Long) _value;
101: }
102:
103: public org.omg.CORBA.Object extract_Object() {
104: return (org.omg.CORBA.Object) _value;
105: }
106:
107: public byte extract_octet() {
108: return (Byte) _value;
109: }
110:
111: public Principal extract_Principal() {
112: throw new UnsupportedOperationException();
113: }
114:
115: public short extract_short() {
116: return (Short) _value;
117: }
118:
119: public Streamable extract_Streamable() {
120: return (Streamable) _value;
121: }
122:
123: public String extract_string() {
124: return (String) _value;
125: }
126:
127: public TypeCode extract_TypeCode() {
128: return (TypeCode) _value;
129: }
130:
131: public int extract_ulong() {
132: return (Integer) _value;
133: }
134:
135: public long extract_ulonglong() {
136: return (Long) _value;
137: }
138:
139: public short extract_ushort() {
140: return (Short) _value;
141: }
142:
143: public java.io.Serializable extract_Value() {
144: return (java.io.Serializable) _value;
145: }
146:
147: public char extract_wchar() {
148: return (Character) _value;
149: }
150:
151: public String extract_wstring() {
152: return (String) _value;
153: }
154:
155: public void insert_any(Any v) {
156: _value = v;
157: }
158:
159: public void insert_boolean(boolean v) {
160: _typeCode = BooleanTypeCode.TYPE_CODE;
161: _value = v;
162: }
163:
164: public void insert_char(char v) {
165: _value = v;
166: }
167:
168: public void insert_double(double v) {
169: _value = v;
170: }
171:
172: public void insert_fixed(java.math.BigDecimal v) {
173: _value = v;
174: }
175:
176: public void insert_fixed(java.math.BigDecimal v, TypeCode type) {
177: throw new UnsupportedOperationException();
178: }
179:
180: public void insert_float(float v) {
181: _value = v;
182: }
183:
184: public void insert_long(int v) {
185: _value = v;
186: }
187:
188: public void insert_longlong(long v) {
189: _value = v;
190: }
191:
192: public void insert_Object(org.omg.CORBA.Object v) {
193: _value = v;
194: }
195:
196: public void insert_Object(org.omg.CORBA.Object v, TypeCode t) {
197: _value = v;
198: }
199:
200: public void insert_octet(byte v) {
201: _value = v;
202: }
203:
204: public void insert_Principal(Principal v) {
205: _value = v;
206: }
207:
208: public void insert_short(short v) {
209: _value = v;
210: }
211:
212: public void insert_Streamable(Streamable v) {
213: _value = v;
214: }
215:
216: public void insert_string(String v) {
217: _value = v;
218: }
219:
220: public void insert_TypeCode(TypeCode v) {
221: _value = v;
222: }
223:
224: public void insert_ulong(int v) {
225: _value = v;
226: }
227:
228: public void insert_ulonglong(long v) {
229: _value = v;
230: }
231:
232: public void insert_ushort(short v) {
233: _value = v;
234: }
235:
236: public void insert_Value(java.io.Serializable v) {
237: System.out.println("VALUE: " + v);
238: _typeCode = _factory.createTypeCode(v.getClass());
239: _value = v;
240: }
241:
242: public void insert_Value(java.io.Serializable v, TypeCode t) {
243: System.out.println("VALUE1: " + v + " " + t);
244: _typeCode = t;
245: _value = v;
246: }
247:
248: public void insert_wchar(char v) {
249: _value = v;
250: }
251:
252: public void insert_wstring(String v) {
253: _value = v;
254: }
255:
256: public void read_value(InputStream is, TypeCode typeCode) {
257: _typeCode = typeCode;
258:
259: _value = ((AbstractTypeCode) typeCode)
260: .readValue((IiopReader) is);
261: }
262:
263: public TypeCode type() {
264: return _typeCode;
265: }
266:
267: public void type(TypeCode t) {
268: _typeCode = t;
269: _value = null;
270: }
271:
272: public void write_value(OutputStream os) {
273: System.out.println("WRITE: " + _typeCode + " " + _value);
274: ((AbstractTypeCode) _typeCode).writeValue((IiopWriter) os,
275: _value);
276: }
277: }
|