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