1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package com.sun.star.comp.jvmaccess.workbench;
29 
30 import com.sun.star.comp.loader.FactoryHelper;
31 import com.sun.star.lang.XMain;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.lang.XServiceInfo;
34 import com.sun.star.lang.XSingleServiceFactory;
35 import com.sun.star.lang.XTypeProvider;
36 import com.sun.star.registry.XRegistryKey;
37 import com.sun.star.uno.Type;
38 
39 /* Deploy this component with pkgchk, and call it with the Basic program
40 
41    Sub Main
42      dim args$()
43      o = createunoservice("com.sun.star.comp.jvmaccess.workbench.TestComponent")
44      o.run args$()
45    End Sub
46 
47    The name of the context class loader should appear on the console.
48  */
49 
50 public final class TestComponent implements XTypeProvider, XServiceInfo, XMain {
51     public Type[] getTypes() {
52         return new Type[] { new Type(XTypeProvider.class),
53                             new Type(XServiceInfo.class),
54                             new Type(XMain.class) };
55     }
56 
57     public byte[] getImplementationId() {
58         byte[] id = new byte[16];
59         int n = hashCode();
60         id[0] = (byte) (n & 0xFF);
61         id[1] = (byte) ((n >> 8) & 0xFF);
62         id[2] = (byte) ((n >> 16) & 0xFF);
63         id[3] = (byte) ((n >> 24) & 0xFF);
64         return id;
65     }
66 
67     public String getImplementationName() {
68         return getClass().getName();
69     }
70 
71     public boolean supportsService(String serviceName) {
72         return serviceName.equals(serviceName);
73     }
74 
75     public String[] getSupportedServiceNames() {
76         return new String[] { serviceName };
77     }
78 
79     public int run(String[] arguments) {
80         System.out.println("context class loader: "
81                            + Thread.currentThread().getContextClassLoader());
82         return 0;
83     }
84 
85     public static XSingleServiceFactory __getServiceFactory(
86         String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)
87     {
88         if (implName.equals(TestComponent.class.getName())) {
89             return FactoryHelper.getServiceFactory(TestComponent.class,
90                                                    serviceName, multiFactory,
91                                                    regKey);
92         } else {
93             return null;
94         }
95     }
96 
97     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
98         return FactoryHelper.writeRegistryServiceInfo(
99             TestComponent.class.getName(), serviceName, regKey);
100     }
101 
102     private static final String serviceName
103     = "com.sun.star.comp.jvmaccess.workbench.TestComponent";
104 }
105