1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BasicHandlerProvider.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.container
.XSet
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.container
.ElementExistException
;
36 import com
.sun
.star
.lang
.IllegalArgumentException
;
37 import com
.sun
.star
.connection
.ConnectionSetupException
;
38 import lib
.TestParameters
;
39 import share
.LogWriter
;
40 import basicrunner
.basichelper
.Connector
;
41 import basicrunner
.basichelper
.DocumentHandler
;
42 import basicrunner
.basichelper
.ThreadRunner
;
43 import basicrunner
.basichelper
.AttributeList
;
44 import basicrunner
.basichelper
.Filter
;
45 import basicrunner
.basichelper
.DispatchProviderInterceptor
;
48 * This class provides a BasicHandler. All classes for the communication with
49 * and handling of the BASIC tests are instantiated and inserted int the
50 * MultiServiceFactory of StarOffice.
52 public class BasicHandlerProvider
{
54 /** The BassicHandler **/
55 static BasicHandler oHandler
= null;
57 static Connector oConnector
= null;
58 /** The DocumentHandler **/
59 static DocumentHandler oDocumentHandler
= null;
60 /** The Thread Runner **/
61 static ThreadRunner oThreadRunner
= null;
62 /** The AttributeList **/
63 static AttributeList oAttributeList
= null;
65 static Filter oFilter
= null;
66 /** The DispatchProviderInterceptor **/
67 static DispatchProviderInterceptor oCeptor
= null ;
68 /** The MultiServiceFactory from StarOffice **/
69 static XMultiServiceFactory MSF
= null;
70 /** IS this a new connection or an existing one? **/
71 static boolean bIsNewConnection
= true;
75 * @param tParam Test parameters.
76 * @param log A log writer
77 * @return An instance of BasicHandler
79 static public BasicHandler
getHandler(TestParameters tParam
, LogWriter log
) {
81 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF();
83 if (!xMSF
.equals(MSF
)) {
85 oHandler
= new BasicHandler(tParam
);
86 oConnector
= new Connector();
87 oFilter
= new Filter();
88 oDocumentHandler
= new DocumentHandler();
89 oThreadRunner
= new ThreadRunner(xMSF
);
90 oCeptor
= new DispatchProviderInterceptor() ;
91 oAttributeList
= new AttributeList();
92 XSet xMSFSet
= (XSet
)UnoRuntime
.queryInterface(XSet
.class, xMSF
);
95 xMSFSet
.insert(oHandler
);
96 xMSFSet
.insert(oConnector
);
97 xMSFSet
.insert(oFilter
);
98 xMSFSet
.insert(oDocumentHandler
);
99 xMSFSet
.insert(oThreadRunner
);
100 xMSFSet
.insert(oCeptor
);
101 xMSFSet
.insert(oAttributeList
);
102 } catch (ElementExistException e
) {
103 System
.out
.println(e
.toString());
104 } catch (IllegalArgumentException e
) {
105 System
.out
.println(e
.toString());
109 oHandler
.Connect(util
.utils
.getFullURL((String
)tParam
.get("BASICBRIDGE")),
111 } catch (ConnectionSetupException e
) {
112 System
.out
.println("Can't connect to BASIC !");
115 bIsNewConnection
= true;
117 bIsNewConnection
= false;
124 * Is this a new connection?
125 * @return True, if the connection did not exist before.
127 static public boolean isNewConnection() {
128 return bIsNewConnection
;
132 * Dispose the BasicHandler
134 static public void disposeHandler() {
137 if (oHandler
!= null) {
141 XSet xMSFSet
= (XSet
)UnoRuntime
.queryInterface(XSet
.class, MSF
);
142 xMSFSet
.remove(oHandler
);
143 xMSFSet
.remove(oFilter
);
144 xMSFSet
.remove(oConnector
);
145 xMSFSet
.remove(oDocumentHandler
);
146 xMSFSet
.remove(oThreadRunner
);
147 xMSFSet
.remove(oAttributeList
);
149 } catch (Exception e
){
150 System
.out
.println(e
.toString());