1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 import com
.sun
.star
.beans
.Property
;
37 import com
.sun
.star
.beans
.PropertyValue
;
38 import com
.sun
.star
.lang
.XServiceInfo
;
39 import com
.sun
.star
.reflection
.XPropertyTypeDescription
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
42 public class UnoPropertyNode
extends UnoNode
{
44 private Property aProperty
;
45 private PropertyValue aPropertyValue
;
46 private String m_sPropertyName
;
47 private Object m_oUnoReturnObject
;
48 private int m_nPropertyType
= XUnoPropertyNode
.nDEFAULT
;
49 private String sLabel
= "";
52 /** Creates a new instance of UnoMethodNode */
53 public UnoPropertyNode(Property _aProperty
, Object _oUnoObject
, Object _oUnoReturnObject
) {
55 aProperty
= _aProperty
;
56 m_sPropertyName
= aProperty
.Name
;
57 m_oUnoReturnObject
= _oUnoReturnObject
;
61 public UnoPropertyNode(Property _aProperty
){
63 aProperty
= _aProperty
;
64 m_sPropertyName
= aProperty
.Name
;
65 m_oUnoReturnObject
= null;
68 public UnoPropertyNode(PropertyValue _aPropertyValue
, Object _oUnoObject
, Object _oUnoReturnObject
) {
70 m_oUnoReturnObject
= _oUnoReturnObject
;
71 aPropertyValue
= _aPropertyValue
;
72 m_sPropertyName
= aPropertyValue
.Name
;
76 public int getPropertyNodeType(){
77 return m_nPropertyType
;
81 public void setPropertyNodeType(int _nPropertyType
){
82 m_nPropertyType
= _nPropertyType
;
86 public String
getPropertyName(){
87 return m_sPropertyName
;
90 public String
getName(){
91 return this.m_sPropertyName
;
96 public String
getClassName(){
97 String sClassName
= "";
98 if (m_oUnoObject
!= null){
99 XServiceInfo xServiceInfo
= UnoRuntime
.queryInterface(XServiceInfo
.class, m_oUnoObject
);
100 if (xServiceInfo
!= null){
101 String
[] sServiceNames
= xServiceInfo
.getSupportedServiceNames();
102 for (int i
= 0; i
< sServiceNames
.length
; i
++){
103 if (doesServiceSupportProperty(sServiceNames
[i
], m_sPropertyName
)){
104 sClassName
= sServiceNames
[i
];
111 sClassName
= "com.sun.star.beans.Property";
118 public String
getAnchor(){
119 return m_sPropertyName
;
124 private boolean doesServiceSupportProperty(String _sServiceName
, String _sPropertyName
){
126 XPropertyTypeDescription
[] xPropertyTypeDescriptions
= Introspector
.getIntrospector().getPropertyDescriptionsOfService(_sServiceName
);
127 for (int i
= 0; i
< xPropertyTypeDescriptions
.length
; i
++){
128 if (xPropertyTypeDescriptions
[i
].getName().equals(_sServiceName
+ "." + _sPropertyName
)){
132 } catch ( java
.lang
.Exception e
) {
133 System
.out
.println(System
.out
);
139 public Object
getUnoReturnObject(){
140 return m_oUnoReturnObject
;
144 private boolean isPrimitive(){
145 boolean bIsPrimitive
= true;
146 if (getUnoReturnObject() != null){
147 if (getProperty() != null){
148 bIsPrimitive
= Introspector
.isObjectPrimitive(getUnoReturnObject().getClass(), getProperty().Type
.getTypeClass());
151 bIsPrimitive
= Introspector
.isObjectPrimitive(getUnoReturnObject().getClass());
155 bIsPrimitive
= Introspector
.isObjectPrimitive(aProperty
.Type
.getTypeClass());
161 protected boolean isFoldable(){
162 boolean bIsFoldable
= false;
163 if (! isPrimitive()){
164 String sTypeName
= getUnoReturnObject().getClass().getName();
165 bIsFoldable
= (!sTypeName
.equals("com.sun.star.uno.Type"));
171 protected String
getLabel(){
172 if (!sLabel
.equals("")){
173 if (! isPrimitive()){
175 sLabel
= getPropertyTypeDescription(aProperty
, getUnoReturnObject());
178 sLabel
= getStandardPropertyDescription(aProperty
, getUnoReturnObject());
182 sLabel
= getStandardPropertyDescription(aProperty
, getUnoReturnObject());
188 public Property
getProperty(){
192 private static String
getPropertyTypeDescription(Property _aProperty
, Object _oUnoObject
){
193 return _aProperty
.Type
.getTypeName() + " " + _aProperty
.Name
+ " = " + _oUnoObject
.toString();
197 protected static String
getStandardPropertyDescription(Property _aProperty
, Object _objectElement
){
198 if (!Introspector
.isObjectPrimitive(_objectElement
)){
199 return _aProperty
.Name
+ " = (" + _aProperty
.Type
.getTypeName() + ") ";
202 return _aProperty
.Name
+ " (" + _aProperty
.Type
.getTypeName() + ") = " + getDisplayValueOfPrimitiveType(_objectElement
);
207 protected static String
getStandardPropertyValueDescription(PropertyValue _aPropertyValue
){
208 if (!Introspector
.isObjectPrimitive(_aPropertyValue
.Value
)){
209 return _aPropertyValue
.Name
;
212 return _aPropertyValue
.Name
+ " : " + UnoNode
.getDisplayValueOfPrimitiveType(_aPropertyValue
.Value
);
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */