134dd1e25SAndrew Rist /**************************************************************
234dd1e25SAndrew Rist  *
334dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
434dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
534dd1e25SAndrew Rist  * distributed with this work for additional information
634dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
734dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
834dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
934dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
1034dd1e25SAndrew Rist  *
1134dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1234dd1e25SAndrew Rist  *
1334dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1434dd1e25SAndrew Rist  * software distributed under the License is distributed on an
1534dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1634dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
1734dd1e25SAndrew Rist  * specific language governing permissions and limitations
1834dd1e25SAndrew Rist  * under the License.
1934dd1e25SAndrew Rist  *
2034dd1e25SAndrew Rist  *************************************************************/
2134dd1e25SAndrew Rist 
2234dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir //_______________________________________________
25cdf0e10cSrcweir // imports
26cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
27cdf0e10cSrcweir import com.sun.star.lib.uno.helper.Factory;
28cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
29cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
30cdf0e10cSrcweir import com.sun.star.awt.*;
31cdf0e10cSrcweir import com.sun.star.beans.*;
32cdf0e10cSrcweir import com.sun.star.task.*;
33cdf0e10cSrcweir import com.sun.star.uno.*;
34cdf0e10cSrcweir import java.lang.*;
35cdf0e10cSrcweir import javax.swing.*;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //_______________________________________________
38cdf0e10cSrcweir // implementation
39cdf0e10cSrcweir 
40cdf0e10cSrcweir /** it implements a simple job component.
41cdf0e10cSrcweir  *
42cdf0e10cSrcweir  *  Such jobs are executable in different ways:
43cdf0e10cSrcweir  *  <ul>
44cdf0e10cSrcweir  *      <li>registered for a special URL schema "vnd.sun.star.jobs:*" and used from the generic dispatch framework</li>
45cdf0e10cSrcweir  *      <li>the global com.sun.star.task.JobExecutor service and registered for special events.</li>
46cdf0e10cSrcweir  *  </ul>
47cdf0e10cSrcweir  */
48cdf0e10cSrcweir public class AsyncJob extends    WeakBase implements XServiceInfo, XAsyncJob
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     //___________________________________________
51cdf0e10cSrcweir     // const
52cdf0e10cSrcweir     public final XComponentContext m_xCmpCtx;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     /** the const list of supported uno service names. */
55cdf0e10cSrcweir     public static final java.lang.String[] SERVICENAMES = {"com.sun.star.task.AsyncJob"};
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     /** the const uno implementation name.
58cdf0e10cSrcweir      *  It must be an unique value! The best naming schema seams to use
59cdf0e10cSrcweir      *  a registered domain in reverse order ...
60cdf0e10cSrcweir      */
61cdf0e10cSrcweir     public static final java.lang.String IMPLEMENTATIONNAME = "com.sun.star.comp.framework.java.services.AsyncJob";
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     //___________________________________________
64cdf0e10cSrcweir     // interface
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     /** initialize a new instance of this class with default values. */
67cdf0e10cSrcweir     public AsyncJob( XComponentContext xCompContext )
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir         m_xCmpCtx = xCompContext;
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     //___________________________________________
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     /** starts execution of this job.
75cdf0e10cSrcweir      *
76cdf0e10cSrcweir      *  @param  lArgs
77cdf0e10cSrcweir      *          list which contains:
78cdf0e10cSrcweir      *          <ul>
79cdf0e10cSrcweir      *              <li>generic job configuration data</li>
80cdf0e10cSrcweir      *              <li>job specific configuration data</li>
81cdf0e10cSrcweir      *              <li>some environment informations</li>
82cdf0e10cSrcweir      *              <li>may optional arguments of a corresponding dispatch request</li>
83cdf0e10cSrcweir      *          </ul>
84cdf0e10cSrcweir      *
85cdf0e10cSrcweir      *  @params xListener
86cdf0e10cSrcweir      *          callback to the executor of this job, which control our life time
87cdf0e10cSrcweir      *
88cdf0e10cSrcweir      *  @throws com.sun.star.lang.IllegalArgumentException
89cdf0e10cSrcweir      *          if given argument list seams to be wrong
90cdf0e10cSrcweir      */
91cdf0e10cSrcweir     public synchronized void executeAsync(com.sun.star.beans.NamedValue[] lArgs    ,
92cdf0e10cSrcweir                                           com.sun.star.task.XJobListener  xListener)
93cdf0e10cSrcweir         throws com.sun.star.lang.IllegalArgumentException
94cdf0e10cSrcweir     {
95*e9faf1d9Smseidel         // For asynchronous jobs a valid listener reference is guaranteed normally ...
96cdf0e10cSrcweir         if (xListener == null)
97cdf0e10cSrcweir             throw new com.sun.star.lang.IllegalArgumentException("invalid listener");
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         // extract all possible sub list of given argument list
100cdf0e10cSrcweir         com.sun.star.beans.NamedValue[] lGenericConfig = null;
101cdf0e10cSrcweir         com.sun.star.beans.NamedValue[] lJobConfig     = null;
102cdf0e10cSrcweir         com.sun.star.beans.NamedValue[] lEnvironment   = null;
103cdf0e10cSrcweir         com.sun.star.beans.NamedValue[] lDynamicData   = null;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         int c = lArgs.length;
106cdf0e10cSrcweir         for (int i=0; i<c; ++i)
107cdf0e10cSrcweir         {
108cdf0e10cSrcweir             if (lArgs[i].Name.equals("Config"))
109cdf0e10cSrcweir                 lGenericConfig = (com.sun.star.beans.NamedValue[])com.sun.star.uno.AnyConverter.toArray(lArgs[i].Value);
110cdf0e10cSrcweir             else
111cdf0e10cSrcweir             if (lArgs[i].Name.equals("JobConfig"))
112cdf0e10cSrcweir                 lJobConfig = (com.sun.star.beans.NamedValue[])com.sun.star.uno.AnyConverter.toArray(lArgs[i].Value);
113cdf0e10cSrcweir             else
114cdf0e10cSrcweir             if (lArgs[i].Name.equals("Environment"))
115cdf0e10cSrcweir                 lEnvironment = (com.sun.star.beans.NamedValue[])com.sun.star.uno.AnyConverter.toArray(lArgs[i].Value);
116cdf0e10cSrcweir             else
117cdf0e10cSrcweir             if (lArgs[i].Name.equals("DynamicData"))
118cdf0e10cSrcweir                 lDynamicData = (com.sun.star.beans.NamedValue[])com.sun.star.uno.AnyConverter.toArray(lArgs[i].Value);
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir 
121a893be29SPedro Giffuni         // Analyze the environment info. This sub list is the only guaranteed one!
122cdf0e10cSrcweir         if (lEnvironment == null)
123cdf0e10cSrcweir             throw new com.sun.star.lang.IllegalArgumentException("no environment");
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         java.lang.String          sEnvType   = null;
126cdf0e10cSrcweir         java.lang.String          sEventName = null;
127cdf0e10cSrcweir         com.sun.star.frame.XFrame xFrame     = null;
128cdf0e10cSrcweir         c = lEnvironment.length;
129cdf0e10cSrcweir         for (int i=0; i<c; ++i)
130cdf0e10cSrcweir         {
131cdf0e10cSrcweir             if (lEnvironment[i].Name.equals("EnvType"))
132cdf0e10cSrcweir                 sEnvType = com.sun.star.uno.AnyConverter.toString(lEnvironment[i].Value);
133cdf0e10cSrcweir             else
134cdf0e10cSrcweir             if (lEnvironment[i].Name.equals("EventName"))
135cdf0e10cSrcweir                 sEventName = com.sun.star.uno.AnyConverter.toString(lEnvironment[i].Value);
136cdf0e10cSrcweir             else
137cdf0e10cSrcweir             if (lEnvironment[i].Name.equals("Frame"))
138cdf0e10cSrcweir                 xFrame = (com.sun.star.frame.XFrame)com.sun.star.uno.AnyConverter.toObject(
139cdf0e10cSrcweir                             new com.sun.star.uno.Type(com.sun.star.frame.XFrame.class),
140cdf0e10cSrcweir                             lEnvironment[i].Value);
141cdf0e10cSrcweir         }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         // Further the environment property "EnvType" is required as minimum.
144cdf0e10cSrcweir         if (
145cdf0e10cSrcweir             (sEnvType==null) ||
146cdf0e10cSrcweir             (
147cdf0e10cSrcweir              (!sEnvType.equals("EXECUTOR")) &&
148cdf0e10cSrcweir              (!sEnvType.equals("DISPATCH"))
149cdf0e10cSrcweir             )
150cdf0e10cSrcweir            )
151cdf0e10cSrcweir         {
152cdf0e10cSrcweir             java.lang.String sMessage = "\"" + sEnvType + "\" isn't a valid value for EnvType";
153cdf0e10cSrcweir             throw new com.sun.star.lang.IllegalArgumentException(sMessage);
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         // Analyze the set of shared config data.
157cdf0e10cSrcweir         java.lang.String sAlias = null;
158cdf0e10cSrcweir         if (lGenericConfig!=null)
159cdf0e10cSrcweir         {
160cdf0e10cSrcweir             c = lGenericConfig.length;
161cdf0e10cSrcweir             for (int i=0; i<c; ++i)
162cdf0e10cSrcweir             {
163cdf0e10cSrcweir                 if (lGenericConfig[i].Name.equals("Alias"))
164cdf0e10cSrcweir                     sAlias = com.sun.star.uno.AnyConverter.toString(lGenericConfig[i].Value);
165cdf0e10cSrcweir             }
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         // do your job ...
169cdf0e10cSrcweir         // Here we print out all found arguments.
170cdf0e10cSrcweir         java.lang.String sOut = formatOutArgs(lGenericConfig, lJobConfig, lEnvironment, lDynamicData);
171cdf0e10cSrcweir         if (xFrame != null)
172cdf0e10cSrcweir             showInfoModal(xFrame.getContainerWindow(), "Arguments of AsyncJob initialization ...", sOut);
173cdf0e10cSrcweir         else
174cdf0e10cSrcweir             showInfoNonModal("Arguments of AsyncJob initialization ...", sOut);
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         // use return value to start different actions
177cdf0e10cSrcweir         // But look for the right environment. Some options make no sense inside the wrong env.
178cdf0e10cSrcweir         com.sun.star.beans.NamedValue aDeactivation   = null;
179cdf0e10cSrcweir         com.sun.star.beans.NamedValue aDispatchResult = null;
180cdf0e10cSrcweir         com.sun.star.beans.NamedValue aSaveRequest    = null;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         // SaveArguments will be made everytimes!
183cdf0e10cSrcweir         c = 1;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         if (lJobConfig==null)
186cdf0e10cSrcweir             lJobConfig = new com.sun.star.beans.NamedValue[1];
187cdf0e10cSrcweir         lJobConfig[0] = new com.sun.star.beans.NamedValue();
188cdf0e10cSrcweir         lJobConfig[0].Name  = "arg_1";
189cdf0e10cSrcweir         lJobConfig[0].Value = "val_1";
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         aSaveRequest = new com.sun.star.beans.NamedValue();
192cdf0e10cSrcweir         aSaveRequest.Name  = "SaveArguments";
193cdf0e10cSrcweir         aSaveRequest.Value = lJobConfig;
194cdf0e10cSrcweir 
195a893be29SPedro Giffuni         // Deactivation is useful inside EXECUTOR environment only
196cdf0e10cSrcweir         if (sEnvType.equals("EXECUTOR"))
197cdf0e10cSrcweir         {
198cdf0e10cSrcweir             ++c;
199cdf0e10cSrcweir             aDeactivation       = new com.sun.star.beans.NamedValue();
200cdf0e10cSrcweir             aDeactivation.Name  = "Deactivate";
201cdf0e10cSrcweir             aDeactivation.Value = java.lang.Boolean.TRUE;
202cdf0e10cSrcweir         }
203cdf0e10cSrcweir 
204a893be29SPedro Giffuni         // Sending of result events is useful inside DISPATCH environment only
205cdf0e10cSrcweir         if (sEnvType.equals("DISPATCH"))
206cdf0e10cSrcweir         {
207cdf0e10cSrcweir             ++c;
208cdf0e10cSrcweir             aDispatchResult       = new com.sun.star.beans.NamedValue();
209cdf0e10cSrcweir             aDispatchResult.Name  = "SendDispatchResult";
210cdf0e10cSrcweir             aDispatchResult.Value = new com.sun.star.frame.DispatchResultEvent(this, com.sun.star.frame.DispatchResultState.SUCCESS, null);
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         // pack it together for return
214cdf0e10cSrcweir         int i=0;
215cdf0e10cSrcweir         com.sun.star.beans.NamedValue[] lReturn = new com.sun.star.beans.NamedValue[c];
216cdf0e10cSrcweir         lReturn[i++] = aSaveRequest;
217cdf0e10cSrcweir         if (aDeactivation!=null)
218cdf0e10cSrcweir             lReturn[i++] = aDeactivation;
219cdf0e10cSrcweir         if (aDispatchResult!=null)
220cdf0e10cSrcweir             lReturn[i++] = aDispatchResult;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         xListener.jobFinished(this, lReturn);
223cdf0e10cSrcweir     }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     //___________________________________________
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     /** show an info box with the UNO based toolkit.
228cdf0e10cSrcweir      *
229cdf0e10cSrcweir      *  It tries to use the container window of a may well know
230cdf0e10cSrcweir      *  office frame as parent. If such parent window could be located,
231cdf0e10cSrcweir      *  the info box can be shown in modal mode. If a parent is missing
232cdf0e10cSrcweir      *  (because this job is called inside an EXECUTOR environment, which
233cdf0e10cSrcweir      *  does not set any frame context here) the info box can't be created!
234cdf0e10cSrcweir      *  Because the toolkit needs parents for non top level windows ...
235cdf0e10cSrcweir      *  In that case the only way is to implement this info box
236cdf0e10cSrcweir      *  native or make it non modal using java dialogs inside it's own thread ...
237cdf0e10cSrcweir      *  (see showInfoNonModal() too)
238cdf0e10cSrcweir      *
239cdf0e10cSrcweir      *  @param  xParent
240cdf0e10cSrcweir      *          used as parent window of the shown info box.
241cdf0e10cSrcweir      *
242cdf0e10cSrcweir      *  @param  sTitle
243cdf0e10cSrcweir      *          is shown as title of the info box.
244cdf0e10cSrcweir      *
245cdf0e10cSrcweir      *  @param  sMessage
246cdf0e10cSrcweir      *          inclused the message body, which is shown as info.
247cdf0e10cSrcweir      */
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     private void showInfoModal( com.sun.star.awt.XWindow xParent  ,
250cdf0e10cSrcweir                                 java.lang.String         sTitle   ,
251cdf0e10cSrcweir                                 java.lang.String         sMessage )
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         try
254cdf0e10cSrcweir         {
255cdf0e10cSrcweir             // get access to the office toolkit environment
256cdf0e10cSrcweir             com.sun.star.awt.XToolkit xKit = (com.sun.star.awt.XToolkit)UnoRuntime.queryInterface(
257cdf0e10cSrcweir                  com.sun.star.awt.XToolkit.class,
258cdf0e10cSrcweir                  m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit",
259cdf0e10cSrcweir                                                                          m_xCmpCtx));
260cdf0e10cSrcweir 
261cdf0e10cSrcweir             // describe the info box ini it's parameters
262cdf0e10cSrcweir             com.sun.star.awt.WindowDescriptor aDescriptor = new com.sun.star.awt.WindowDescriptor();
263cdf0e10cSrcweir             aDescriptor.WindowServiceName = "infobox";
264cdf0e10cSrcweir             aDescriptor.Bounds            = new com.sun.star.awt.Rectangle(0,0,300,200);
265cdf0e10cSrcweir             aDescriptor.WindowAttributes  = com.sun.star.awt.WindowAttribute.BORDER   |
266cdf0e10cSrcweir                                             com.sun.star.awt.WindowAttribute.MOVEABLE |
267cdf0e10cSrcweir                                             com.sun.star.awt.WindowAttribute.CLOSEABLE;
268cdf0e10cSrcweir             aDescriptor.Type              = com.sun.star.awt.WindowClass.MODALTOP;
269cdf0e10cSrcweir             aDescriptor.ParentIndex       = 1;
270cdf0e10cSrcweir             aDescriptor.Parent            = (com.sun.star.awt.XWindowPeer)UnoRuntime.queryInterface(
271cdf0e10cSrcweir                                                 com.sun.star.awt.XWindowPeer.class,
272cdf0e10cSrcweir                                                 xParent);
273cdf0e10cSrcweir 
274cdf0e10cSrcweir             // create the info box window
275cdf0e10cSrcweir             com.sun.star.awt.XWindowPeer xPeer    = xKit.createWindow(aDescriptor);
276cdf0e10cSrcweir             com.sun.star.awt.XMessageBox xInfoBox = (com.sun.star.awt.XMessageBox)UnoRuntime.queryInterface(
277cdf0e10cSrcweir                                                         com.sun.star.awt.XMessageBox.class,
278cdf0e10cSrcweir                                                         xPeer);
279cdf0e10cSrcweir             if (xInfoBox == null)
280cdf0e10cSrcweir                 return;
281cdf0e10cSrcweir 
282cdf0e10cSrcweir             // fill it with all given informations and show it
283cdf0e10cSrcweir             xInfoBox.setCaptionText(sTitle);
284cdf0e10cSrcweir             xInfoBox.setMessageText(sMessage);
285cdf0e10cSrcweir             xInfoBox.execute();
286cdf0e10cSrcweir         }
287cdf0e10cSrcweir         catch(java.lang.Throwable exIgnore)
288cdf0e10cSrcweir         {
289a893be29SPedro Giffuni             // ignore any problem, which can occur here.
290a893be29SPedro Giffuni             // It's not really a bug for this example job, if
291cdf0e10cSrcweir             // it's message could not be printed out!
292cdf0e10cSrcweir         }
293cdf0e10cSrcweir     }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     //___________________________________________
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     private void showInfoNonModal( java.lang.String sTitle   ,
298cdf0e10cSrcweir                                    java.lang.String sMessage )
299cdf0e10cSrcweir     {
300a893be29SPedro Giffuni         // Couldnt be implemented really using the toolkit ...
301cdf0e10cSrcweir         // Because we need a parent anytime.
302cdf0e10cSrcweir         // And showing e.g. a java dialog can make some trouble
303cdf0e10cSrcweir         // inside office ... but we have no chance here.
304cdf0e10cSrcweir 	final java.lang.String sFinalTitle = sTitle;
305cdf0e10cSrcweir 	final java.lang.String sFinalMessage = sMessage;
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 	// On Mac OS X, AWT/Swing must not be accessed from the AppKit thread, so call
308cdf0e10cSrcweir 	// SwingUtilities.invokeLater always on a fresh thread to avoid that problem
309cdf0e10cSrcweir 	// (also, the current thread must not wait for that fresh thread to terminate,
310cdf0e10cSrcweir 	// as that would cause a deadlock if this thread is the AppKit thread):
311cdf0e10cSrcweir 	final Runnable doRun = new Runnable() {
312cdf0e10cSrcweir 		public void run() {
313cdf0e10cSrcweir 		    javax.swing.JOptionPane.showMessageDialog(null, sFinalMessage, sFinalTitle, javax.swing.JOptionPane.INFORMATION_MESSAGE);
314cdf0e10cSrcweir 		}
315cdf0e10cSrcweir 	    };
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 	 new Thread( doRun ) {
318cdf0e10cSrcweir 	     public void run() { javax.swing.SwingUtilities.invokeLater(doRun); }
319cdf0e10cSrcweir 	 }.start();
320cdf0e10cSrcweir     }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     //___________________________________________
323cdf0e10cSrcweir 
324cdf0e10cSrcweir     /** helper to print out the given argument list.
325cdf0e10cSrcweir      *
326cdf0e10cSrcweir      *  @param  lGenericConfig
327cdf0e10cSrcweir      *          contains all shared configuration items for a job
328cdf0e10cSrcweir      *
329cdf0e10cSrcweir      *  @param  lJobConfig
330cdf0e10cSrcweir      *          contains all job sepcific configuration items
331cdf0e10cSrcweir      *
332cdf0e10cSrcweir      *  @param  lEnvironment
333cdf0e10cSrcweir      *          contains some environment informations
334cdf0e10cSrcweir      *
335cdf0e10cSrcweir      *  @param  lDynamicData
336cdf0e10cSrcweir      *          contains optional data of a might corresponding dispatch() request
337cdf0e10cSrcweir      */
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     private java.lang.String formatOutArgs(com.sun.star.beans.NamedValue[] lGenericConfig,
340cdf0e10cSrcweir                                            com.sun.star.beans.NamedValue[] lJobConfig    ,
341cdf0e10cSrcweir                                            com.sun.star.beans.NamedValue[] lEnvironment  ,
342cdf0e10cSrcweir                                            com.sun.star.beans.NamedValue[] lDynamicData )
343cdf0e10cSrcweir     {
344cdf0e10cSrcweir         java.lang.StringBuffer sOut = new java.lang.StringBuffer(1024);
345cdf0e10cSrcweir 
346cdf0e10cSrcweir         sOut.append("list \"Config\": ");
347cdf0e10cSrcweir         if (lGenericConfig==null)
348cdf0e10cSrcweir             sOut.append("0 items\n");
349cdf0e10cSrcweir         else
350cdf0e10cSrcweir         {
351cdf0e10cSrcweir             int c = lGenericConfig.length;
352cdf0e10cSrcweir             sOut.append(c+" items\n");
353cdf0e10cSrcweir             for (int i=0; i<c; ++i)
354cdf0e10cSrcweir                 sOut.append("\t["+i+"] \""+lGenericConfig[i].Name+"\" = {"+lGenericConfig[i].Value+"}\n");
355cdf0e10cSrcweir         }
356cdf0e10cSrcweir         sOut.append("list \"JobConfig\": ");
357cdf0e10cSrcweir         if (lJobConfig==null)
358cdf0e10cSrcweir             sOut.append("0 items\n");
359cdf0e10cSrcweir         else
360cdf0e10cSrcweir         {
361cdf0e10cSrcweir             int c = lJobConfig.length;
362cdf0e10cSrcweir             sOut.append(c+" items\n");
363cdf0e10cSrcweir             for (int i=0; i<c; ++i)
364cdf0e10cSrcweir                 sOut.append("\t["+i+"] \""+lJobConfig[i].Name+"\" = {"+lJobConfig[i].Value+"}\n");
365cdf0e10cSrcweir         }
366cdf0e10cSrcweir         sOut.append("list \"Environment\": ");
367cdf0e10cSrcweir         if (lEnvironment==null)
368cdf0e10cSrcweir             sOut.append("0 items\n");
369cdf0e10cSrcweir         else
370cdf0e10cSrcweir         {
371cdf0e10cSrcweir             int c = lEnvironment.length;
372cdf0e10cSrcweir             sOut.append(c+" items\n");
373cdf0e10cSrcweir             for (int i=0; i<c; ++i)
374cdf0e10cSrcweir                 sOut.append("\t["+i+"] \""+lEnvironment[i].Name+"\" = {"+lEnvironment[i].Value+"}\n");
375cdf0e10cSrcweir         }
376cdf0e10cSrcweir         sOut.append("list \"DynamicData\": ");
377cdf0e10cSrcweir         if (lDynamicData==null)
378cdf0e10cSrcweir             sOut.append("0 items\n");
379cdf0e10cSrcweir         else
380cdf0e10cSrcweir         {
381cdf0e10cSrcweir             int c = lDynamicData.length;
382cdf0e10cSrcweir             sOut.append(c+" items\n");
383cdf0e10cSrcweir             for (int i=0; i<c; ++i)
384cdf0e10cSrcweir                 sOut.append("\t["+i+"] \""+lDynamicData[i].Name+"\" = {"+lDynamicData[i].Value+"}\n");
385cdf0e10cSrcweir         }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir         return sOut.toString();
388cdf0e10cSrcweir     }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir     public String[] getSupportedServiceNames() {
391cdf0e10cSrcweir         return SERVICENAMES;
392cdf0e10cSrcweir     }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     public boolean supportsService( String sService ) {
395cdf0e10cSrcweir         int len = SERVICENAMES.length;
396cdf0e10cSrcweir 
397cdf0e10cSrcweir         for( int i=0; i < len; i++) {
398cdf0e10cSrcweir             if ( sService.equals( SERVICENAMES[i] ) )
399cdf0e10cSrcweir                 return true;
400cdf0e10cSrcweir         }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir         return false;
403cdf0e10cSrcweir     }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     public String getImplementationName() {
406cdf0e10cSrcweir         return( AsyncJob.class.getName() );
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     //___________________________________________
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     public synchronized static com.sun.star.lang.XSingleComponentFactory __getComponentFactory(java.lang.String sImplName)
413cdf0e10cSrcweir     {
414cdf0e10cSrcweir         com.sun.star.lang.XSingleComponentFactory xFactory = null;
415cdf0e10cSrcweir         if (sImplName.equals(AsyncJob.IMPLEMENTATIONNAME))
416cdf0e10cSrcweir             xFactory = Factory.createComponentFactory(AsyncJob.class, SERVICENAMES);
417cdf0e10cSrcweir 
418cdf0e10cSrcweir         return xFactory;
419cdf0e10cSrcweir     }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     //___________________________________________
422cdf0e10cSrcweir     // This method not longer necessary since OOo 3.4 where the component registration
423cdf0e10cSrcweir     // was changed to passive component registration. For more details see
424cdf0e10cSrcweir     // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
425cdf0e10cSrcweir 
426cdf0e10cSrcweir //     public synchronized static boolean __writeRegistryServiceInfo(com.sun.star.registry.XRegistryKey xRegKey)
427cdf0e10cSrcweir //     {
428cdf0e10cSrcweir //         return Factory.writeRegistryServiceInfo(
429cdf0e10cSrcweir //             AsyncJob.IMPLEMENTATIONNAME,
430cdf0e10cSrcweir //             AsyncJob.SERVICENAMES,
431cdf0e10cSrcweir //             xRegKey);
432cdf0e10cSrcweir //     }
433cdf0e10cSrcweir }
434