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