1*a5b190bfSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a5b190bfSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a5b190bfSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a5b190bfSAndrew Rist * distributed with this work for additional information 6*a5b190bfSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a5b190bfSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a5b190bfSAndrew Rist * "License"); you may not use this file except in compliance 9*a5b190bfSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*a5b190bfSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*a5b190bfSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a5b190bfSAndrew Rist * software distributed under the License is distributed on an 15*a5b190bfSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a5b190bfSAndrew Rist * KIND, either express or implied. See the License for the 17*a5b190bfSAndrew Rist * specific language governing permissions and limitations 18*a5b190bfSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*a5b190bfSAndrew Rist *************************************************************/ 21*a5b190bfSAndrew Rist 22*a5b190bfSAndrew Rist 23cdf0e10cSrcweir package com.sun.star.comp.helper; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 26cdf0e10cSrcweir import com.sun.star.lang.XComponent; 27cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.comp.helper.ComponentContext; 30cdf0e10cSrcweir import com.sun.star.comp.helper.ComponentContextEntry; 31cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import java.util.Hashtable; 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir public class ComponentContext_Test { main(String args[])37cdf0e10cSrcweir public static void main(String args[]) { 38cdf0e10cSrcweir try { 39cdf0e10cSrcweir Hashtable table = new Hashtable(); 40cdf0e10cSrcweir table.put( "bla1", new ComponentContextEntry( null, new Integer( 1 ) ) ); 41cdf0e10cSrcweir XComponentContext xInitialContext = Bootstrap.createInitialComponentContext( table ); 42cdf0e10cSrcweir 43cdf0e10cSrcweir table = new Hashtable(); 44cdf0e10cSrcweir table.put( "bla2", new ComponentContextEntry( new Integer( 2 ) ) ); 45cdf0e10cSrcweir table.put( "bla3", new Integer( 3 ) ); 46cdf0e10cSrcweir XComponentContext xContext = new ComponentContext( table, xInitialContext ); 47cdf0e10cSrcweir 48cdf0e10cSrcweir XMultiComponentFactory xSMgr = xContext.getServiceManager(); 49cdf0e10cSrcweir Object o = xSMgr.createInstanceWithContext( "com.sun.star.loader.Java", xContext ); 50cdf0e10cSrcweir if (o == null) 51cdf0e10cSrcweir System.err.println( "### failed raising service: 1!" ); 52cdf0e10cSrcweir o = xSMgr.createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", xContext ); 53cdf0e10cSrcweir if (o == null) 54cdf0e10cSrcweir System.err.println( "### failed raising service: 2!" ); 55cdf0e10cSrcweir o = xSMgr.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", xContext ); 56cdf0e10cSrcweir if (o == null) 57cdf0e10cSrcweir System.err.println( "### failed raising service: 3!" ); 58cdf0e10cSrcweir o = xSMgr.createInstanceWithContext( "com.sun.star.connection.Connector", xContext ); 59cdf0e10cSrcweir if (o == null) 60cdf0e10cSrcweir System.err.println( "### failed raising service: 4!" ); 61cdf0e10cSrcweir o = xSMgr.createInstanceWithContext( "com.sun.star.connection.Acceptor", xContext ); 62cdf0e10cSrcweir if (o == null) 63cdf0e10cSrcweir System.err.println( "### failed raising service: 5!" ); 64cdf0e10cSrcweir o = xSMgr.createInstanceWithContext( "com.sun.star.lang.ServiceManager", xContext ); 65cdf0e10cSrcweir if (o == null) 66cdf0e10cSrcweir System.err.println( "### failed raising service: 6!" ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir if (xContext.getValueByName( "bla1" ) == null || 69cdf0e10cSrcweir xContext.getValueByName( "bla2" ) == null || 70cdf0e10cSrcweir xContext.getValueByName( "bla3" ) == null || 71cdf0e10cSrcweir xInitialContext.getValueByName( "bla2" ) != null || 72cdf0e10cSrcweir xInitialContext.getValueByName( "bla3" ) != null) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir System.err.println( "### bootstrap context test failed: 1!" ); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir if (((Integer)xContext.getValueByName( "bla1" )).intValue() != 1 || 77cdf0e10cSrcweir ((Integer)xContext.getValueByName( "bla2" )).intValue() != 2 || 78cdf0e10cSrcweir ((Integer)xContext.getValueByName( "bla3" )).intValue() != 3 || 79cdf0e10cSrcweir ((Integer)xInitialContext.getValueByName( "bla1" )).intValue() != 1) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir System.err.println( "### bootstrap context test failed: 2!" ); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir XComponent xComp = UnoRuntime.queryInterface( 85cdf0e10cSrcweir XComponent.class, xInitialContext ); 86cdf0e10cSrcweir xComp.dispose(); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir catch(Exception exception) { 89cdf0e10cSrcweir System.err.println("exception occurred:" + exception); 90cdf0e10cSrcweir exception.printStackTrace(); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir } 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir 96