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