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