tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / javaunohelper / test / com / sun / star / lib / uno / helper / Factory_Test.java
blobbb0a605ebc7c77dc43faa9aaeeef96f33a1f16ae
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package com.sun.star.lib.uno.helper;
20 import com.sun.star.uno.XComponentContext;
21 import com.sun.star.uno.Type;
22 import com.sun.star.uno.AnyConverter;
23 import com.sun.star.lang.XServiceInfo;
24 import com.sun.star.lang.XSingleComponentFactory;
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.lang.XComponent;
27 import com.sun.star.beans.XPropertySet;
28 import com.sun.star.registry.XRegistryKey;
29 import com.sun.star.registry.XSimpleRegistry;
30 import com.sun.star.registry.XImplementationRegistration;
31 import com.sun.star.container.XSet;
33 import com.sun.star.comp.helper.RegistryServiceFactory;
34 import com.sun.star.uno.UnoRuntime;
37 @Deprecated
38 public class Factory_Test
39 extends WeakBase
40 implements XServiceInfo
42 static final String m_impl_name = Factory_Test.class.getName();
43 static final String m_supported_services [] = {
44 "Factory_Test.Service0", "Factory_Test.Service1" };
47 public Factory_Test()
51 public Factory_Test( XComponentContext xContext )
53 if (null == xContext.getValueByName( "/singletons/com.sun.star.lang.theServiceManager" ))
55 throw new com.sun.star.uno.RuntimeException(
56 "bad component context given!", this );
60 public static Object __create( XComponentContext xContext )
62 return new Factory_Test( xContext );
65 // XServiceInfo impl
67 public final String getImplementationName()
69 return m_impl_name;
72 public final boolean supportsService( String service_name )
74 for ( int nPos = 0; nPos < m_supported_services.length; ++nPos )
76 if (m_supported_services[ nPos ].equals( service_name ))
77 return true;
79 return false;
82 public final String [] getSupportedServiceNames()
84 return m_supported_services;
88 public static XSingleComponentFactory __getComponentFactory( String implName )
90 if (implName.equals( m_impl_name ))
92 return Factory.createComponentFactory(
93 Factory_Test.class, Factory_Test.m_supported_services );
95 return null;
98 public static boolean __writeRegistryServiceInfo( XRegistryKey xKey )
100 return Factory.writeRegistryServiceInfo(
101 m_impl_name, Factory_Test.m_supported_services, xKey );
105 static void service_info_test( Object inst )
107 XServiceInfo xInfo = UnoRuntime.queryInterface( XServiceInfo.class, inst );
109 if (! xInfo.getImplementationName().equals( m_impl_name ))
111 System.err.println( "Factory_Test: err -- 1" );
112 System.exit( 1 );
114 String supported_services [] = xInfo.getSupportedServiceNames();
115 if (supported_services.length != m_supported_services.length)
117 System.err.println( "Factory_Test: err -- 2" );
118 System.exit( 1 );
120 for ( int nPos = 0; nPos < supported_services.length; ++nPos )
122 if (! supported_services[ nPos ].equals( m_supported_services[ nPos ] ))
124 System.err.println( "Factory_Test: err -- 3" );
125 System.exit( 1 );
127 if (! xInfo.supportsService( m_supported_services[ nPos ] ))
129 System.err.println( "Factory_Test: err -- 4" );
130 System.exit( 1 );
135 public static void main( String args [] )
139 String jar = "file://" + new java.io.File( args[ 0 ] ).toURL().getPath();
140 String rdb = "file://" + new java.io.File( args[ 1 ] ).toURL().getPath();
141 System.out.println( "jar file = " + jar );
142 System.out.println( "rdb file = " + rdb );
144 // bootstrap service manager
145 XMultiServiceFactory xMgr = RegistryServiceFactory.create( rdb );
146 XPropertySet xProps = UnoRuntime.queryInterface(
147 XPropertySet.class, xMgr );
148 XComponentContext xContext = (XComponentContext)AnyConverter.toObject(
149 new Type( XComponentContext.class ), xProps.getPropertyValue( "DefaultContext" ) );
150 // insert java loader
151 XSet xSet = (XSet)AnyConverter.toObject(
152 new Type( XSet.class ), xContext.getServiceManager() );
153 xSet.insert( new com.sun.star.comp.loader.JavaLoaderFactory( xMgr ) );
154 // get rdb of smgr
155 XSimpleRegistry xRDB = (XSimpleRegistry)AnyConverter.toObject(
156 new Type( XSimpleRegistry.class ), xProps.getPropertyValue( "Registry" ) );
157 // register impl
158 XImplementationRegistration xImpReg =
159 UnoRuntime.queryInterface(
160 XImplementationRegistration.class,
161 xContext.getServiceManager().createInstanceWithContext(
162 "com.sun.star.registry.ImplementationRegistration", xContext ) );
163 xImpReg.registerImplementation( "com.sun.star.loader.Java2", jar, xRDB );
165 // tests
166 System.out.println( "testing instance" );
167 service_info_test( new Factory_Test() );
168 System.out.println( "testing instance" );
169 service_info_test( new Factory_Test( xContext ) );
170 System.out.println( "testing instance" );
171 service_info_test( Factory_Test.__create( xContext ) );
172 System.out.println( "testing factory __getComponentFactory()" );
173 service_info_test( __getComponentFactory( m_impl_name ) );
174 for ( int nPos = 0; nPos < m_supported_services.length; ++nPos )
176 System.out.println( "testing factory " + m_supported_services[ nPos ] );
177 service_info_test(
178 // create Service
179 xContext.getServiceManager().createInstanceWithContext(
180 m_supported_services[ nPos ], xContext ) );
183 XComponent xComp = UnoRuntime.queryInterface( XComponent.class, xContext );
184 xComp.dispose();
186 catch (Exception exc)
188 System.err.println( ">>>>>>>>>> exc occurred: " + exc.toString() );
189 exc.printStackTrace();
191 System.exit( 0 );