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