1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * The Contents of this file are made available subject to the terms of 4*cdf0e10cSrcweir * the BSD license. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * All rights reserved. 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * Redistribution and use in source and binary forms, with or without 10*cdf0e10cSrcweir * modification, are permitted provided that the following conditions 11*cdf0e10cSrcweir * are met: 12*cdf0e10cSrcweir * 1. Redistributions of source code must retain the above copyright 13*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer. 14*cdf0e10cSrcweir * 2. Redistributions in binary form must reproduce the above copyright 15*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer in the 16*cdf0e10cSrcweir * documentation and/or other materials provided with the distribution. 17*cdf0e10cSrcweir * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18*cdf0e10cSrcweir * contributors may be used to endorse or promote products derived 19*cdf0e10cSrcweir * from this software without specific prior written permission. 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*cdf0e10cSrcweir * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*cdf0e10cSrcweir * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*cdf0e10cSrcweir * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*cdf0e10cSrcweir * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*cdf0e10cSrcweir * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*cdf0e10cSrcweir * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28*cdf0e10cSrcweir * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29*cdf0e10cSrcweir * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30*cdf0e10cSrcweir * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31*cdf0e10cSrcweir * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*cdf0e10cSrcweir * 33*cdf0e10cSrcweir *************************************************************************/ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir /* 36*cdf0e10cSrcweir This example shows a UNO component that inherits com.sun.star.lib.uno.helper.PropertySet in 37*cdf0e10cSrcweir order to provide implementations of these interfaces: 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir com.sun.star.beans.XPropertySet 40*cdf0e10cSrcweir com.sun.star.beans.XMultiPropertySet 41*cdf0e10cSrcweir com.sun.star.beans.XFastPropertySet 42*cdf0e10cSrcweir com.sun.star.lang.XComponent 43*cdf0e10cSrcweir com.sun.star.uno.XWeak 44*cdf0e10cSrcweir com.sun.star.lang.XTypeProvider 45*cdf0e10cSrcweir */ 46*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.PropertySet; 47*cdf0e10cSrcweir import com.sun.star.comp.loader.FactoryHelper; 48*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 49*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 50*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 51*cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey; 52*cdf0e10cSrcweir import com.sun.star.uno.Any; 53*cdf0e10cSrcweir import com.sun.star.uno.Type; 54*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 55*cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider; 56*cdf0e10cSrcweir import com.sun.star.beans.PropertyAttribute; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir /** 59*cdf0e10cSrcweir This component contains the followin properties: 60*cdf0e10cSrcweir * <table border> 61*cdf0e10cSrcweir * <tr> 62*cdf0e10cSrcweir * <th> Property Name </th> 63*cdf0e10cSrcweir * <th> Type Name </th> 64*cdf0e10cSrcweir * <th> PropertyAttribute </th> 65*cdf0e10cSrcweir * <tr><td>boolA</td><td>BOOLEAN</td><td> - </td</tr> 66*cdf0e10cSrcweir * <tr><td>charA</td><td>CHAR</td><td> - </td></tr> 67*cdf0e10cSrcweir * <tr><td>byteA</td><td>BYTE</td><td> - </td></tr> 68*cdf0e10cSrcweir * <tr><td>shortA</td><td>SHORT</td><td> - </td></tr> 69*cdf0e10cSrcweir * <tr><td>intA</td><td>LONG</td><td> - </td></tr> 70*cdf0e10cSrcweir * <tr><td>longA</td><td>HYPER</td><td> - </td></tr> 71*cdf0e10cSrcweir * <tr><td>floatA</td><td>FLOAT</td><td> - </td></tr> 72*cdf0e10cSrcweir * <tr><td>doubleA</td><td>DOUBLE</td><td> - </td></tr> 73*cdf0e10cSrcweir * <tr><td>stringA</td><td>STRING</td><td> - </td></tr> 74*cdf0e10cSrcweir * <tr><td>objectA</td><td>ANY</td><td> - </td></tr> 75*cdf0e10cSrcweir * <tr><td>anyA</td><td>ANY</td><td> - </td></tr> 76*cdf0e10cSrcweir * <tr><td>typeA</td><td>TYPE</td><td> - </td></tr> 77*cdf0e10cSrcweir * <tr><td>xinterfaceA</td><td>INTERFACE</td><td> - </td></tr> 78*cdf0e10cSrcweir * <tr><td>xtypeproviderA</td><td>INTERFACE</td><td> - </td></tr> 79*cdf0e10cSrcweir * <tr><td>arBoolA</td><td>[]boolean</td><td> - </td></tr> 80*cdf0e10cSrcweir * <tr><td>arCharA</td><td>[]char</td><td> - </td></tr> 81*cdf0e10cSrcweir * <tr><td>arByteA</td><td>[]byte</td><td> - </td></tr> 82*cdf0e10cSrcweir * <tr><td>arShortA</td><td>[]short</td><td> - </td></tr> 83*cdf0e10cSrcweir * <tr><td>arIntA</td><td>[]long</td><td> - </td></tr> 84*cdf0e10cSrcweir * <tr><td>arLongA</td><td>[]hyper</td><td> - </td></tr> 85*cdf0e10cSrcweir * <tr><td>arFloatA</td><td>[]float</td><td> - </td></tr> 86*cdf0e10cSrcweir * <tr><td>arDoubleA</td><td>[]double</td><td> - </td></tr> 87*cdf0e10cSrcweir * <tr><td>arStringA</td><td>[]string</td><td> - </td></tr> 88*cdf0e10cSrcweir * <tr><td>arObjectA</td><td>[]any</td><td> - </td></tr> 89*cdf0e10cSrcweir * <tr><td>arXinterfaceA</td><td>[]com.sun.star.uno.XInterface</td><td> - </td></tr> 90*cdf0e10cSrcweir * <tr><td>ar2BoolA</td><td>[][]boolean</td><td> - </td></tr> 91*cdf0e10cSrcweir * <tr><td>boolClassA</td><td>boolean</td><td> - </td></tr> 92*cdf0e10cSrcweir * <tr><td>charClassA</td><td>char</td><td> - </td></tr> 93*cdf0e10cSrcweir * <tr><td>byteClassA</td><td>byte</td><td> - </td></tr> 94*cdf0e10cSrcweir * <tr><td>shortClassA</td><td>short</td><td> - </td></tr> 95*cdf0e10cSrcweir * <tr><td>intClassA</td><td>long</td><td> - </td></tr> 96*cdf0e10cSrcweir * <tr><td>longClassA</td><td>hyper</td><td> - </td></tr> 97*cdf0e10cSrcweir * <tr><td>floatClassA</td><td>float</td><td> - </td></tr> 98*cdf0e10cSrcweir * <tr><td>doubleClassA</td><td>double</td><td> - </td></tr> 99*cdf0e10cSrcweir * <tr><td>roIntA</td><td>long</td><td>READONLY</td></tr> 100*cdf0e10cSrcweir * <tr><td>roIntClassA</td><td>long</td><td>READONLY</td></tr> 101*cdf0e10cSrcweir * <tr><td>roObjectA</td><td>any</td><td>READONLY</td></tr> 102*cdf0e10cSrcweir * <tr><td>roAnyA</td><td>any</td><td>READONLY</td></tr> 103*cdf0e10cSrcweir * <tr><td>bcBoolA</td><td>boolean</td><td>BOUND,CONSTRAINED</td></tr> 104*cdf0e10cSrcweir * <tr><td>bcBoolClassA</td><td>boolean</td><td>BOUND,CONSTRAINED</td></tr> 105*cdf0e10cSrcweir * <tr><td>bcObjectA</td><td>any</td><td>BOUND,CONSTRAINED</td></tr> 106*cdf0e10cSrcweir * <tr><td>bcAnyA</td><td>any</td><td>BOUND,CONSTRAINED</td></tr> 107*cdf0e10cSrcweir * <tr><td>mvIntA</td><td>long</td><td>MAYBEVOID</td></tr> 108*cdf0e10cSrcweir * <tr><td>mvObjectA</td><td>any</td><td>MAYBEVOID</td></tr> 109*cdf0e10cSrcweir * <tr><td>mvAnyA</td><td>any</td><td>MAYBEVOID</td></tr> 110*cdf0e10cSrcweir * <tr><td>mvXinterfaceA</td><td>any</td><td>MAYBEVOID</td></tr> 111*cdf0e10cSrcweir </table> 112*cdf0e10cSrcweir */ 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir public class PropTest extends PropertySet implements XServiceInfo 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir public boolean boolA; 118*cdf0e10cSrcweir public char charA; 119*cdf0e10cSrcweir public byte byteA; 120*cdf0e10cSrcweir public short shortA; 121*cdf0e10cSrcweir public int intA; 122*cdf0e10cSrcweir public long longA; 123*cdf0e10cSrcweir public float floatA; 124*cdf0e10cSrcweir public double doubleA; 125*cdf0e10cSrcweir public String stringA; // MAYBEVOID 126*cdf0e10cSrcweir public Object objectA; // MAYBEVOID 127*cdf0e10cSrcweir public Any anyA; // MAYBEVOID 128*cdf0e10cSrcweir public Type typeA;// MAYBEVOID 129*cdf0e10cSrcweir public XInterface xinterfaceA;// MAYBEVOID 130*cdf0e10cSrcweir public XTypeProvider xtypeproviderA;// MAYBEVOID 131*cdf0e10cSrcweir public boolean[] arBoolA; // MAYBEVOID 132*cdf0e10cSrcweir public char[] arCharA; // MAYBEVOID 133*cdf0e10cSrcweir public byte[] arByteA; // MAYBEVOID 134*cdf0e10cSrcweir public short[] arShortA; // MAYBEVOID 135*cdf0e10cSrcweir public int[] arIntA; // MAYBEVOID 136*cdf0e10cSrcweir public long[] arLongA; // MAYBEVOID 137*cdf0e10cSrcweir public float[] arFloatA; // MAYBEVOID 138*cdf0e10cSrcweir public double[] arDoubleA; // MAYBEVOID 139*cdf0e10cSrcweir public String[] arStringA; // MAYBEVOID 140*cdf0e10cSrcweir public Object[] arObjectA; // MAYBEVOID 141*cdf0e10cSrcweir public Any[] arAnyA; // MAYBEVOID 142*cdf0e10cSrcweir public XInterface[] arXinterfaceA; // MAYBEVOID 143*cdf0e10cSrcweir public boolean[][] ar2BoolA; // MAYBEVOID 144*cdf0e10cSrcweir public Boolean boolClassA; // MAYBEVOID 145*cdf0e10cSrcweir public Character charClassA; // MAYBEVOID 146*cdf0e10cSrcweir public Byte byteClassA; // MAYBEVOID 147*cdf0e10cSrcweir public Short shortClassA; // MAYBEVOID 148*cdf0e10cSrcweir public Integer intClassA; // MAYBEVOID 149*cdf0e10cSrcweir public Long longClassA; // MAYBEVOID 150*cdf0e10cSrcweir public Float floatClassA; // MAYBEVOID 151*cdf0e10cSrcweir public Double doubleClassA; // MAYBEVOID 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // readonly 154*cdf0e10cSrcweir public int roIntA= 100; 155*cdf0e10cSrcweir public Integer roIntClassA= new Integer(100); 156*cdf0e10cSrcweir public Object roObjectA= new Integer(101); 157*cdf0e10cSrcweir public Any roAnyA= new Any( new Type(int.class), new Integer(102)); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir // BOUND & CONSTRAINED 160*cdf0e10cSrcweir public boolean bcBoolA; 161*cdf0e10cSrcweir public Boolean bcBoolClassA; // MAYBEVOID 162*cdf0e10cSrcweir public Object bcObjectA; // MAYBEVOID 163*cdf0e10cSrcweir public Any bcAnyA; // MAYBEVOID 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // MAYBEVOID 166*cdf0e10cSrcweir public Integer mvIntA; 167*cdf0e10cSrcweir public Object mvObjectA; 168*cdf0e10cSrcweir public Any mvAnyA; 169*cdf0e10cSrcweir public XInterface mvXinterfaceA; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir public static final String __serviceName="PropTest"; 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir public PropTest() { 174*cdf0e10cSrcweir registerProperty("boolA", (short) 0); 175*cdf0e10cSrcweir registerProperty("charA", (short) 0); 176*cdf0e10cSrcweir registerProperty("byteA", (short) 0); 177*cdf0e10cSrcweir registerProperty("shortA", (short) 0); 178*cdf0e10cSrcweir registerProperty("intA", (short) 0); 179*cdf0e10cSrcweir registerProperty("longA", (short) 0); 180*cdf0e10cSrcweir registerProperty("floatA", (short) 0); 181*cdf0e10cSrcweir registerProperty("doubleA", (short) 0); 182*cdf0e10cSrcweir registerProperty("stringA", PropertyAttribute.MAYBEVOID); 183*cdf0e10cSrcweir registerProperty("objectA", PropertyAttribute.MAYBEVOID); 184*cdf0e10cSrcweir registerProperty("anyA", PropertyAttribute.MAYBEVOID); 185*cdf0e10cSrcweir registerProperty("typeA", PropertyAttribute.MAYBEVOID); 186*cdf0e10cSrcweir registerProperty("xinterfaceA", PropertyAttribute.MAYBEVOID); 187*cdf0e10cSrcweir registerProperty("xtypeproviderA", PropertyAttribute.MAYBEVOID); 188*cdf0e10cSrcweir registerProperty("arBoolA", PropertyAttribute.MAYBEVOID); 189*cdf0e10cSrcweir registerProperty("arCharA", PropertyAttribute.MAYBEVOID); 190*cdf0e10cSrcweir registerProperty("arByteA", PropertyAttribute.MAYBEVOID); 191*cdf0e10cSrcweir registerProperty("arShortA", PropertyAttribute.MAYBEVOID); 192*cdf0e10cSrcweir registerProperty("arIntA", PropertyAttribute.MAYBEVOID); 193*cdf0e10cSrcweir registerProperty("arLongA", PropertyAttribute.MAYBEVOID); 194*cdf0e10cSrcweir registerProperty("arFloatA", PropertyAttribute.MAYBEVOID); 195*cdf0e10cSrcweir registerProperty("arDoubleA", PropertyAttribute.MAYBEVOID); 196*cdf0e10cSrcweir registerProperty("arStringA", PropertyAttribute.MAYBEVOID); 197*cdf0e10cSrcweir registerProperty("arObjectA", PropertyAttribute.MAYBEVOID); 198*cdf0e10cSrcweir registerProperty("arAnyA", PropertyAttribute.MAYBEVOID); 199*cdf0e10cSrcweir registerProperty("arXinterfaceA", PropertyAttribute.MAYBEVOID); 200*cdf0e10cSrcweir registerProperty("ar2BoolA", PropertyAttribute.MAYBEVOID); 201*cdf0e10cSrcweir registerProperty("boolClassA", PropertyAttribute.MAYBEVOID); 202*cdf0e10cSrcweir registerProperty("charClassA", PropertyAttribute.MAYBEVOID); 203*cdf0e10cSrcweir registerProperty("byteClassA", PropertyAttribute.MAYBEVOID); 204*cdf0e10cSrcweir registerProperty("shortClassA", PropertyAttribute.MAYBEVOID); 205*cdf0e10cSrcweir registerProperty("intClassA", PropertyAttribute.MAYBEVOID); 206*cdf0e10cSrcweir registerProperty("longClassA", PropertyAttribute.MAYBEVOID); 207*cdf0e10cSrcweir registerProperty("floatClassA", PropertyAttribute.MAYBEVOID); 208*cdf0e10cSrcweir registerProperty("doubleClassA", PropertyAttribute.MAYBEVOID); 209*cdf0e10cSrcweir registerProperty("roIntA", PropertyAttribute.READONLY); 210*cdf0e10cSrcweir registerProperty("roIntClassA", PropertyAttribute.READONLY); 211*cdf0e10cSrcweir registerProperty("roObjectA", PropertyAttribute.READONLY); 212*cdf0e10cSrcweir registerProperty("roAnyA", PropertyAttribute.READONLY); 213*cdf0e10cSrcweir registerProperty("bcBoolA",(short) ( PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED)); 214*cdf0e10cSrcweir registerProperty("bcBoolClassA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED | PropertyAttribute.MAYBEVOID)); 215*cdf0e10cSrcweir registerProperty("bcObjectA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED | PropertyAttribute.MAYBEVOID)); 216*cdf0e10cSrcweir registerProperty("bcAnyA", (short) (PropertyAttribute.BOUND | PropertyAttribute.CONSTRAINED |PropertyAttribute.MAYBEVOID)); 217*cdf0e10cSrcweir registerProperty("mvIntA", PropertyAttribute.MAYBEVOID); 218*cdf0e10cSrcweir registerProperty("mvObjectA", PropertyAttribute.MAYBEVOID); 219*cdf0e10cSrcweir registerProperty("mvAnyA", PropertyAttribute.MAYBEVOID); 220*cdf0e10cSrcweir registerProperty("mvXinterfaceA", PropertyAttribute.MAYBEVOID); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // XServiceName 225*cdf0e10cSrcweir public String getImplementationName( ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir return getClass().getName(); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir // XServiceName 231*cdf0e10cSrcweir public boolean supportsService( /*IN*/String name ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir if (name.equals(__serviceName)) 234*cdf0e10cSrcweir return true; 235*cdf0e10cSrcweir return false; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir //XServiceName 239*cdf0e10cSrcweir public String[] getSupportedServiceNames( ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir String[] retValue= new String[]{__serviceName}; 242*cdf0e10cSrcweir return retValue; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir public static XSingleServiceFactory __getServiceFactory(String implName, 246*cdf0e10cSrcweir XMultiServiceFactory multiFactory, 247*cdf0e10cSrcweir XRegistryKey regKey) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir XSingleServiceFactory xSingleServiceFactory = null; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir if (implName.equals( PropTest.class.getName()) ) 252*cdf0e10cSrcweir xSingleServiceFactory = FactoryHelper.getServiceFactory( PropTest.class, 253*cdf0e10cSrcweir PropTest.__serviceName, 254*cdf0e10cSrcweir multiFactory, 255*cdf0e10cSrcweir regKey); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir return xSingleServiceFactory; 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir // This method not longer necessary since OOo 3.4 where the component registration 261*cdf0e10cSrcweir // was changed to passive component registration. For more details see 262*cdf0e10cSrcweir // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir // public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) 265*cdf0e10cSrcweir // { 266*cdf0e10cSrcweir // return FactoryHelper.writeRegistryServiceInfo( PropTest.class.getName(), 267*cdf0e10cSrcweir // PropTest.__serviceName, regKey); 268*cdf0e10cSrcweir // } 269*cdf0e10cSrcweir } 270