1*6ed2a3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6ed2a3faSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6ed2a3faSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6ed2a3faSAndrew Rist  * distributed with this work for additional information
6*6ed2a3faSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6ed2a3faSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6ed2a3faSAndrew Rist  * "License"); you may not use this file except in compliance
9*6ed2a3faSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6ed2a3faSAndrew Rist  *
11*6ed2a3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6ed2a3faSAndrew Rist  *
13*6ed2a3faSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6ed2a3faSAndrew Rist  * software distributed under the License is distributed on an
15*6ed2a3faSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6ed2a3faSAndrew Rist  * KIND, either express or implied.  See the License for the
17*6ed2a3faSAndrew Rist  * specific language governing permissions and limitations
18*6ed2a3faSAndrew Rist  * under the License.
19*6ed2a3faSAndrew Rist  *
20*6ed2a3faSAndrew Rist  *************************************************************/
21*6ed2a3faSAndrew Rist 
22*6ed2a3faSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.comp.jvmaccess.workbench;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.comp.loader.FactoryHelper;
27cdf0e10cSrcweir import com.sun.star.lang.XMain;
28cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
29cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
30cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
31cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider;
32cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
33cdf0e10cSrcweir import com.sun.star.uno.Type;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /* Deploy this component with pkgchk, and call it with the Basic program
36cdf0e10cSrcweir 
37cdf0e10cSrcweir    Sub Main
38cdf0e10cSrcweir      dim args$()
39cdf0e10cSrcweir      o = createunoservice("com.sun.star.comp.jvmaccess.workbench.TestComponent")
40cdf0e10cSrcweir      o.run args$()
41cdf0e10cSrcweir    End Sub
42cdf0e10cSrcweir 
43cdf0e10cSrcweir    The name of the context class loader should appear on the console.
44cdf0e10cSrcweir  */
45cdf0e10cSrcweir 
46cdf0e10cSrcweir public final class TestComponent implements XTypeProvider, XServiceInfo, XMain {
getTypes()47cdf0e10cSrcweir     public Type[] getTypes() {
48cdf0e10cSrcweir         return new Type[] { new Type(XTypeProvider.class),
49cdf0e10cSrcweir                             new Type(XServiceInfo.class),
50cdf0e10cSrcweir                             new Type(XMain.class) };
51cdf0e10cSrcweir     }
52cdf0e10cSrcweir 
getImplementationId()53cdf0e10cSrcweir     public byte[] getImplementationId() {
54cdf0e10cSrcweir         byte[] id = new byte[16];
55cdf0e10cSrcweir         int n = hashCode();
56cdf0e10cSrcweir         id[0] = (byte) (n & 0xFF);
57cdf0e10cSrcweir         id[1] = (byte) ((n >> 8) & 0xFF);
58cdf0e10cSrcweir         id[2] = (byte) ((n >> 16) & 0xFF);
59cdf0e10cSrcweir         id[3] = (byte) ((n >> 24) & 0xFF);
60cdf0e10cSrcweir         return id;
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir 
getImplementationName()63cdf0e10cSrcweir     public String getImplementationName() {
64cdf0e10cSrcweir         return getClass().getName();
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
supportsService(String serviceName)67cdf0e10cSrcweir     public boolean supportsService(String serviceName) {
68cdf0e10cSrcweir         return serviceName.equals(serviceName);
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
getSupportedServiceNames()71cdf0e10cSrcweir     public String[] getSupportedServiceNames() {
72cdf0e10cSrcweir         return new String[] { serviceName };
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir 
run(String[] arguments)75cdf0e10cSrcweir     public int run(String[] arguments) {
76cdf0e10cSrcweir         System.out.println("context class loader: "
77cdf0e10cSrcweir                            + Thread.currentThread().getContextClassLoader());
78cdf0e10cSrcweir         return 0;
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
__getServiceFactory( String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)81cdf0e10cSrcweir     public static XSingleServiceFactory __getServiceFactory(
82cdf0e10cSrcweir         String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         if (implName.equals(TestComponent.class.getName())) {
85cdf0e10cSrcweir             return FactoryHelper.getServiceFactory(TestComponent.class,
86cdf0e10cSrcweir                                                    serviceName, multiFactory,
87cdf0e10cSrcweir                                                    regKey);
88cdf0e10cSrcweir         } else {
89cdf0e10cSrcweir             return null;
90cdf0e10cSrcweir         }
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir 
__writeRegistryServiceInfo(XRegistryKey regKey)93cdf0e10cSrcweir     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
94cdf0e10cSrcweir         return FactoryHelper.writeRegistryServiceInfo(
95cdf0e10cSrcweir             TestComponent.class.getName(), serviceName, regKey);
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     private static final String serviceName
99cdf0e10cSrcweir     = "com.sun.star.comp.jvmaccess.workbench.TestComponent";
100cdf0e10cSrcweir }
101