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 package com.sun.star.comp.helper;
28 
29 import com.sun.star.uno.XComponentContext;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiComponentFactory;
32 
33 import com.sun.star.comp.helper.ComponentContext;
34 import com.sun.star.comp.helper.ComponentContextEntry;
35 import com.sun.star.uno.UnoRuntime;
36 
37 import java.util.Hashtable;
38 
39 
40 public class ComponentContext_Test {
41 	public static void main(String args[]) {
42 		try {
43             Hashtable table = new Hashtable();
44             table.put( "bla1", new ComponentContextEntry( null, new Integer( 1 ) ) );
45             XComponentContext xInitialContext = Bootstrap.createInitialComponentContext( table );
46 
47             table = new Hashtable();
48             table.put( "bla2", new ComponentContextEntry( new Integer( 2 ) ) );
49             table.put( "bla3", new Integer( 3 ) );
50             XComponentContext xContext = new ComponentContext( table, xInitialContext );
51 
52             XMultiComponentFactory xSMgr = xContext.getServiceManager();
53             Object o = xSMgr.createInstanceWithContext( "com.sun.star.loader.Java", xContext );
54             if (o == null)
55                 System.err.println( "### failed raising service: 1!" );
56             o = xSMgr.createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", xContext );
57             if (o == null)
58                 System.err.println( "### failed raising service: 2!" );
59             o = xSMgr.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", xContext );
60             if (o == null)
61                 System.err.println( "### failed raising service: 3!" );
62             o = xSMgr.createInstanceWithContext( "com.sun.star.connection.Connector", xContext );
63             if (o == null)
64                 System.err.println( "### failed raising service: 4!" );
65             o = xSMgr.createInstanceWithContext( "com.sun.star.connection.Acceptor", xContext );
66             if (o == null)
67                 System.err.println( "### failed raising service: 5!" );
68             o = xSMgr.createInstanceWithContext( "com.sun.star.lang.ServiceManager", xContext );
69             if (o == null)
70                 System.err.println( "### failed raising service: 6!" );
71 
72             if (xContext.getValueByName( "bla1" ) == null ||
73                 xContext.getValueByName( "bla2" ) == null ||
74                 xContext.getValueByName( "bla3" ) == null ||
75                 xInitialContext.getValueByName( "bla2" ) != null ||
76                 xInitialContext.getValueByName( "bla3" ) != null)
77             {
78                 System.err.println( "### bootstrap context test failed: 1!" );
79             }
80             if (((Integer)xContext.getValueByName( "bla1" )).intValue() != 1 ||
81                 ((Integer)xContext.getValueByName( "bla2" )).intValue() != 2 ||
82                 ((Integer)xContext.getValueByName( "bla3" )).intValue() != 3 ||
83                 ((Integer)xInitialContext.getValueByName( "bla1" )).intValue() != 1)
84             {
85                 System.err.println( "### bootstrap context test failed: 2!" );
86             }
87 
88             XComponent xComp = UnoRuntime.queryInterface(
89                 XComponent.class, xInitialContext );
90             xComp.dispose();
91 		}
92 		catch(Exception exception) {
93 			System.err.println("exception occurred:" + exception);
94 			exception.printStackTrace();
95 		}
96 	}
97 }
98 
99 
100