merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Components / JavaComponent / TestComponentB.java
bloba123f8c7f3b3a7be4b49993f103a1527f170cbab
1 /*************************************************************************
3 * $RCSfile: TestComponentB.java,v $
5 * $Revision: 1.4 $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:15:25 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
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
17 * are met:
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 *************************************************************************/
40 import com.sun.star.uno.XComponentContext;
41 import com.sun.star.lang.XTypeProvider;
42 import com.sun.star.lang.XServiceInfo;
43 import com.sun.star.test.XSomethingB;
44 import com.sun.star.uno.Type;
46 // TestComponentB implements all necessary interfaces self, this is only
47 // for demonstration. More convenient is to use the impelmentation WeakBase or
48 // ComponentBase, see implementation of TestComponentA.
49 public class TestComponentB implements XTypeProvider, XServiceInfo, XSomethingB {
50 static final String __serviceName= "com.sun.star.test.SomethingB";
52 static byte[] _implementationId;
53 private XComponentContext context;
54 private Object[] args;
56 public TestComponentB(XComponentContext context, Object[] args) {
57 this.context= context;
58 this.args= args;
61 // XSomethingB
62 public String methodTwo(String val) {
63 if (args.length > 0 && args[0] instanceof String )
64 return (String) args[0];
65 return val;
68 //XTypeProvider
69 public com.sun.star.uno.Type[] getTypes( ) {
70 Type[] retValue= new Type[3];
71 retValue[0]= new Type( XServiceInfo.class);
72 retValue[1]= new Type( XTypeProvider.class);
73 retValue[2]= new Type( XSomethingB.class);
74 return retValue;
76 //XTypeProvider
77 synchronized public byte[] getImplementationId( ) {
78 if (_implementationId == null) {
79 _implementationId= new byte[16];
80 int hash = hashCode();
81 _implementationId[0] = (byte)(hash & 0xff);
82 _implementationId[1] = (byte)((hash >>> 8) & 0xff);
83 _implementationId[2] = (byte)((hash >>> 16) & 0xff);
84 _implementationId[3] = (byte)((hash >>>24) & 0xff);
86 return _implementationId;
89 //XServiceInfo
90 public String getImplementationName( ) {
91 return getClass().getName();
94 // XServiceInfo
95 public boolean supportsService( /*IN*/String serviceName ) {
96 if ( serviceName.equals( __serviceName))
97 return true;
98 return false;
100 //XServiceInfo
101 public String[] getSupportedServiceNames( ) {
102 String[] retValue= new String[0];
103 retValue[0]= __serviceName;
104 return retValue;