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