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.form; 24 25 import com.sun.star.beans.PropertyValue; 26 import com.sun.star.uno.Type; 27 import com.sun.star.wizards.common.Properties; 28 import com.sun.star.wizards.common.PropertyNames; 29 30 /** This class capsulates the class, that implements the minimal component, a 31 * factory for creating the service (<CODE>__getServiceFactory</CODE>). 32 * @author Bertram Nolte 33 */ 34 public class CallFormWizard 35 { 36 37 /** Gives a factory for creating the service. 38 * This method is called by the <code>JavaLoader</code> 39 * <p> 40 * @return Returns a <code>XSingleServiceFactory</code> for creating the 41 * component. 42 * @see com.sun.star.comp.loader.JavaLoader# 43 * @param stringImplementationName The implementation name of the component. 44 * @param xmultiservicefactory The service manager, who gives access to every 45 * known service. 46 * @param xregistrykey Makes structural information (except regarding tree 47 * structures) of a single 48 * registry key accessible. 49 */ __getServiceFactory(String stringImplementationName, com.sun.star.lang.XMultiServiceFactory xMSF, com.sun.star.registry.XRegistryKey xregistrykey)50 public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory(String stringImplementationName, com.sun.star.lang.XMultiServiceFactory xMSF, com.sun.star.registry.XRegistryKey xregistrykey) 51 { 52 com.sun.star.lang.XSingleServiceFactory xsingleservicefactory = null; 53 if (stringImplementationName.equals(FormWizardImplementation.class.getName())) 54 { 55 xsingleservicefactory = com.sun.star.comp.loader.FactoryHelper.getServiceFactory(FormWizardImplementation.class, FormWizardImplementation.__serviceName, xMSF, xregistrykey); 56 } 57 return xsingleservicefactory; 58 } 59 60 /** This class implements the component. At least the interfaces XServiceInfo, 61 * XTypeProvider, and XInitialization should be provided by the service. 62 */ 63 public static class FormWizardImplementation extends com.sun.star.lib.uno.helper.PropertySet implements com.sun.star.lang.XInitialization, com.sun.star.lang.XServiceInfo, com.sun.star.lang.XTypeProvider, com.sun.star.task.XJobExecutor 64 { 65 private PropertyValue[] m_wizardContext; 66 67 /** The constructor of the inner class has a XMultiServiceFactory parameter. 68 * @param xmultiservicefactoryInitialization A special service factory 69 * could be introduced while initializing. 70 */ FormWizardImplementation(com.sun.star.lang.XMultiServiceFactory xmultiservicefactoryInitialization)71 public FormWizardImplementation(com.sun.star.lang.XMultiServiceFactory xmultiservicefactoryInitialization) 72 { 73 super(); 74 m_serviceFactory = xmultiservicefactoryInitialization; 75 } 76 trigger(String sEvent)77 public void trigger(String sEvent) 78 { 79 try 80 { 81 if (sEvent.compareTo(PropertyNames.START) == 0) 82 { 83 FormWizard CurFormWizard = new FormWizard( m_serviceFactory, m_wizardContext ); 84 CurFormWizard.start(); 85 } 86 } 87 catch (Exception exception) 88 { 89 System.err.println(exception); 90 } 91 System.gc(); 92 } 93 /** The service name, that must be used to get an instance of this service. 94 */ 95 private static final String __serviceName = "com.sun.star.wizards.form.CallFormWizard"; 96 /** The service manager, that gives access to all registered services. 97 */ 98 private com.sun.star.lang.XMultiServiceFactory m_serviceFactory; 99 100 /** This method is a member of the interface for initializing an object 101 * directly after its creation. 102 * @param object This array of arbitrary objects will be passed to the 103 * component after its creation. 104 * @throws Exception Every exception will not be handled, but will be 105 * passed to the caller. 106 */ initialize(Object[] object)107 public void initialize(Object[] object) throws com.sun.star.uno.Exception 108 { 109 m_wizardContext = Properties.convertToPropertyValueArray(object); 110 } 111 112 /** This method returns an array of all supported service names. 113 * @return Array of supported service names. 114 */ getSupportedServiceNames()115 public java.lang.String[] getSupportedServiceNames() 116 { 117 String[] stringSupportedServiceNames = new String[1]; 118 119 stringSupportedServiceNames[0] = __serviceName; 120 121 return (stringSupportedServiceNames); 122 } 123 124 /** This method returns true, if the given service will be 125 * supported by the component. 126 * @param stringService Service name. 127 * @return True, if the given service name will be supported. 128 */ supportsService(String stringService)129 public boolean supportsService(String stringService) 130 { 131 boolean booleanSupportsService = false; 132 133 if (stringService.equals(__serviceName)) 134 { 135 booleanSupportsService = true; 136 } 137 return (booleanSupportsService); 138 } 139 140 /** This method returns an array of bytes, that can be used to 141 * unambiguously distinguish between two sets of types, e.g. 142 * to realise hashing functionality when the object is introspected. 143 * Two objects that return the same ID also have to return 144 * the same set of types in getTypes(). If an unique 145 * implementation Id cannot be provided this method has to 146 * return an empty sequence. Important: If the object 147 * aggregates other objects the ID has to be unique for the 148 * whole combination of objects. 149 * @return Array of bytes, in order to distinguish between two sets. 150 */ getImplementationId()151 public byte[] getImplementationId() 152 { 153 byte[] byteReturn = 154 { 155 }; 156 157 try 158 { 159 byteReturn = (PropertyNames.EMPTY_STRING + this.hashCode()).getBytes(); 160 } 161 catch (Exception exception) 162 { 163 System.err.println(exception); 164 } 165 166 return (byteReturn); 167 } 168 169 /** Return the class name of the component. 170 * @return Class name of the component. 171 */ getImplementationName()172 public java.lang.String getImplementationName() 173 { 174 return (FormWizardImplementation.class.getName()); 175 } 176 177 /** Provides a sequence of all types (usually interface types) 178 * provided by the object. 179 * @return Sequence of all types (usually interface types) provided by the 180 * service. 181 */ getTypes()182 public Type[] getTypes() 183 { 184 Type[] typeReturn = 185 { 186 }; 187 188 try 189 { 190 typeReturn = new Type[] 191 { 192 new Type(com.sun.star.task.XJobExecutor.class), new Type(com.sun.star.lang.XTypeProvider.class), new Type(com.sun.star.lang.XServiceInfo.class), new Type(com.sun.star.beans.XPropertySet.class), new Type(com.sun.star.beans.XFastPropertySet.class), new Type(com.sun.star.beans.XMultiPropertySet.class), new Type(com.sun.star.lang.XInitialization.class) 193 }; 194 } 195 catch (Exception exception) 196 { 197 System.err.println(exception); 198 } 199 200 return (typeReturn); 201 } 202 } 203 } 204