diff options
author | Joachim Lingner <jl@openoffice.org> | 2002-04-25 11:51:05 +0000 |
---|---|---|
committer | Joachim Lingner <jl@openoffice.org> | 2002-04-25 11:51:05 +0000 |
commit | 71f176caff1e04a7bd5472c0330a7c3170594df6 (patch) | |
tree | 93d571951dbbbd221e6d3a85df0c09fbb8abf410 /javaunohelper | |
parent | 9d2f110689b23e83fef2cdbd5f42142f26e99f74 (diff) |
#97746#
Diffstat (limited to 'javaunohelper')
-rw-r--r-- | javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java | 41 | ||||
-rw-r--r-- | javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java | 79 |
2 files changed, 112 insertions, 8 deletions
diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java index 6b657f743..856525b55 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java @@ -2,9 +2,9 @@ * * $RCSfile: PropertySet.java,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: jl $ $Date: 2002-04-25 11:31:36 $ + * last change: $Author: jl $ $Date: 2002-04-25 12:50:24 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -171,7 +171,7 @@ XMultiPropertySet registerProperty(p, id); } - /** Registers a property with this helper class and associates the argument id with it. + /** Registers a property with this class and associates the argument id with it. * It does the same as {@link #registerProperty(Property, Object)}. The first three * arguments are used to construct a Property object. The value for the Property.Handle * is generated and does not have to be specified here. Use this method for registering @@ -189,6 +189,41 @@ XMultiPropertySet Property p= new Property(name, lastHandle++, type, attributes); registerProperty(p, id); } + + /** Registers a property with this class. This method expects that property values + * are stored in member variables as is the case if the methods convertPropertyValue, + * setPropertyValueNoBroadcast and getPropertyValue(Property) are not overridden. + * It is presumed that the name of property is equal to the name of the member variable + * that holds the property value. It is further presumed that the type of the member variable + * corresponds Property.Type. For example, if the TypeClass of Property.Type is to be + * a TypeClass.SHORT then the member must be a short or java.lang.Short. + * The handle for the property is generated.<br> + * If there is no member with the specified name or if the member has an incompatible type + * then a com.sun.star.uno.RuntimeException is thrown. + * @param name The name of the property and the member variable that holds the property's value. + * @param attributes The property attributes. + */ + protected void registerProperty(String name, short attributes) + { + Field propField= null; + try + { + propField= getClass().getDeclaredField(name); + } + catch (NoSuchFieldException e) + { + throw new com.sun.star.uno.RuntimeException("there is no member variable: " + name); + } + Class cl= propField.getType(); + Type t= new Type(cl); + if (t.getTypeClass() != TypeClass.UNKNOWN) + { + Property p= new Property(name, lastHandle++, t, attributes); + registerProperty(p,name); + } + else + throw new com.sun.star.uno.RuntimeException("the member has an unknown type: " + name); + } /** Returns the Property object for a given property name or null if that property does * not exists (i.e. it has not been registered). Override this method diff --git a/javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java b/javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java index 11374891a..71c6af903 100644 --- a/javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java +++ b/javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java @@ -2,9 +2,9 @@ * * $RCSfile: PropertySet_Test.java,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: jl $ $Date: 2002-04-25 11:36:26 $ + * last change: $Author: jl $ $Date: 2002-04-25 12:51:05 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -1071,6 +1071,13 @@ public class PropertySet_Test TestClass2 cl= new TestClass2(); return cl.test_registerProperty1(); } + + public boolean registerProperty2() + { + TestClass2 cl= new TestClass2(); + return cl.test_registerProperty2(); + } + public static boolean test() { PropertySet_Test test= new PropertySet_Test(); @@ -1088,6 +1095,7 @@ public class PropertySet_Test r[i++]= test.addPropertiesChangeListener(); r[i++]= test.firePropertiesChangeEvent(); r[i++]= test.registerProperty1(); + r[i++]= test.registerProperty2(); boolean bOk= true; for (int c= 0; c < i; c++) bOk= bOk && r[c]; @@ -1480,9 +1488,14 @@ class TestClass extends PropertySet class TestClass2 extends PropertySet { - public TestClass2() - { - } + + public char charA; + protected char charB; + char charC; + + public Character charClassA; + protected Character charClassB; + Character charClassC; boolean test_registerProperty1() { @@ -1521,6 +1534,62 @@ class TestClass2 extends PropertySet System.out.println("Ok"); return bOk; } + + boolean test_registerProperty2() + { + System.out.println("registerProperty Test 2"); + boolean r[]= new boolean[50]; + int i= 0; + + registerProperty("charA", (short) 0); + registerProperty("charB", (short) 0); + registerProperty("charC", (short) 0); + registerProperty("charClassB", PropertyAttribute.MAYBEVOID); + + XPropertySetInfo info= getPropertySetInfo(); + Property[] props= info.getProperties(); + for (int j= 0; j < props.length; j++) + { + Property aProp= props[j]; + if (aProp.Name.equals("charA") && aProp.Type.equals(new Type(char.class)) && + aProp.Attributes == 0) + r[i++]= true; + else if (aProp.Name.equals("charB") && aProp.Type.equals(new Type(char.class)) && + aProp.Attributes == 0) + r[i++]= true; + else if (aProp.Name.equals("charC") && aProp.Type.equals(new Type(char.class)) && + aProp.Attributes == 0) + r[i++]= true; + else if (aProp.Name.equals("charClassB") && aProp.Type.equals(new Type(char.class)) && + aProp.Attributes == PropertyAttribute.MAYBEVOID) + r[i++]= true; + else + r[i++]= false; + } + Object ret; + Object val= new Character('A'); + try{ + setPropertyValue("charA", val); + ret= getPropertyValue("charA"); + r[i++]= val.equals(ret); + setPropertyValue("charClassB",val); + ret= getPropertyValue("charClassB"); + r[i++]= val.equals(ret); + } + catch(Exception e) + { + r[i++]=false; + } + boolean bOk= true; + for (int c= 0; c < i; c++) + bOk= bOk && r[c]; + if (bOk == false) + System.out.println("Failed"); + else + System.out.println("Ok"); + return bOk; + } + } class util |