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 import com.sun.star.uno.XComponentContext; 24 import com.sun.star.lang.XTypeProvider; 25 import com.sun.star.lang.XServiceInfo; 26 import com.sun.star.test.XSomethingB; 27 import com.sun.star.uno.Type; 28 29 // TestComponentB implements all necessary interfaces self, this is only 30 // for demonstration. More convenient is to use the impelmentation WeakBase or 31 // ComponentBase, see implementation of TestComponentA. 32 public class TestComponentB implements XTypeProvider, XServiceInfo, XSomethingB { 33 static final String __serviceName= "com.sun.star.test.SomethingB"; 34 35 static byte[] _implementationId; 36 private XComponentContext context; 37 private Object[] args; 38 TestComponentB(XComponentContext context, Object[] args)39 public TestComponentB(XComponentContext context, Object[] args) { 40 this.context= context; 41 this.args= args; 42 } 43 44 // XSomethingB methodTwo(String val)45 public String methodTwo(String val) { 46 if (args.length > 0 && args[0] instanceof String ) 47 return (String) args[0]; 48 return val; 49 } 50 51 //XTypeProvider getTypes( )52 public com.sun.star.uno.Type[] getTypes( ) { 53 Type[] retValue= new Type[3]; 54 retValue[0]= new Type( XServiceInfo.class); 55 retValue[1]= new Type( XTypeProvider.class); 56 retValue[2]= new Type( XSomethingB.class); 57 return retValue; 58 } 59 //XTypeProvider getImplementationId( )60 synchronized public byte[] getImplementationId( ) { 61 if (_implementationId == null) { 62 _implementationId= new byte[16]; 63 int hash = hashCode(); 64 _implementationId[0] = (byte)(hash & 0xff); 65 _implementationId[1] = (byte)((hash >>> 8) & 0xff); 66 _implementationId[2] = (byte)((hash >>> 16) & 0xff); 67 _implementationId[3] = (byte)((hash >>>24) & 0xff); 68 } 69 return _implementationId; 70 } 71 72 //XServiceInfo getImplementationName( )73 public String getImplementationName( ) { 74 return getClass().getName(); 75 } 76 77 // XServiceInfo supportsService( String serviceName )78 public boolean supportsService( /*IN*/String serviceName ) { 79 if ( serviceName.equals( __serviceName)) 80 return true; 81 return false; 82 } 83 //XServiceInfo getSupportedServiceNames( )84 public String[] getSupportedServiceNames( ) { 85 String[] retValue= new String[0]; 86 retValue[0]= __serviceName; 87 return retValue; 88 } 89 } 90