Update ooo320-m1
[ooovba.git] / ridljar / com / sun / star / uno / Any.java
blobb76de1f8bff9e9b89941c3651dbb6ca7e85c630c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Any.java,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 package com.sun.star.uno;
35 /**
36 * The UNO IDL type any is mapped to java type <code>java.lang.Object</code>.
37 * <p>
38 * In special cases it is necessary to have an explicit any to additionally transport
39 * an exact type. For instance if you want to pass an object reference via
40 * an interprocess connection using an any, you should use this class to add
41 * an explicit interface type, so the remote counterpart doesn't need to invoke
42 * a queryInterface).
43 * <p>
44 * @version $Revision: 1.11 $ $ $Date: 2008-04-11 11:11:43 $
46 public class Any {
47 /**
48 * The type of the any.
49 * <p>
50 * @see #getType
52 protected Type _type;
54 /**
55 * The data of the any.
56 * <p>
57 * @see #getObject
59 protected Object _object;
61 public static final Any VOID = new Any(new Type("void", TypeClass.VOID),
62 null);
63 // do not use Type.VOID here to avoid circular dependencies between
64 // static members of Any and Type
66 /**
67 * Constructs a new any.
68 * <p>
69 * @param zInterface the type of the any.
70 * @param object the data of the any.
71 * @deprecated as of UDK 2.0
73 public Any(Class zInterface, Object object) {
74 this(new Type(zInterface), object);
77 /** Constructs a new any with a given type and value
78 @param type the UNO type of the any.
79 @param object the value of the any.
81 public Any(Type type, Object object) {
82 if (type.equals(Type.ANY)) {
83 throw new IllegalArgumentException("Any cannot contain Any");
85 _type = type;
86 _object = object;
89 /**
90 Complete a UNO <code>ANY</code> (make sure it is wrapped up as an
91 <code>Any</code> instance).
93 @param any a Java value representing a UNO <code>ANY</code> value.
95 @return a complete Java value (that is, an <code>Any</code> instance)
96 representing the same UNO <code>ANY</code> value as the given argument.
98 @since UDK 3.2.3
100 public static final Any complete(Object any) {
101 return any instanceof Any
102 ? (Any) any
103 : new Any(
104 new Type(any == null ? XInterface.class : any.getClass()), any);
108 * Gets the type of the value within the any.
109 * <p>
110 * @return the type of the value within the any.
112 public Type getType() {
113 return _type;
117 * Gets the value within the any.
118 * <p>
119 * @return gets the value within the any.
121 public Object getObject() {
122 return _object;
125 // @see java.lang.Object#equals
126 public boolean equals(Object obj) {
127 return obj instanceof Any && _type.equals(((Any) obj)._type)
128 && (_object == null
129 ? ((Any) obj)._object == null
130 : _object.equals(((Any) obj)._object));
133 // @see java.lang.Object#hashCode
134 public int hashCode() {
135 return _type.hashCode() * 13
136 + (_object == null ? 0 : _object.hashCode());
139 // @see java.lang.Object#toString
140 public String toString() {
141 return "Any[" + _type + ", " + _object + "]";