2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 package com
.sun
.star
.uno
;
24 * The UNO IDL type any is mapped to java type <code>java.lang.Object</code>.
26 * In special cases it is necessary to have an explicit any to additionally transport
27 * an exact type. For instance if you want to pass an object reference via
28 * an interprocess connection using an any, you should use this class to add
29 * an explicit interface type, so the remote counterpart doesn't need to invoke
35 * The type of the any.
42 * The data of the any.
46 protected Object _object
;
48 public static final Any VOID
= new Any(new Type("void", TypeClass
.VOID
),
50 // do not use Type.VOID here to avoid circular dependencies between
51 // static members of Any and Type
54 * Constructs a new any.
56 * @param zInterface the type of the any.
57 * @param object the data of the any.
58 * @deprecated as of UDK 2.0
61 public Any(Class
<?
> zInterface
, Object object
) {
62 this(new Type(zInterface
), object
);
66 * Constructs a new any with a given type and value
68 * @param type the UNO type of the any.
69 * @param object the value of the any.
71 public Any(Type type
, Object object
) {
72 if (type
.equals(Type
.ANY
)) {
73 throw new IllegalArgumentException("Any cannot contain Any");
80 * Complete a UNO <code>ANY</code> (make sure it is wrapped up as an
81 * <code>Any</code> instance).
83 * @param any a Java value representing a UNO <code>ANY</code> value.
84 * @return a complete Java value (that is, an <code>Any</code> instance)
85 * representing the same UNO <code>ANY</code> value as the given argument.
88 public static final Any
complete(Object any
) {
89 return any
instanceof Any
92 new Type(any
== null ? XInterface
.class : any
.getClass()), any
);
96 * Gets the type of the value within the any.
98 * @return the type of the value within the any.
100 public Type
getType() {
105 * Gets the value within the any.
107 * @return gets the value within the any.
109 public Object
getObject() {
114 * Indicates whether some other object is equal to this one.
116 * @param obj the reference object with which to compare.
117 * @return <code>true</code> if this object is the same as the obj argument;
118 * <code>false</code> otherwise.
119 * @see java.lang.Object#equals
122 public boolean equals(Object obj
) {
123 return obj
instanceof Any
&& _type
.equals(((Any
) obj
)._type
)
125 ?
((Any
) obj
)._object
== null
126 : _object
.equals(((Any
) obj
)._object
));
130 * Returns a hash code value for the object.
132 * @return a hash code value for this object.
133 * @see java.lang.Object#hashCode
136 public int hashCode() {
137 return _type
.hashCode() * 13
138 + (_object
== null ?
0 : _object
.hashCode());
142 * Returns a string representation of the object.
144 * @return a string representation of the object.
145 * @see java.lang.Object#toString
148 public String
toString() {
149 return "Any[" + _type
+ ", " + _object
+ "]";