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