1 /*************************************************************************
3 * $RCSfile: UnoPropertyNode.java,v $
7 * last change: $Author: rt $ $Date: 2007-01-30 08:15:04 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 import com
.sun
.star
.beans
.Property
;
42 import com
.sun
.star
.beans
.PropertyValue
;
43 import com
.sun
.star
.lang
.XServiceInfo
;
44 import com
.sun
.star
.reflection
.TypeDescriptionSearchDepth
;
45 import com
.sun
.star
.reflection
.XConstantTypeDescription
;
46 import com
.sun
.star
.reflection
.XPropertyTypeDescription
;
47 import com
.sun
.star
.reflection
.XServiceTypeDescription
;
48 import com
.sun
.star
.reflection
.XTypeDescription
;
49 import com
.sun
.star
.reflection
.XTypeDescriptionEnumeration
;
50 import com
.sun
.star
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.TypeClass
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XComponentContext
;
54 import javax
.swing
.tree
.DefaultMutableTreeNode
;
56 public class UnoPropertyNode
extends UnoNode
{
59 PropertyValue aPropertyValue
;
60 String m_sPropertyName
;
61 Object m_oUnoReturnObject
;
62 private int m_nPropertyType
= XUnoPropertyNode
.nDEFAULT
;
63 private String sLabel
= "";
65 private static XConstantTypeDescription
[] xPropertyAttributesTypeDescriptions
= null;
68 /** Creates a new instance of UnoMethodNode */
69 public UnoPropertyNode(Property _aProperty
, Object _oUnoObject
, Object _oUnoReturnObject
) {
71 aProperty
= _aProperty
;
72 m_sPropertyName
= aProperty
.Name
;
73 m_oUnoReturnObject
= _oUnoReturnObject
;
77 public UnoPropertyNode(Property _aProperty
){
79 aProperty
= _aProperty
;
80 m_sPropertyName
= aProperty
.Name
;
81 m_oUnoReturnObject
= null;
84 public UnoPropertyNode(PropertyValue _aPropertyValue
, Object _oUnoObject
, Object _oUnoReturnObject
) {
86 m_oUnoReturnObject
= _oUnoReturnObject
;
87 aPropertyValue
= _aPropertyValue
;
88 m_sPropertyName
= aPropertyValue
.Name
;
92 public int getPropertyNodeType(){
93 return m_nPropertyType
;
97 public void setPropertyNodeType(int _nPropertyType
){
98 m_nPropertyType
= _nPropertyType
;
102 public String
getPropertyName(){
103 return m_sPropertyName
;
106 public String
getName(){
107 return this.m_sPropertyName
;
111 public String
getClassName(){
112 String sClassName
= "";
113 if (m_oUnoObject
!= null){
114 XServiceInfo xServiceInfo
= (XServiceInfo
) UnoRuntime
.queryInterface(XServiceInfo
.class, m_oUnoObject
);
115 if (xServiceInfo
!= null){
116 String
[] sServiceNames
= xServiceInfo
.getSupportedServiceNames();
117 for (int i
= 0; i
< sServiceNames
.length
; i
++){
118 if (doesServiceSupportProperty(sServiceNames
[i
], m_sPropertyName
)){
119 sClassName
= sServiceNames
[i
];
126 sClassName
= "com.sun.star.beans.Property";
132 public String
getAnchor(){
133 return m_sPropertyName
;
138 protected boolean doesServiceSupportProperty(String _sServiceName
, String _sPropertyName
){
140 XPropertyTypeDescription
[] xPropertyTypeDescriptions
= Introspector
.getIntrospector().getPropertyDescriptionsOfService(_sServiceName
);
141 for (int i
= 0; i
< xPropertyTypeDescriptions
.length
; i
++){
142 if (xPropertyTypeDescriptions
[i
].getName().equals(_sServiceName
+ "." + _sPropertyName
)){
146 } catch ( java
.lang
.Exception e
) {
147 System
.out
.println(System
.out
);
153 public Object
getUnoReturnObject(){
154 return m_oUnoReturnObject
;
158 private boolean isPrimitive(){
159 boolean bIsPrimitive
= true;
160 if (getUnoReturnObject() != null){
161 if (getProperty() != null){
162 bIsPrimitive
= Introspector
.isObjectPrimitive(getUnoReturnObject().getClass(), getProperty().Type
.getTypeClass());
165 bIsPrimitive
= Introspector
.isObjectPrimitive(getUnoReturnObject().getClass());
169 bIsPrimitive
= Introspector
.isObjectPrimitive(aProperty
.Type
.getTypeClass());
175 protected boolean isFoldable(){
176 boolean bIsFoldable
= false;
177 if (! isPrimitive()){
178 String sTypeName
= getUnoReturnObject().getClass().getName();
179 bIsFoldable
= (!sTypeName
.equals("com.sun.star.uno.Type"));
185 protected String
getLabel(){
186 if (!sLabel
.equals("")){
187 if (! isPrimitive()){
189 sLabel
= getPropertyTypeDescription(aProperty
, getUnoReturnObject());
192 sLabel
= getStandardPropertyDescription(aProperty
, getUnoReturnObject());
196 sLabel
= getStandardPropertyDescription(aProperty
, getUnoReturnObject());
202 public Property
getProperty(){
206 protected static String
getPropertyTypeDescription(Property _aProperty
, Object _oUnoObject
){
207 return _aProperty
.Type
.getTypeName() + " " + _aProperty
.Name
+ " = " + _oUnoObject
.toString();
211 protected static String
getStandardPropertyDescription(Property _aProperty
, Object _objectElement
){
212 if (!Introspector
.isObjectPrimitive(_objectElement
)){
213 return _aProperty
.Name
+ " = (" + _aProperty
.Type
.getTypeName() + ") ";
216 return _aProperty
.Name
+ " (" + _aProperty
.Type
.getTypeName() + ") = " + getDisplayValueOfPrimitiveType(_objectElement
);
221 protected static String
getStandardPropertyValueDescription(PropertyValue _aPropertyValue
){
222 if (!Introspector
.isObjectPrimitive(_aPropertyValue
.Value
)){
223 return _aPropertyValue
.Name
;
226 return _aPropertyValue
.Name
+ " : " + UnoNode
.getDisplayValueOfPrimitiveType(_aPropertyValue
.Value
);