1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 import com.sun.star.beans.Property; 25 import com.sun.star.beans.PropertyValue; 26 import com.sun.star.lang.XServiceInfo; 27 import com.sun.star.reflection.TypeDescriptionSearchDepth; 28 import com.sun.star.reflection.XConstantTypeDescription; 29 import com.sun.star.reflection.XPropertyTypeDescription; 30 import com.sun.star.reflection.XServiceTypeDescription; 31 import com.sun.star.reflection.XTypeDescription; 32 import com.sun.star.reflection.XTypeDescriptionEnumeration; 33 import com.sun.star.uno.AnyConverter; 34 import com.sun.star.uno.TypeClass; 35 import com.sun.star.uno.UnoRuntime; 36 import com.sun.star.uno.XComponentContext; 37 import javax.swing.tree.DefaultMutableTreeNode; 38 39 public class UnoPropertyNode extends UnoNode{ 40 41 Property aProperty; 42 PropertyValue aPropertyValue; 43 String m_sPropertyName; 44 Object m_oUnoReturnObject; 45 private int m_nPropertyType = XUnoPropertyNode.nDEFAULT; 46 private String sLabel = ""; 47 48 private static XConstantTypeDescription[] xPropertyAttributesTypeDescriptions = null; 49 50 51 /** Creates a new instance of UnoMethodNode */ UnoPropertyNode(Property _aProperty, Object _oUnoObject, Object _oUnoReturnObject)52 public UnoPropertyNode(Property _aProperty, Object _oUnoObject, Object _oUnoReturnObject) { 53 super(_oUnoObject); 54 aProperty = _aProperty; 55 m_sPropertyName = aProperty.Name; 56 m_oUnoReturnObject = _oUnoReturnObject; 57 } 58 59 UnoPropertyNode(Property _aProperty)60 public UnoPropertyNode(Property _aProperty){ 61 super(null); 62 aProperty = _aProperty; 63 m_sPropertyName = aProperty.Name; 64 m_oUnoReturnObject = null; 65 } 66 UnoPropertyNode(PropertyValue _aPropertyValue, Object _oUnoObject, Object _oUnoReturnObject)67 public UnoPropertyNode(PropertyValue _aPropertyValue, Object _oUnoObject, Object _oUnoReturnObject) { 68 super(_oUnoObject); 69 m_oUnoReturnObject = _oUnoReturnObject; 70 aPropertyValue = _aPropertyValue; 71 m_sPropertyName = aPropertyValue.Name; 72 } 73 74 getPropertyNodeType()75 public int getPropertyNodeType(){ 76 return m_nPropertyType; 77 } 78 79 setPropertyNodeType(int _nPropertyType)80 public void setPropertyNodeType(int _nPropertyType){ 81 m_nPropertyType = _nPropertyType; 82 } 83 84 getPropertyName()85 public String getPropertyName(){ 86 return m_sPropertyName; 87 } 88 getName()89 public String getName(){ 90 return this.m_sPropertyName; 91 } 92 93 getClassName()94 public String getClassName(){ 95 String sClassName = ""; 96 if (m_oUnoObject != null){ 97 XServiceInfo xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, m_oUnoObject); 98 if (xServiceInfo != null){ 99 String[] sServiceNames = xServiceInfo.getSupportedServiceNames(); 100 for (int i = 0; i < sServiceNames.length; i++){ 101 if (doesServiceSupportProperty(sServiceNames[i], m_sPropertyName)){ 102 sClassName = sServiceNames[i]; 103 break; 104 } 105 } 106 } 107 } 108 else{ 109 sClassName = "com.sun.star.beans.Property"; 110 } 111 return sClassName; 112 } 113 114 getAnchor()115 public String getAnchor(){ 116 return m_sPropertyName; 117 } 118 119 120 doesServiceSupportProperty(String _sServiceName, String _sPropertyName)121 protected boolean doesServiceSupportProperty(String _sServiceName, String _sPropertyName){ 122 try { 123 XPropertyTypeDescription[] xPropertyTypeDescriptions = Introspector.getIntrospector().getPropertyDescriptionsOfService(_sServiceName); 124 for (int i = 0; i < xPropertyTypeDescriptions.length; i++){ 125 if (xPropertyTypeDescriptions[i].getName().equals(_sServiceName + "." + _sPropertyName)){ 126 return true; 127 } 128 } 129 } catch ( java.lang.Exception e) { 130 System.out.println(System.out); 131 } 132 return false; 133 } 134 135 getUnoReturnObject()136 public Object getUnoReturnObject(){ 137 return m_oUnoReturnObject; 138 } 139 140 isPrimitive()141 private boolean isPrimitive(){ 142 boolean bIsPrimitive = true; 143 if (getUnoReturnObject() != null){ 144 if (getProperty() != null){ 145 bIsPrimitive = Introspector.isObjectPrimitive(getUnoReturnObject().getClass(), getProperty().Type.getTypeClass()); 146 } 147 else{ 148 bIsPrimitive = Introspector.isObjectPrimitive(getUnoReturnObject().getClass()); 149 } 150 } 151 else{ 152 bIsPrimitive = Introspector.isObjectPrimitive(aProperty.Type.getTypeClass()); 153 } 154 return bIsPrimitive; 155 } 156 157 isFoldable()158 protected boolean isFoldable(){ 159 boolean bIsFoldable = false; 160 if (! isPrimitive()){ 161 String sTypeName = getUnoReturnObject().getClass().getName(); 162 bIsFoldable = (!sTypeName.equals("com.sun.star.uno.Type")); 163 } 164 return bIsFoldable; 165 } 166 167 getLabel()168 protected String getLabel(){ 169 if (!sLabel.equals("")){ 170 if (! isPrimitive()){ 171 if (isFoldable()){ 172 sLabel = getPropertyTypeDescription(aProperty, getUnoReturnObject()); 173 } 174 else{ 175 sLabel = getStandardPropertyDescription(aProperty, getUnoReturnObject()); 176 } 177 } 178 else { 179 sLabel = getStandardPropertyDescription(aProperty, getUnoReturnObject()); 180 } 181 } 182 return sLabel; 183 } 184 getProperty()185 public Property getProperty(){ 186 return aProperty; 187 } 188 getPropertyTypeDescription(Property _aProperty, Object _oUnoObject)189 protected static String getPropertyTypeDescription(Property _aProperty, Object _oUnoObject){ 190 return _aProperty.Type.getTypeName() + " " + _aProperty.Name + " = " + _oUnoObject.toString(); 191 } 192 193 getStandardPropertyDescription(Property _aProperty, Object _objectElement)194 protected static String getStandardPropertyDescription(Property _aProperty, Object _objectElement){ 195 if (!Introspector.isObjectPrimitive(_objectElement)){ 196 return _aProperty.Name + " = (" + _aProperty.Type.getTypeName() + ") "; 197 } 198 else{ 199 return _aProperty.Name + " (" + _aProperty.Type.getTypeName() + ") = " + getDisplayValueOfPrimitiveType(_objectElement); 200 } 201 } 202 203 getStandardPropertyValueDescription(PropertyValue _aPropertyValue)204 protected static String getStandardPropertyValueDescription(PropertyValue _aPropertyValue){ 205 if (!Introspector.isObjectPrimitive(_aPropertyValue.Value)){ 206 return _aPropertyValue.Name; 207 } 208 else{ 209 return _aPropertyValue.Name + " : " + UnoNode.getDisplayValueOfPrimitiveType(_aPropertyValue.Value); 210 } 211 } 212 } 213 214 215