1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
29 using System
.Collections
;
32 using unoidl
.com
.sun
.star
.uno
;
33 using unoidl
.com
.sun
.star
.lang
;
34 using unoidl
.com
.sun
.star
.container
;
37 //==============================================================================
38 internal class Factory
:
39 WeakComponentBase
, XSingleComponentFactory
, XServiceInfo
41 private String m_service
;
43 private System
.Reflection
.ConstructorInfo m_ctor
;
45 public Factory( Type type
, String service
)
49 m_ctor
= type
.GetConstructor(
50 new Type
[] { typeof (XComponentContext) }
);
53 public Object
createInstanceWithContext( XComponentContext xContext
)
55 return m_ctor
.Invoke( new Object
[] { xContext }
);
58 public Object
createInstanceWithArgumentsAndContext(
59 uno
.Any
[] args
, XComponentContext xContext
)
61 return m_ctor
.Invoke( new Object
[] { xContext }
);
64 public bool supportsService( String name
)
66 return m_service
.Equals( name
);
69 public String
[] getSupportedServiceNames()
71 return new String
[] { m_service }
;
74 public String
getImplementationName()
76 return m_type
.ToString();
81 /** This executable does the same as the batch file starting via uno.exe,
82 but via bootstrapping native UNO.
84 public class BridgeTest
86 public static int Main( String
[] args
)
88 // System.Diagnostics.Debugger.Launch();
91 string bootstrap_ini
= "cli_bridgetest_inprocess.ini";
97 "\n\ncli_bridgetest_inprocess [bootstrap file] \n\n"
99 + "\t contains the entries UNO_TYPES and UNO_SERVICES.\n"
100 + "\t If a file is not provided than it is assumed that a\n"
101 + "\t cli_bridgetest_inprocess.ini file can be found in the\n "
102 + "\t current working directory.\n"
108 bootstrap_ini
= args
[0];
112 // bootstrap native UNO
113 XComponentContext xContext
=
114 Bootstrap
.defaultBootstrap_InitialComponentContext(
115 bootstrap_ini
, null );
117 using (new uno
.util
.DisposeGuard( (XComponent
) xContext
))
119 XSet xSet
= (XSet
) xContext
.getServiceManager();
122 typeof (XSingleComponentFactory
),
124 typeof (cs_testobj
.BridgeTestObject
),
125 "com.sun.star.test.bridge.cli_uno.CsTestObject" ) ) );
128 typeof (XSingleComponentFactory
),
130 typeof (vb_testobj
.VBBridgeTestObject
),
131 "com.sun.star.test.bridge.cli_uno.VbTestObject" ) ) );
134 typeof (XSingleComponentFactory
),
136 typeof (cpp_bridgetest
.BridgeTest
),
137 "com.sun.star.test.bridge.cli_uno.CppBridgeTest" ) ) );
140 typeof (XSingleComponentFactory
),
142 typeof (cs_testobj
.BridgeTest
),
143 "com.sun.star.test.bridge.cli_uno.CsBridgeTest" ) ) );
146 typeof (XSingleComponentFactory
),
148 typeof (vb_bridetest
.BridgeTest
),
149 "com.sun.star.test.bridge.cli_uno.VbBridgeTest" ) ) );
152 // direct unbridged test
153 // get client object via singleton entry
156 test_client
= new cs_testobj
.BridgeTest( xContext
);
157 xClient
= (XMain
) test_client
;
159 "\n[cli bridgetest] 1. C# client calls C# object");
160 // run with CLI target object
163 "com.sun.star.test.bridge.cli_uno.CsTestObject" } );
166 // uno -ro uno_services.rdb -ro uno_types.rdb
167 // -s com.sun.star.test.bridge.BridgeTest
168 // -- com.sun.star.test.bridge.cli_uno.TestObject
172 xContext
.getServiceManager().createInstanceWithContext(
173 "com.sun.star.test.bridge.BridgeTest", xContext
);
174 xClient
= (XMain
) test_client
;
176 "\n[cli bridgetest] 2. C++ client (native) calls C# object");
177 // run with CLI target object
180 "com.sun.star.test.bridge.cli_uno.CsTestObject",
181 "noCurrentContext"} );
184 // uno -ro uno_services.rdb -ro uno_types.rdb
185 // -s com.sun.star.test.bridge.cli_uno.BridgeTest
186 // -- com.sun.star.test.bridge.CppTestObject
190 xContext
.getServiceManager().createInstanceWithContext(
191 "com.sun.star.test.bridge.cli_uno.CsBridgeTest",
193 xClient
= (XMain
) test_client
;
195 "\n[cli bridgetest] 3. C# client calls C++ object (native)");
196 // run with native target object
198 new String
[] { "com.sun.star.test.bridge.CppTestObject" }
);
201 // uno -ro uno_services.rdb -ro uno_types.rdb
202 // -s com.sun.star.test.bridge.cli_uno.VbBridgeTest
203 // -- com.sun.star.test.bridge.CppTestObject
206 xContext
.getServiceManager().createInstanceWithContext(
207 "com.sun.star.test.bridge.cli_uno.VbBridgeTest",
209 xClient
= (XMain
) test_client
;
211 "\n[cli bridgetest] 4. Visual Basic client calls C++ (native) object" );
212 // run with native target object
214 new String
[] { "com.sun.star.test.bridge.CppTestObject" }
);
217 // uno -ro uno_services.rdb -ro uno_types.rdb
218 // -s com.sun.star.test.bridge.BridgeTest
219 // -- com.sun.star.test.bridge.cli_uno.VbTestObject
222 // xContext.getServiceManager().createInstanceWithContext(
223 // "com.sun.star.test.bridge.BridgeTest", xContext );
224 // xClient = (XMain) test_client;
225 // Console.WriteLine(
226 // "[cli bridgetest] Visual Basic client: {0}",
227 // xClient.ToString() );
228 // // run with native target object
231 // "com.sun.star.test.bridge.cli_uno.VbTestObject" } );
234 // uno -ro uno_services.rdb -ro uno_types.rdb
235 // -s com.sun.star.test.bridge.cli_uno.CppBridgeTest
236 // -- com.sun.star.test.bridge.CppTestObject
238 xContext
.getServiceManager().createInstanceWithContext(
239 "com.sun.star.test.bridge.cli_uno.CppBridgeTest",
241 xClient
= (XMain
) test_client
;
243 "\n[cli bridgetest] 6. CLI C++ client calls C++ object (native)");
244 // run with native target object
246 new String
[] { "com.sun.star.test.bridge.CppTestObject" }
);
249 catch (System
.Exception exc
)
251 GC
.WaitForPendingFinalizers();
252 System
.Console
.WriteLine( exc
);
256 GC
.WaitForPendingFinalizers();
257 System
.Console
.WriteLine( "====> all tests ok." );