1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 import com.sun.star.uno.XComponentContext;
35 import com.sun.star.lang.XTypeProvider;
36 import com.sun.star.lang.XServiceInfo;
37 import com.sun.star.test.XSomethingB;
38 import com.sun.star.uno.Type;
39 
40 // TestComponentB implements all necessary interfaces self, this is only
41 // for demonstration. More convenient is to use the impelmentation WeakBase or
42 // ComponentBase, see implementation of TestComponentA.
43 public class TestComponentB implements XTypeProvider, XServiceInfo, XSomethingB {
44 	static final String __serviceName= "com.sun.star.test.SomethingB";
45 
46    	static byte[] _implementationId;
47 	private XComponentContext context;
48 	private Object[] args;
49 
50 	public TestComponentB(XComponentContext context, Object[] args) {
51 		this.context= context;
52 		this.args= args;
53 	}
54 
55     // XSomethingB
56 	public String methodTwo(String val) {
57 		if (args.length > 0 && args[0] instanceof String )
58 			return (String) args[0];
59 		return val;
60 	}
61 
62 	//XTypeProvider
63 	public com.sun.star.uno.Type[] getTypes(  ) {
64 		Type[] retValue= new Type[3];
65 		retValue[0]= new Type( XServiceInfo.class);
66 		retValue[1]= new Type( XTypeProvider.class);
67 		retValue[2]= new Type( XSomethingB.class);
68 		return retValue;
69 	}
70 	//XTypeProvider
71 	synchronized public byte[] getImplementationId(  ) {
72 		if (_implementationId == null) {
73 			_implementationId= new byte[16];
74 			int hash = hashCode();
75 			_implementationId[0] = (byte)(hash & 0xff);
76 			_implementationId[1] = (byte)((hash >>> 8) & 0xff);
77 			_implementationId[2] = (byte)((hash >>> 16) & 0xff);
78 			_implementationId[3] = (byte)((hash >>>24) & 0xff);
79 		}
80 		return _implementationId;
81 	}
82 
83     //XServiceInfo
84 	public String getImplementationName(  ) {
85 		return getClass().getName();
86 	}
87 
88 	// XServiceInfo
89 	public boolean supportsService( /*IN*/String serviceName ) {
90 		if ( serviceName.equals( __serviceName))
91 			return true;
92 		return false;
93 	}
94 	//XServiceInfo
95 	public String[] getSupportedServiceNames(  ) {
96 		String[] retValue= new String[0];
97 		retValue[0]= __serviceName;
98 		return retValue;
99 	}
100 }
101