01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.iiop.rmi;
23:
24: import org.omg.CORBA.Any;
25:
26: /**
27: * Constant analysis.
28: *
29: * Routines here are conforming to the "Java(TM) Language to IDL Mapping
30: * Specification", version 1.1 (01-06-07).
31: *
32: * @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
33: * @version $Revision: 57194 $
34: */
35: public class ConstantAnalysis extends AbstractAnalysis {
36: // Constants -----------------------------------------------------
37:
38: // Attributes ----------------------------------------------------
39:
40: // Static --------------------------------------------------------
41:
42: // Constructors --------------------------------------------------
43:
44: ConstantAnalysis(String javaName, Class type, Object value) {
45: super (javaName);
46:
47: if (type == Void.TYPE || !type.isPrimitive()
48: && type != java.lang.String.class)
49: throw new IllegalArgumentException(
50: "Bad type for constant: " + type.getName());
51:
52: this .type = type;
53: this .value = value;
54: }
55:
56: // Public --------------------------------------------------------
57:
58: /**
59: * Return my Java type.
60: */
61: public Class getType() {
62: return type;
63: }
64:
65: /**
66: * Return my value.
67: */
68: public Object getValue() {
69: return value;
70: }
71:
72: /**
73: * Insert the constant value into the argument Any.
74: */
75: public void insertValue(Any any) {
76: if (type == String.class)
77: any.insert_wstring((String) value); // 1.3.5.10 Map to wstring
78: else
79: Util.insertAnyPrimitive(any, value);
80: }
81:
82: // Protected -----------------------------------------------------
83:
84: // Private -------------------------------------------------------
85:
86: /**
87: * Java type of constant.
88: */
89: private Class type;
90:
91: /**
92: * The value of the constant.
93: */
94: private Object value;
95:
96: }
|