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