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