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