1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * The Contents of this file are made available subject to the terms of 4*cdf0e10cSrcweir * the BSD license. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * All rights reserved. 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * Redistribution and use in source and binary forms, with or without 10*cdf0e10cSrcweir * modification, are permitted provided that the following conditions 11*cdf0e10cSrcweir * are met: 12*cdf0e10cSrcweir * 1. Redistributions of source code must retain the above copyright 13*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer. 14*cdf0e10cSrcweir * 2. Redistributions in binary form must reproduce the above copyright 15*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer in the 16*cdf0e10cSrcweir * documentation and/or other materials provided with the distribution. 17*cdf0e10cSrcweir * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18*cdf0e10cSrcweir * contributors may be used to endorse or promote products derived 19*cdf0e10cSrcweir * from this software without specific prior written permission. 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*cdf0e10cSrcweir * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*cdf0e10cSrcweir * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*cdf0e10cSrcweir * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*cdf0e10cSrcweir * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*cdf0e10cSrcweir * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*cdf0e10cSrcweir * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28*cdf0e10cSrcweir * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29*cdf0e10cSrcweir * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30*cdf0e10cSrcweir * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31*cdf0e10cSrcweir * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*cdf0e10cSrcweir * 33*cdf0e10cSrcweir *************************************************************************/ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir //_______________________________________________ 36*cdf0e10cSrcweir // imports 37*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 38*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.Factory; 39*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase; 40*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 41*cdf0e10cSrcweir import com.sun.star.awt.*; 42*cdf0e10cSrcweir import com.sun.star.beans.*; 43*cdf0e10cSrcweir import com.sun.star.task.*; 44*cdf0e10cSrcweir import com.sun.star.uno.*; 45*cdf0e10cSrcweir import java.lang.*; 46*cdf0e10cSrcweir import javax.swing.*; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir //_______________________________________________ 49*cdf0e10cSrcweir // implementation 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir /** it implements a simple job component. 52*cdf0e10cSrcweir * 53*cdf0e10cSrcweir * Such jobs are executable in different ways: 54*cdf0e10cSrcweir * <ul> 55*cdf0e10cSrcweir * <li>registered for a special URL schema "vnd.sun.star.jobs:*" and used from the generic dispatch framework</li> 56*cdf0e10cSrcweir * <li>the global com.sun.star.task.JobExecutor service and registered for special events.</li> 57*cdf0e10cSrcweir * </ul> 58*cdf0e10cSrcweir */ 59*cdf0e10cSrcweir public class AsyncJob extends WeakBase implements XServiceInfo, XAsyncJob 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir //___________________________________________ 62*cdf0e10cSrcweir // const 63*cdf0e10cSrcweir public final XComponentContext m_xCmpCtx; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir /** the const list of supported uno service names. */ 66*cdf0e10cSrcweir public static final java.lang.String[] SERVICENAMES = {"com.sun.star.task.AsyncJob"}; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir /** the const uno implementation name. 69*cdf0e10cSrcweir * It must be an unique value! The best naming schema seams to use 70*cdf0e10cSrcweir * a registered domain in reverse order ... 71*cdf0e10cSrcweir */ 72*cdf0e10cSrcweir public static final java.lang.String IMPLEMENTATIONNAME = "com.sun.star.comp.framework.java.services.AsyncJob"; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir //___________________________________________ 75*cdf0e10cSrcweir // interface 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir /** initialize a new instance of this class with default values. */ 78*cdf0e10cSrcweir public AsyncJob( XComponentContext xCompContext ) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir m_xCmpCtx = xCompContext; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir //___________________________________________ 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir /** starts execution of this job. 86*cdf0e10cSrcweir * 87*cdf0e10cSrcweir * @param lArgs 88*cdf0e10cSrcweir * list which contains: 89*cdf0e10cSrcweir * <ul> 90*cdf0e10cSrcweir * <li>generic job configuration data</li> 91*cdf0e10cSrcweir * <li>job specific configuration data</li> 92*cdf0e10cSrcweir * <li>some environment informations</li> 93*cdf0e10cSrcweir * <li>may optional arguments of a corresponding dispatch request</li> 94*cdf0e10cSrcweir * </ul> 95*cdf0e10cSrcweir * 96*cdf0e10cSrcweir * @params xListener 97*cdf0e10cSrcweir * callback to the executor of this job, which control our life time 98*cdf0e10cSrcweir * 99*cdf0e10cSrcweir * @throws com.sun.star.lang.IllegalArgumentException 100*cdf0e10cSrcweir * if given argument list seams to be wrong 101*cdf0e10cSrcweir */ 102*cdf0e10cSrcweir public synchronized void executeAsync(com.sun.star.beans.NamedValue[] lArgs , 103*cdf0e10cSrcweir com.sun.star.task.XJobListener xListener) 104*cdf0e10cSrcweir throws com.sun.star.lang.IllegalArgumentException 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir // For asynchronous jobs a valid listener reference is guranteed normaly ... 107*cdf0e10cSrcweir if (xListener == null) 108*cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException("invalid listener"); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // extract all possible sub list of given argument list 111*cdf0e10cSrcweir com.sun.star.beans.NamedValue[] lGenericConfig = null; 112*cdf0e10cSrcweir com.sun.star.beans.NamedValue[] lJobConfig = null; 113*cdf0e10cSrcweir com.sun.star.beans.NamedValue[] lEnvironment = null; 114*cdf0e10cSrcweir com.sun.star.beans.NamedValue[] lDynamicData = null; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir int c = lArgs.length; 117*cdf0e10cSrcweir for (int i=0; i<c; ++i) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir if (lArgs[i].Name.equals("Config")) 120*cdf0e10cSrcweir lGenericConfig = (com.sun.star.beans.NamedValue[])com.sun.star.uno.AnyConverter.toArray(lArgs[i].Value); 121*cdf0e10cSrcweir else 122*cdf0e10cSrcweir if (lArgs[i].Name.equals("JobConfig")) 123*cdf0e10cSrcweir lJobConfig = (com.sun.star.beans.NamedValue[])com.sun.star.uno.AnyConverter.toArray(lArgs[i].Value); 124*cdf0e10cSrcweir else 125*cdf0e10cSrcweir if (lArgs[i].Name.equals("Environment")) 126*cdf0e10cSrcweir lEnvironment = (com.sun.star.beans.NamedValue[])com.sun.star.uno.AnyConverter.toArray(lArgs[i].Value); 127*cdf0e10cSrcweir else 128*cdf0e10cSrcweir if (lArgs[i].Name.equals("DynamicData")) 129*cdf0e10cSrcweir lDynamicData = (com.sun.star.beans.NamedValue[])com.sun.star.uno.AnyConverter.toArray(lArgs[i].Value); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir // Analyze the environment info. This sub list is the only guarenteed one! 133*cdf0e10cSrcweir if (lEnvironment == null) 134*cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException("no environment"); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir java.lang.String sEnvType = null; 137*cdf0e10cSrcweir java.lang.String sEventName = null; 138*cdf0e10cSrcweir com.sun.star.frame.XFrame xFrame = null; 139*cdf0e10cSrcweir c = lEnvironment.length; 140*cdf0e10cSrcweir for (int i=0; i<c; ++i) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir if (lEnvironment[i].Name.equals("EnvType")) 143*cdf0e10cSrcweir sEnvType = com.sun.star.uno.AnyConverter.toString(lEnvironment[i].Value); 144*cdf0e10cSrcweir else 145*cdf0e10cSrcweir if (lEnvironment[i].Name.equals("EventName")) 146*cdf0e10cSrcweir sEventName = com.sun.star.uno.AnyConverter.toString(lEnvironment[i].Value); 147*cdf0e10cSrcweir else 148*cdf0e10cSrcweir if (lEnvironment[i].Name.equals("Frame")) 149*cdf0e10cSrcweir xFrame = (com.sun.star.frame.XFrame)com.sun.star.uno.AnyConverter.toObject( 150*cdf0e10cSrcweir new com.sun.star.uno.Type(com.sun.star.frame.XFrame.class), 151*cdf0e10cSrcweir lEnvironment[i].Value); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // Further the environment property "EnvType" is required as minimum. 155*cdf0e10cSrcweir if ( 156*cdf0e10cSrcweir (sEnvType==null) || 157*cdf0e10cSrcweir ( 158*cdf0e10cSrcweir (!sEnvType.equals("EXECUTOR")) && 159*cdf0e10cSrcweir (!sEnvType.equals("DISPATCH")) 160*cdf0e10cSrcweir ) 161*cdf0e10cSrcweir ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir java.lang.String sMessage = "\"" + sEnvType + "\" isn't a valid value for EnvType"; 164*cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException(sMessage); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // Analyze the set of shared config data. 168*cdf0e10cSrcweir java.lang.String sAlias = null; 169*cdf0e10cSrcweir if (lGenericConfig!=null) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir c = lGenericConfig.length; 172*cdf0e10cSrcweir for (int i=0; i<c; ++i) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir if (lGenericConfig[i].Name.equals("Alias")) 175*cdf0e10cSrcweir sAlias = com.sun.star.uno.AnyConverter.toString(lGenericConfig[i].Value); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir // do your job ... 180*cdf0e10cSrcweir // Here we print out all found arguments. 181*cdf0e10cSrcweir java.lang.String sOut = formatOutArgs(lGenericConfig, lJobConfig, lEnvironment, lDynamicData); 182*cdf0e10cSrcweir if (xFrame != null) 183*cdf0e10cSrcweir showInfoModal(xFrame.getContainerWindow(), "Arguments of AsyncJob initialization ...", sOut); 184*cdf0e10cSrcweir else 185*cdf0e10cSrcweir showInfoNonModal("Arguments of AsyncJob initialization ...", sOut); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // use return value to start different actions 188*cdf0e10cSrcweir // But look for the right environment. Some options make no sense inside the wrong env. 189*cdf0e10cSrcweir com.sun.star.beans.NamedValue aDeactivation = null; 190*cdf0e10cSrcweir com.sun.star.beans.NamedValue aDispatchResult = null; 191*cdf0e10cSrcweir com.sun.star.beans.NamedValue aSaveRequest = null; 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir // SaveArguments will be made everytimes! 194*cdf0e10cSrcweir c = 1; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir if (lJobConfig==null) 197*cdf0e10cSrcweir lJobConfig = new com.sun.star.beans.NamedValue[1]; 198*cdf0e10cSrcweir lJobConfig[0] = new com.sun.star.beans.NamedValue(); 199*cdf0e10cSrcweir lJobConfig[0].Name = "arg_1"; 200*cdf0e10cSrcweir lJobConfig[0].Value = "val_1"; 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir aSaveRequest = new com.sun.star.beans.NamedValue(); 203*cdf0e10cSrcweir aSaveRequest.Name = "SaveArguments"; 204*cdf0e10cSrcweir aSaveRequest.Value = lJobConfig; 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // Deactivation is usefull inside EXECUTOR environment only 207*cdf0e10cSrcweir if (sEnvType.equals("EXECUTOR")) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir ++c; 210*cdf0e10cSrcweir aDeactivation = new com.sun.star.beans.NamedValue(); 211*cdf0e10cSrcweir aDeactivation.Name = "Deactivate"; 212*cdf0e10cSrcweir aDeactivation.Value = java.lang.Boolean.TRUE; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir // Sending of result events is usefull inside DISPATCH environment only 216*cdf0e10cSrcweir if (sEnvType.equals("DISPATCH")) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir ++c; 219*cdf0e10cSrcweir aDispatchResult = new com.sun.star.beans.NamedValue(); 220*cdf0e10cSrcweir aDispatchResult.Name = "SendDispatchResult"; 221*cdf0e10cSrcweir aDispatchResult.Value = new com.sun.star.frame.DispatchResultEvent(this, com.sun.star.frame.DispatchResultState.SUCCESS, null); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // pack it together for return 225*cdf0e10cSrcweir int i=0; 226*cdf0e10cSrcweir com.sun.star.beans.NamedValue[] lReturn = new com.sun.star.beans.NamedValue[c]; 227*cdf0e10cSrcweir lReturn[i++] = aSaveRequest; 228*cdf0e10cSrcweir if (aDeactivation!=null) 229*cdf0e10cSrcweir lReturn[i++] = aDeactivation; 230*cdf0e10cSrcweir if (aDispatchResult!=null) 231*cdf0e10cSrcweir lReturn[i++] = aDispatchResult; 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir xListener.jobFinished(this, lReturn); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir //___________________________________________ 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir /** show an info box with the UNO based toolkit. 239*cdf0e10cSrcweir * 240*cdf0e10cSrcweir * It tries to use the container window of a may well know 241*cdf0e10cSrcweir * office frame as parent. If such parent window could be located, 242*cdf0e10cSrcweir * the info box can be shown in modal mode. If a parent is missing 243*cdf0e10cSrcweir * (because this job is called inside an EXECUTOR environment, which 244*cdf0e10cSrcweir * does not set any frame context here) the info box can't be created! 245*cdf0e10cSrcweir * Because the toolkit needs parents for non top level windows ... 246*cdf0e10cSrcweir * In that case the only way is to implement this info box 247*cdf0e10cSrcweir * native or make it non modal using java dialogs inside it's own thread ... 248*cdf0e10cSrcweir * (see showInfoNonModal() too) 249*cdf0e10cSrcweir * 250*cdf0e10cSrcweir * @param xParent 251*cdf0e10cSrcweir * used as parent window of the shown info box. 252*cdf0e10cSrcweir * 253*cdf0e10cSrcweir * @param sTitle 254*cdf0e10cSrcweir * is shown as title of the info box. 255*cdf0e10cSrcweir * 256*cdf0e10cSrcweir * @param sMessage 257*cdf0e10cSrcweir * inclused the message body, which is shown as info. 258*cdf0e10cSrcweir */ 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir private void showInfoModal( com.sun.star.awt.XWindow xParent , 261*cdf0e10cSrcweir java.lang.String sTitle , 262*cdf0e10cSrcweir java.lang.String sMessage ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir try 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir // get access to the office toolkit environment 267*cdf0e10cSrcweir com.sun.star.awt.XToolkit xKit = (com.sun.star.awt.XToolkit)UnoRuntime.queryInterface( 268*cdf0e10cSrcweir com.sun.star.awt.XToolkit.class, 269*cdf0e10cSrcweir m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", 270*cdf0e10cSrcweir m_xCmpCtx)); 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir // describe the info box ini it's parameters 273*cdf0e10cSrcweir com.sun.star.awt.WindowDescriptor aDescriptor = new com.sun.star.awt.WindowDescriptor(); 274*cdf0e10cSrcweir aDescriptor.WindowServiceName = "infobox"; 275*cdf0e10cSrcweir aDescriptor.Bounds = new com.sun.star.awt.Rectangle(0,0,300,200); 276*cdf0e10cSrcweir aDescriptor.WindowAttributes = com.sun.star.awt.WindowAttribute.BORDER | 277*cdf0e10cSrcweir com.sun.star.awt.WindowAttribute.MOVEABLE | 278*cdf0e10cSrcweir com.sun.star.awt.WindowAttribute.CLOSEABLE; 279*cdf0e10cSrcweir aDescriptor.Type = com.sun.star.awt.WindowClass.MODALTOP; 280*cdf0e10cSrcweir aDescriptor.ParentIndex = 1; 281*cdf0e10cSrcweir aDescriptor.Parent = (com.sun.star.awt.XWindowPeer)UnoRuntime.queryInterface( 282*cdf0e10cSrcweir com.sun.star.awt.XWindowPeer.class, 283*cdf0e10cSrcweir xParent); 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir // create the info box window 286*cdf0e10cSrcweir com.sun.star.awt.XWindowPeer xPeer = xKit.createWindow(aDescriptor); 287*cdf0e10cSrcweir com.sun.star.awt.XMessageBox xInfoBox = (com.sun.star.awt.XMessageBox)UnoRuntime.queryInterface( 288*cdf0e10cSrcweir com.sun.star.awt.XMessageBox.class, 289*cdf0e10cSrcweir xPeer); 290*cdf0e10cSrcweir if (xInfoBox == null) 291*cdf0e10cSrcweir return; 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir // fill it with all given informations and show it 294*cdf0e10cSrcweir xInfoBox.setCaptionText(sTitle); 295*cdf0e10cSrcweir xInfoBox.setMessageText(sMessage); 296*cdf0e10cSrcweir xInfoBox.execute(); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir catch(java.lang.Throwable exIgnore) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir // ignore any problem, which can occure here. 301*cdf0e10cSrcweir // It's not realy a bug for this example job, if 302*cdf0e10cSrcweir // it's message could not be printed out! 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir //___________________________________________ 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir private void showInfoNonModal( java.lang.String sTitle , 309*cdf0e10cSrcweir java.lang.String sMessage ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir // Couldnt be implemented realy using the toolkit ... 312*cdf0e10cSrcweir // Because we need a parent anytime. 313*cdf0e10cSrcweir // And showing e.g. a java dialog can make some trouble 314*cdf0e10cSrcweir // inside office ... but we have no chance here. 315*cdf0e10cSrcweir final java.lang.String sFinalTitle = sTitle; 316*cdf0e10cSrcweir final java.lang.String sFinalMessage = sMessage; 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir // On Mac OS X, AWT/Swing must not be accessed from the AppKit thread, so call 319*cdf0e10cSrcweir // SwingUtilities.invokeLater always on a fresh thread to avoid that problem 320*cdf0e10cSrcweir // (also, the current thread must not wait for that fresh thread to terminate, 321*cdf0e10cSrcweir // as that would cause a deadlock if this thread is the AppKit thread): 322*cdf0e10cSrcweir final Runnable doRun = new Runnable() { 323*cdf0e10cSrcweir public void run() { 324*cdf0e10cSrcweir javax.swing.JOptionPane.showMessageDialog(null, sFinalMessage, sFinalTitle, javax.swing.JOptionPane.INFORMATION_MESSAGE); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir }; 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir new Thread( doRun ) { 329*cdf0e10cSrcweir public void run() { javax.swing.SwingUtilities.invokeLater(doRun); } 330*cdf0e10cSrcweir }.start(); 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir //___________________________________________ 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir /** helper to print out the given argument list. 336*cdf0e10cSrcweir * 337*cdf0e10cSrcweir * @param lGenericConfig 338*cdf0e10cSrcweir * contains all shared configuration items for a job 339*cdf0e10cSrcweir * 340*cdf0e10cSrcweir * @param lJobConfig 341*cdf0e10cSrcweir * contains all job sepcific configuration items 342*cdf0e10cSrcweir * 343*cdf0e10cSrcweir * @param lEnvironment 344*cdf0e10cSrcweir * contains some environment informations 345*cdf0e10cSrcweir * 346*cdf0e10cSrcweir * @param lDynamicData 347*cdf0e10cSrcweir * contains optional data of a might corresponding dispatch() request 348*cdf0e10cSrcweir */ 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir private java.lang.String formatOutArgs(com.sun.star.beans.NamedValue[] lGenericConfig, 351*cdf0e10cSrcweir com.sun.star.beans.NamedValue[] lJobConfig , 352*cdf0e10cSrcweir com.sun.star.beans.NamedValue[] lEnvironment , 353*cdf0e10cSrcweir com.sun.star.beans.NamedValue[] lDynamicData ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir java.lang.StringBuffer sOut = new java.lang.StringBuffer(1024); 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir sOut.append("list \"Config\": "); 358*cdf0e10cSrcweir if (lGenericConfig==null) 359*cdf0e10cSrcweir sOut.append("0 items\n"); 360*cdf0e10cSrcweir else 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir int c = lGenericConfig.length; 363*cdf0e10cSrcweir sOut.append(c+" items\n"); 364*cdf0e10cSrcweir for (int i=0; i<c; ++i) 365*cdf0e10cSrcweir sOut.append("\t["+i+"] \""+lGenericConfig[i].Name+"\" = {"+lGenericConfig[i].Value+"}\n"); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir sOut.append("list \"JobConfig\": "); 368*cdf0e10cSrcweir if (lJobConfig==null) 369*cdf0e10cSrcweir sOut.append("0 items\n"); 370*cdf0e10cSrcweir else 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir int c = lJobConfig.length; 373*cdf0e10cSrcweir sOut.append(c+" items\n"); 374*cdf0e10cSrcweir for (int i=0; i<c; ++i) 375*cdf0e10cSrcweir sOut.append("\t["+i+"] \""+lJobConfig[i].Name+"\" = {"+lJobConfig[i].Value+"}\n"); 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir sOut.append("list \"Environment\": "); 378*cdf0e10cSrcweir if (lEnvironment==null) 379*cdf0e10cSrcweir sOut.append("0 items\n"); 380*cdf0e10cSrcweir else 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir int c = lEnvironment.length; 383*cdf0e10cSrcweir sOut.append(c+" items\n"); 384*cdf0e10cSrcweir for (int i=0; i<c; ++i) 385*cdf0e10cSrcweir sOut.append("\t["+i+"] \""+lEnvironment[i].Name+"\" = {"+lEnvironment[i].Value+"}\n"); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir sOut.append("list \"DynamicData\": "); 388*cdf0e10cSrcweir if (lDynamicData==null) 389*cdf0e10cSrcweir sOut.append("0 items\n"); 390*cdf0e10cSrcweir else 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir int c = lDynamicData.length; 393*cdf0e10cSrcweir sOut.append(c+" items\n"); 394*cdf0e10cSrcweir for (int i=0; i<c; ++i) 395*cdf0e10cSrcweir sOut.append("\t["+i+"] \""+lDynamicData[i].Name+"\" = {"+lDynamicData[i].Value+"}\n"); 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir return sOut.toString(); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir public String[] getSupportedServiceNames() { 402*cdf0e10cSrcweir return SERVICENAMES; 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir public boolean supportsService( String sService ) { 406*cdf0e10cSrcweir int len = SERVICENAMES.length; 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir for( int i=0; i < len; i++) { 409*cdf0e10cSrcweir if ( sService.equals( SERVICENAMES[i] ) ) 410*cdf0e10cSrcweir return true; 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir return false; 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir public String getImplementationName() { 417*cdf0e10cSrcweir return( AsyncJob.class.getName() ); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir //___________________________________________ 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir public synchronized static com.sun.star.lang.XSingleComponentFactory __getComponentFactory(java.lang.String sImplName) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir com.sun.star.lang.XSingleComponentFactory xFactory = null; 426*cdf0e10cSrcweir if (sImplName.equals(AsyncJob.IMPLEMENTATIONNAME)) 427*cdf0e10cSrcweir xFactory = Factory.createComponentFactory(AsyncJob.class, SERVICENAMES); 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir return xFactory; 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir //___________________________________________ 433*cdf0e10cSrcweir // This method not longer necessary since OOo 3.4 where the component registration 434*cdf0e10cSrcweir // was changed to passive component registration. For more details see 435*cdf0e10cSrcweir // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir // public synchronized static boolean __writeRegistryServiceInfo(com.sun.star.registry.XRegistryKey xRegKey) 438*cdf0e10cSrcweir // { 439*cdf0e10cSrcweir // return Factory.writeRegistryServiceInfo( 440*cdf0e10cSrcweir // AsyncJob.IMPLEMENTATIONNAME, 441*cdf0e10cSrcweir // AsyncJob.SERVICENAMES, 442*cdf0e10cSrcweir // xRegKey); 443*cdf0e10cSrcweir // } 444*cdf0e10cSrcweir } 445