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.report; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 26cdf0e10cSrcweir import com.sun.star.uno.Type; 27cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 28cdf0e10cSrcweir import com.sun.star.wizards.common.Properties; 29cdf0e10cSrcweir import com.sun.star.sdb.application.XDatabaseDocumentUI; 30cdf0e10cSrcweir import com.sun.star.wizards.common.NamedValueCollection; 31cdf0e10cSrcweir import com.sun.star.wizards.common.PropertyNames; 32cdf0e10cSrcweir import java.util.logging.Level; 33cdf0e10cSrcweir import java.util.logging.Logger; 34cdf0e10cSrcweir 35cdf0e10cSrcweir /** This class capsulates the class, that implements the minimal component, a 36cdf0e10cSrcweir * factory for creating the service (<CODE>__getServiceFactory</CODE>). 37cdf0e10cSrcweir * @author Bertram Nolte 38cdf0e10cSrcweir */ 39cdf0e10cSrcweir public class CallReportWizard 40cdf0e10cSrcweir { 41cdf0e10cSrcweir 42cdf0e10cSrcweir static boolean bWizardstartedalready; 43cdf0e10cSrcweir 44cdf0e10cSrcweir /* public static void main(String args[]) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir String ConnectStr = "uno:pipe,name=fs93730;urp;StarOffice.ServiceManager"; 47cdf0e10cSrcweir try 48cdf0e10cSrcweir { 49cdf0e10cSrcweir XMultiServiceFactory orb = Desktop.connect(ConnectStr); 50cdf0e10cSrcweir if ( orb != null ) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir PropertyValue[] curproperties = new PropertyValue[1]; 53cdf0e10cSrcweir curproperties[0] = Properties.createProperty("DataSourceName", "countries"); 54cdf0e10cSrcweir 55cdf0e10cSrcweir ReportWizard wizard = new ReportWizard( orb, curproperties ); 56cdf0e10cSrcweir wizard.startReportWizard(); 57cdf0e10cSrcweir } 58cdf0e10cSrcweir } 59cdf0e10cSrcweir catch (java.lang.Exception jexception) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir jexception.printStackTrace(System.out); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir }*/ 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** Gives a factory for creating the service. 66cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 67cdf0e10cSrcweir * <p> 68cdf0e10cSrcweir * @return Returns a <code>XSingleServiceFactory</code> for creating the 69cdf0e10cSrcweir * component. 70cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader# 71cdf0e10cSrcweir * @param stringImplementationName The implementation name of the component. 72cdf0e10cSrcweir * @param xMSF The service manager, who gives access to every 73cdf0e10cSrcweir * known service. 74cdf0e10cSrcweir * @param xregistrykey Makes structural information (except regarding tree 75cdf0e10cSrcweir * structures) of a single 76cdf0e10cSrcweir * registry key accessible. 77cdf0e10cSrcweir */ __getServiceFactory(String stringImplementationName, com.sun.star.lang.XMultiServiceFactory xMSF, com.sun.star.registry.XRegistryKey xregistrykey)78cdf0e10cSrcweir public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory(String stringImplementationName, com.sun.star.lang.XMultiServiceFactory xMSF, com.sun.star.registry.XRegistryKey xregistrykey) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir com.sun.star.lang.XSingleServiceFactory xsingleservicefactory = null; 81cdf0e10cSrcweir if (stringImplementationName.equals( 82cdf0e10cSrcweir ReportWizardImplementation.class.getName())) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir xsingleservicefactory = com.sun.star.comp.loader.FactoryHelper.getServiceFactory( 85cdf0e10cSrcweir ReportWizardImplementation.class, 86cdf0e10cSrcweir ReportWizardImplementation.__serviceName, 87cdf0e10cSrcweir xMSF, 88cdf0e10cSrcweir xregistrykey); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir return xsingleservicefactory; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir /** This class implements the component. At least the interfaces XServiceInfo, 94cdf0e10cSrcweir * XTypeProvider, and XInitialization should be provided by the service. 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir public static class ReportWizardImplementation 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 97cdf0e10cSrcweir { 98cdf0e10cSrcweir 99cdf0e10cSrcweir private PropertyValue[] m_wizardContext; 100cdf0e10cSrcweir 101cdf0e10cSrcweir /** The constructor of the inner class has a XMultiServiceFactory parameter. 102cdf0e10cSrcweir * @param xmultiservicefactoryInitialization A special service factory 103cdf0e10cSrcweir * could be introduced while initializing. 104cdf0e10cSrcweir */ ReportWizardImplementation(com.sun.star.lang.XMultiServiceFactory xmultiservicefactoryInitialization)105cdf0e10cSrcweir public ReportWizardImplementation(com.sun.star.lang.XMultiServiceFactory xmultiservicefactoryInitialization) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir super(); 108cdf0e10cSrcweir xmultiservicefactory = xmultiservicefactoryInitialization; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir trigger(String sEvent)111cdf0e10cSrcweir public void trigger(String sEvent) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir try 114cdf0e10cSrcweir { 115cdf0e10cSrcweir if (sEvent.compareTo(PropertyNames.START) == 0) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir if (!bWizardstartedalready) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir ReportWizard CurReportWizard = new ReportWizard( xmultiservicefactory, m_wizardContext ); 120cdf0e10cSrcweir CurReportWizard.startReportWizard(); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir bWizardstartedalready = false; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir else if (sEvent.compareTo("fill") == 0) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir Dataimport CurDataimport = new Dataimport(xmultiservicefactory); 127cdf0e10cSrcweir if (m_wizardContext != null) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir NamedValueCollection context = new NamedValueCollection( m_wizardContext ); 130cdf0e10cSrcweir XTextDocument textDocument = context.queryOrDefault( "TextDocument", null, XTextDocument.class ); 131cdf0e10cSrcweir XDatabaseDocumentUI documentUI = context.queryOrDefault( "DocumentUI", null, XDatabaseDocumentUI.class ); 132cdf0e10cSrcweir if ( textDocument != null ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir CurDataimport.createReport(xmultiservicefactory, documentUI, textDocument, m_wizardContext); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir catch (Exception e) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir Logger.getLogger(CallReportWizard.class.getName()).log(Level.SEVERE, null, e); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir System.gc(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir /** The service name, that must be used to get an instance of this service. 146cdf0e10cSrcweir */ 147cdf0e10cSrcweir private static final String __serviceName = "com.sun.star.wizards.report.CallReportWizard"; 148cdf0e10cSrcweir /** The service manager, that gives access to all registered services. 149cdf0e10cSrcweir */ 150cdf0e10cSrcweir private com.sun.star.lang.XMultiServiceFactory xmultiservicefactory; 151cdf0e10cSrcweir 152cdf0e10cSrcweir /** This method is a member of the interface for initializing an object 153cdf0e10cSrcweir * directly after its creation. 154cdf0e10cSrcweir * @param object This array of arbitrary objects will be passed to the 155cdf0e10cSrcweir * component after its creation. 156cdf0e10cSrcweir * @throws com.sun.star.uno.Exception Every exception will not be handled, but will be 157cdf0e10cSrcweir * passed to the caller. 158cdf0e10cSrcweir */ initialize(Object[] object)159cdf0e10cSrcweir public void initialize(Object[] object) throws com.sun.star.uno.Exception 160cdf0e10cSrcweir { 161cdf0e10cSrcweir this.m_wizardContext = Properties.convertToPropertyValueArray(object); 162cdf0e10cSrcweir 163cdf0e10cSrcweir // xmultiservicefactory = (XMultiservicefactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, object[0]); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir /** This method returns an array of all supported service names. 167cdf0e10cSrcweir * @return Array of supported service names. 168cdf0e10cSrcweir */ getSupportedServiceNames()169cdf0e10cSrcweir public java.lang.String[] getSupportedServiceNames() 170cdf0e10cSrcweir { 171cdf0e10cSrcweir String[] stringSupportedServiceNames = new String[1]; 172cdf0e10cSrcweir 173cdf0e10cSrcweir stringSupportedServiceNames[ 0] = __serviceName; 174cdf0e10cSrcweir 175cdf0e10cSrcweir return (stringSupportedServiceNames); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir /** This method returns true, if the given service will be 179cdf0e10cSrcweir * supported by the component. 180cdf0e10cSrcweir * @param stringService Service name. 181cdf0e10cSrcweir * @return True, if the given service name will be supported. 182cdf0e10cSrcweir */ supportsService(String stringService)183cdf0e10cSrcweir public boolean supportsService(String stringService) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir boolean booleanSupportsService = false; 186cdf0e10cSrcweir 187cdf0e10cSrcweir if (stringService.equals(__serviceName)) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir booleanSupportsService = true; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir return (booleanSupportsService); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir /** This method returns an array of bytes, that can be used to 195cdf0e10cSrcweir * unambiguously distinguish between two sets of types, e.g. 196cdf0e10cSrcweir * to realise hashing functionality when the object is introspected. 197cdf0e10cSrcweir * Two objects that return the same ID also have to return 198cdf0e10cSrcweir * the same set of types in getTypes(). If an unique 199cdf0e10cSrcweir * implementation Id cannot be provided this method has to 200cdf0e10cSrcweir * return an empty sequence. Important: If the object 201cdf0e10cSrcweir * aggregates other objects the ID has to be unique for the 202cdf0e10cSrcweir * whole combination of objects. 203cdf0e10cSrcweir * @return Array of bytes, in order to distinguish between two sets. 204cdf0e10cSrcweir */ getImplementationId()205cdf0e10cSrcweir public byte[] getImplementationId() 206cdf0e10cSrcweir { 207cdf0e10cSrcweir byte[] byteReturn = 208cdf0e10cSrcweir { 209cdf0e10cSrcweir }; 210cdf0e10cSrcweir 211cdf0e10cSrcweir try 212cdf0e10cSrcweir { 213cdf0e10cSrcweir byteReturn = (PropertyNames.EMPTY_STRING + this.hashCode()).getBytes(); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir catch (Exception e) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir Logger.getLogger(CallReportWizard.class.getName()).log(Level.SEVERE, null, e); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir return (byteReturn); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir /** Return the class name of the component. 224cdf0e10cSrcweir * @return Class name of the component. 225cdf0e10cSrcweir */ getImplementationName()226cdf0e10cSrcweir public java.lang.String getImplementationName() 227cdf0e10cSrcweir { 228cdf0e10cSrcweir return (ReportWizardImplementation.class.getName()); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir /** Provides a sequence of all types (usually interface types) 232cdf0e10cSrcweir * provided by the object. 233cdf0e10cSrcweir * @return Sequence of all types (usually interface types) provided by the 234cdf0e10cSrcweir * service. 235cdf0e10cSrcweir */ getTypes()236cdf0e10cSrcweir public Type[] getTypes() 237cdf0e10cSrcweir { 238cdf0e10cSrcweir Type[] typeReturn = 239cdf0e10cSrcweir { 240cdf0e10cSrcweir }; 241cdf0e10cSrcweir 242cdf0e10cSrcweir try 243cdf0e10cSrcweir { 244cdf0e10cSrcweir typeReturn = new Type[] 245cdf0e10cSrcweir { 246cdf0e10cSrcweir new Type(com.sun.star.task.XJobExecutor.class), 247cdf0e10cSrcweir new Type(com.sun.star.lang.XTypeProvider.class), 248cdf0e10cSrcweir new Type(com.sun.star.lang.XServiceInfo.class), 249cdf0e10cSrcweir new Type(com.sun.star.lang.XInitialization.class) 250cdf0e10cSrcweir }; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir catch (Exception e) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir Logger.getLogger(CallReportWizard.class.getName()).log(Level.SEVERE, null, e); 255cdf0e10cSrcweir } 256cdf0e10cSrcweir 257cdf0e10cSrcweir return (typeReturn); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir } 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262