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.wizards.web;
28 
29 import com.sun.star.beans.XPropertyAccess;
30 import com.sun.star.comp.loader.FactoryHelper;
31 import com.sun.star.lang.XInitialization;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.lang.XServiceInfo;
34 import com.sun.star.lang.XSingleServiceFactory;
35 import com.sun.star.lang.XTypeProvider;
36 import com.sun.star.registry.XRegistryKey;
37 import com.sun.star.task.XJob;
38 import com.sun.star.task.XJobExecutor;
39 import com.sun.star.uno.Type;
40 import com.sun.star.wizards.common.Desktop;
41 import com.sun.star.wizards.common.PropertyNames;
42 import com.sun.star.wizards.common.Resource;
43 
44 /**
45  * This class capsulates the class, that implements the minimal component, a factory for
46  * creating the service (<CODE>__getServiceFactory</CODE>).
47  *
48  * @author rpiterman
49  * @version $Revision: 1.10.52.1 $
50  */
51 public class CallWizard
52 {
53 
54     /**
55      * Gives a factory for creating the service. This method is called by the
56      * <code>JavaLoader</code>
57      *
58      * <p></p>
59      *
60      * @param stringImplementationName The implementation name of the component.
61      * @param xMSF The service manager, who gives access to every known service.
62      * @param xregistrykey Makes structural information (except regarding tree
63      *        structures) of a single registry key accessible.
64      *
65      * @return Returns a <code>XSingleServiceFactory</code> for creating the component.
66      *
67      * @see com.sun.star.comp.loader.JavaLoader#
68      */
69     public static XSingleServiceFactory __getServiceFactory(String stringImplementationName, XMultiServiceFactory xMSF, XRegistryKey xregistrykey)
70     {
71         XSingleServiceFactory xsingleservicefactory = null;
72 
73         if (stringImplementationName.equals(WizardImplementation.class.getName()))
74         {
75             xsingleservicefactory = FactoryHelper.getServiceFactory(WizardImplementation.class, WizardImplementation.__serviceName, xMSF, xregistrykey);
76         }
77 
78         return xsingleservicefactory;
79     }
80 
81     /**
82      * This class implements the component. At least the interfaces XServiceInfo,
83      * XTypeProvider, and XInitialization should be provided by the service.
84      */
85     public static class WizardImplementation implements XInitialization, XTypeProvider, XServiceInfo, XJobExecutor
86     {
87 
88         /**
89          * The constructor of the inner class has a XMultiServiceFactory parameter.
90          *
91          * @param xmultiservicefactoryInitialization A special service factory could be
92          *        introduced while initializing.
93          */
94         public WizardImplementation(XMultiServiceFactory xmultiservicefactoryInitialization)
95         {
96             xmultiservicefactory = xmultiservicefactoryInitialization;
97 
98             if (xmultiservicefactory != null)
99             {
100             }
101         }
102         private static WebWizard webWizard = null;
103 
104         /**
105          * Execute Wizard
106          *
107          * @param str only valid parameter is 'start' at the moment.
108          */
109         public void trigger(String str)
110         {
111             if (str.equalsIgnoreCase(PropertyNames.START))
112             {
113                 if (webWizard == null)
114                 {
115                     WebWizard ww = null;
116                     try
117                     {
118                         webWizard = new WebWizard(xmultiservicefactory);
119                         ww = webWizard;
120                         webWizard.show();
121                         webWizard = null;
122                     }
123                     catch (Exception ex)
124                     {
125                         webWizard = null;
126                         ex.printStackTrace();
127                         Resource.showCommonResourceError(xmultiservicefactory);
128                     }
129                     finally
130                     {
131                         webWizard = null;
132                         try
133                         {
134                             if (ww != null)
135                             {
136                                 ww.cleanup();
137                             }
138                         }
139                         catch (Exception ex)
140                         {
141                             ex.printStackTrace();
142                         }
143 
144                     }
145                 }
146                 else
147                 {
148                     webWizard.activate();
149                 }
150 
151 
152             }
153         }        //*******************************************
154         /**
155          * The service name, that must be used to get an instance of this service.
156          */
157         private static final String __serviceName = "com.sun.star.wizards.web.CallWizard";
158         /**
159          * The service manager, that gives access to all registered services.
160          */
161         private XMultiServiceFactory xmultiservicefactory;
162 
163         /**
164          * This method is a member of the interface for initializing an object directly
165          * after its creation.
166          *
167          * @param object This array of arbitrary objects will be passed to the component
168          *        after its creation.
169          *
170          * @throws com.sun.star.uno.Exception Every exception will not be handled, but
171          *         will be passed to the caller.
172          */
173         public void initialize(Object[] object) throws com.sun.star.uno.Exception
174         {
175             //wizardStarted = false;
176         }
177 
178         /**
179          * This method returns an array of all supported service names.
180          *
181          * @return Array of supported service names.
182          */
183         public java.lang.String[] getSupportedServiceNames()
184         {
185             String[] stringSupportedServiceNames = new String[1];
186             stringSupportedServiceNames[0] = __serviceName;
187 
188             return (stringSupportedServiceNames);
189         }
190 
191         /**
192          * This method returns true, if the given service will be supported by the
193          * component.
194          *
195          * @param stringService Service name.
196          *
197          * @return True, if the given service name will be supported.
198          */
199         public boolean supportsService(String stringService)
200         {
201             boolean booleanSupportsService = false;
202 
203             if (stringService.equals(__serviceName))
204             {
205                 booleanSupportsService = true;
206             }
207 
208             return (booleanSupportsService);
209         }
210 
211         /**
212          * This method returns an array of bytes, that can be used to unambiguously
213          * distinguish between two sets of types, e.g. to realise hashing functionality
214          * when the object is introspected. Two objects that return the same ID also
215          * have to return the same set of types in getTypes(). If an unique
216          * implementation Id cannot be provided this method has to return an empty
217          * sequence. Important: If the object aggregates other objects the ID has to be
218          * unique for the whole combination of objects.
219          *
220          * @return Array of bytes, in order to distinguish between two sets.
221          */
222         public byte[] getImplementationId()
223         {
224             byte[] byteReturn =
225             {
226             };
227 
228             try
229             {
230                 byteReturn = (PropertyNames.EMPTY_STRING + this.hashCode()).getBytes();
231             }
232             catch (Exception exception)
233             {
234                 System.err.println(exception);
235             }
236 
237             return (byteReturn);
238         }
239 
240         /**
241          * Return the class name of the component.
242          *
243          * @return Class name of the component.
244          */
245         public java.lang.String getImplementationName()
246         {
247             return (WizardImplementation.class.getName());
248         }
249 
250         /**
251          * Provides a sequence of all types (usually interface types) provided by the
252          * object.
253          *
254          * @return Sequence of all types (usually interface types) provided by the
255          *         service.
256          */
257         public com.sun.star.uno.Type[] getTypes()
258         {
259             Type[] typeReturn =
260             {
261             };
262 
263             try
264             {
265                 typeReturn = new Type[]
266                         {
267                             new Type(XPropertyAccess.class), new Type(XJob.class), new Type(XJobExecutor.class), new Type(XTypeProvider.class), new Type(XServiceInfo.class), new Type(XInitialization.class)
268                         };
269             }
270             catch (Exception exception)
271             {
272                 System.err.println(exception);
273             }
274 
275             return (typeReturn);
276         }
277     }
278 
279     public static void main(String[] s)
280     {
281 
282         String ConnectStr =
283                 "uno:socket,host=localhost,port=8100;urp,negotiate=0,forcesynchronous=1;StarOffice.ServiceManager";
284         try
285         {
286             XMultiServiceFactory xmsf = Desktop.connect(ConnectStr);
287             CallWizard.WizardImplementation ww = new CallWizard.WizardImplementation(xmsf);
288             ww.trigger(PropertyNames.START);
289 
290         }
291         catch (Exception exception)
292         {
293             exception.printStackTrace(System.out);
294         }
295     }
296 }
297