xref: /AOO41X/main/odk/examples/java/Inspector/Inspector.java (revision 34dd1e2512dbacb6a9a7e4c7f17b9296daa8eff3)
1*34dd1e25SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir import com.sun.star.awt.Rectangle;
25cdf0e10cSrcweir import com.sun.star.awt.XMessageBox;
26cdf0e10cSrcweir import com.sun.star.awt.XMessageBoxFactory;
27cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer;
28cdf0e10cSrcweir import com.sun.star.beans.NamedValue;
29cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
30cdf0e10cSrcweir import com.sun.star.container.XNameAccess;
31cdf0e10cSrcweir import com.sun.star.frame.XModel;
32cdf0e10cSrcweir import com.sun.star.lang.XComponent;
33cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
34cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
35cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
36cdf0e10cSrcweir import com.sun.star.lang.XSingleComponentFactory;
37cdf0e10cSrcweir import com.sun.star.lib.uno.helper.Factory;
38cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
39cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
40cdf0e10cSrcweir import com.sun.star.ui.dialogs.XExecutableDialog;
41cdf0e10cSrcweir import com.sun.star.ui.dialogs.XFolderPicker;
42cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
43cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
44cdf0e10cSrcweir import com.sun.star.util.CloseVetoException;
45cdf0e10cSrcweir import com.sun.star.util.XChangesBatch;
46cdf0e10cSrcweir import com.sun.star.util.XCloseable;
47cdf0e10cSrcweir import java.util.HashMap;
48cdf0e10cSrcweir import java.util.Iterator;
49cdf0e10cSrcweir import java.util.Set;
50cdf0e10cSrcweir import java.util.Vector;
51cdf0e10cSrcweir import org.openoffice.XInstanceInspector;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir /** The purpose of this class is to provide a factory for creating the service
55cdf0e10cSrcweir  * (<CODE>__getServiceFactory</CODE>) and writes the information into the given
56cdf0e10cSrcweir  * registry key (<CODE>__writeRegistryServiceInfo</CODE>).
57cdf0e10cSrcweir  */
58cdf0e10cSrcweir public class Inspector{
59cdf0e10cSrcweir      public static final String sIDLDOCUMENTSUBFOLDER = "docs/common/ref/";
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     /** This class implements the method of the interface XInstanceInspector.
63cdf0e10cSrcweir      * Also the class implements the interfaces XServiceInfo, and XTypeProvider.
64cdf0e10cSrcweir      */
65cdf0e10cSrcweir     static public class _Inspector extends WeakBase implements XInstanceInspector, XServiceInfo{
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         static private final String __serviceName = "org.openoffice.InstanceInspector";
68cdf0e10cSrcweir         private HashMap aApplicationHashMap = new HashMap();
69cdf0e10cSrcweir         private String sTitle = "Object Inspector";
70cdf0e10cSrcweir         private Vector aHiddenDocuments = new Vector();
71cdf0e10cSrcweir //        private String[] sApplicationDocUrls = new String[]{"private:factory/swriter", "private:factory/scalc", "private:factory/simpress", "private:factory/sdraw", "private:factory/sbase"};
72cdf0e10cSrcweir //        private String[] sApplicationDocNames = new String[]{"Text Document", "Spreadsheet", "Presentation", "Drawing", "Database"};
73cdf0e10cSrcweir         private XComponentContext m_xComponentContext;
74cdf0e10cSrcweir         private HashMap aInspectorPanes = new HashMap();
75cdf0e10cSrcweir         private XDialogProvider m_oSwingDialogProvider;
76cdf0e10cSrcweir         private TDocSupplier oTDocSupplier;
77cdf0e10cSrcweir         private Introspector m_oIntrospector = null;
78cdf0e10cSrcweir         // TODO: improve these strings:
79cdf0e10cSrcweir         private static final String sWRONGINSTALLATIONPATH = "Your selected path does not refer to an SDK-Installation!";
80cdf0e10cSrcweir         /** Creates a new instance of Dialog */
81cdf0e10cSrcweir         public _Inspector(XComponentContext _xComponentContext) {
82cdf0e10cSrcweir             m_xComponentContext = _xComponentContext;
83cdf0e10cSrcweir             m_oIntrospector = Introspector.getIntrospector(m_xComponentContext);
84cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/swriter", "Text Document");
85cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/scalc", "Spreadsheet");
86cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/simpress", "Presentation");
87cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/sdraw", "Drawing");
88cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/smath", "Formula");
89cdf0e10cSrcweir             m_oSwingDialogProvider = new SwingDialogProvider(this, sTitle);
90cdf0e10cSrcweir //            aApplicationHashMap.put("private:factory/sbase", "Database");
91cdf0e10cSrcweir         }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         public XComponentContext getXComponentContext(){
95cdf0e10cSrcweir             return m_xComponentContext;
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         public HashMap getInspectorPages(){
100cdf0e10cSrcweir             return aInspectorPanes;
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         protected String getSDKPath(){
105cdf0e10cSrcweir         String sRetPath = "";
106cdf0e10cSrcweir         try{
107cdf0e10cSrcweir             XNameAccess xNameAccess  = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
108cdf0e10cSrcweir             XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
109cdf0e10cSrcweir             sRetPath = (String) xPropertySet.getPropertyValue("SDKPath");
110cdf0e10cSrcweir         }catch( Exception exception ) {
111cdf0e10cSrcweir             exception.printStackTrace(System.out);
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir         return sRetPath;
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         public String getIDLPath(){
118cdf0e10cSrcweir             String sRetPath = getSDKPath();
119cdf0e10cSrcweir             if (m_oIntrospector.isValidSDKInstallationPath(sRetPath)){
120cdf0e10cSrcweir                 sRetPath = m_oIntrospector.addToPath(sRetPath, sIDLDOCUMENTSUBFOLDER);
121cdf0e10cSrcweir             }
122cdf0e10cSrcweir             else{
123cdf0e10cSrcweir                 sRetPath = "";
124cdf0e10cSrcweir             }
125cdf0e10cSrcweir             return sRetPath;
126cdf0e10cSrcweir         }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         public void openIdlFileforSelectedNode(){
130cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
131cdf0e10cSrcweir             if (oInspectorPane != null){
132cdf0e10cSrcweir                 XUnoNode oUnoNode = oInspectorPane.getSelectedNode();
133cdf0e10cSrcweir                 if (oUnoNode != null){
134cdf0e10cSrcweir                     String sPath = getIDLPath();
135cdf0e10cSrcweir                     oUnoNode.openIdlDescription(sPath);
136cdf0e10cSrcweir                 }
137cdf0e10cSrcweir             }
138cdf0e10cSrcweir         }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         public void assignSDKPath() {
142cdf0e10cSrcweir         try {
143cdf0e10cSrcweir             String sInstallationFolder = "";
144cdf0e10cSrcweir             Object oFolderPicker = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.ui.dialogs.FolderPicker", m_xComponentContext);
145cdf0e10cSrcweir             XFolderPicker xFolderPicker = (XFolderPicker) UnoRuntime.queryInterface(XFolderPicker.class, oFolderPicker);
146cdf0e10cSrcweir             XExecutableDialog xExecutable = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, oFolderPicker);
147cdf0e10cSrcweir             XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, oFolderPicker);
148cdf0e10cSrcweir             String sPath = getSDKPath();
149cdf0e10cSrcweir             if (!sPath.equals("")){
150cdf0e10cSrcweir                 xFolderPicker.setDisplayDirectory(sPath);
151cdf0e10cSrcweir             }
152cdf0e10cSrcweir             xFolderPicker.setTitle("Add the Path to your SDK installation");
153cdf0e10cSrcweir             short nResult = xExecutable.execute();
154cdf0e10cSrcweir             if (nResult == com.sun.star.ui.dialogs.ExecutableDialogResults.OK){
155cdf0e10cSrcweir                 sInstallationFolder = xFolderPicker.getDirectory();
156cdf0e10cSrcweir                 if (m_oIntrospector.isValidSDKInstallationPath(sInstallationFolder)){
157cdf0e10cSrcweir                     XNameAccess xNameAccess = getConfigurationAccess(true);
158cdf0e10cSrcweir                     XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
159cdf0e10cSrcweir                     xPropertySet.setPropertyValue("SDKPath", sInstallationFolder);
160cdf0e10cSrcweir                     XChangesBatch xBatch = (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
161cdf0e10cSrcweir                     xBatch.commitChanges();
162cdf0e10cSrcweir                 }
163cdf0e10cSrcweir                 else{
164cdf0e10cSrcweir                     XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFolderPicker);
165cdf0e10cSrcweir                     Object oWindow = xPropertySet.getPropertyValue("Window");
166cdf0e10cSrcweir                     XWindowPeer xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, oWindow);
167cdf0e10cSrcweir                     showErrorMessageBox(xWindowPeer, sTitle, sWRONGINSTALLATIONPATH);
168cdf0e10cSrcweir                     assignSDKPath();
169cdf0e10cSrcweir                 }
170cdf0e10cSrcweir             }
171cdf0e10cSrcweir             xComponent.dispose();
172cdf0e10cSrcweir         }catch( Exception exception ) {
173cdf0e10cSrcweir             exception.printStackTrace(System.out);
174cdf0e10cSrcweir         }}
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         public void showErrorMessageBox(XWindowPeer _xWindowPeer, String _sTitle, String _sMessage){
178cdf0e10cSrcweir         try {
179cdf0e10cSrcweir             Object oToolkit = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xComponentContext);
180cdf0e10cSrcweir             XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit);
181cdf0e10cSrcweir             Rectangle aRectangle = new Rectangle();
182cdf0e10cSrcweir             XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(_xWindowPeer, aRectangle, "errorbox", com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, _sTitle, _sMessage);
183cdf0e10cSrcweir             XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox);
184cdf0e10cSrcweir             if (xMessageBox != null){
185cdf0e10cSrcweir                 short nResult = xMessageBox.execute();
186cdf0e10cSrcweir                 xComponent.dispose();
187cdf0e10cSrcweir             }
188cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception ex) {
189cdf0e10cSrcweir             ex.printStackTrace(System.out);
190cdf0e10cSrcweir         }}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         public void inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
194cdf0e10cSrcweir         try {
195cdf0e10cSrcweir             int nPageIndex = m_oSwingDialogProvider.getInspectorPageCount();
196cdf0e10cSrcweir             SwingTreeControlProvider oSwingTreeControlProvider = new SwingTreeControlProvider(m_oSwingDialogProvider);
197cdf0e10cSrcweir             InspectorPane oInspectorPane = new InspectorPane(getXComponentContext(), m_oSwingDialogProvider, oSwingTreeControlProvider, getSourceCodeLanguage());
198cdf0e10cSrcweir             oInspectorPane.inspect(_oUserDefinedObject, _sTitle);
199cdf0e10cSrcweir             getInspectorPages().put(_sTitle, oInspectorPane);
200cdf0e10cSrcweir             m_oSwingDialogProvider.show(nPageIndex);
201cdf0e10cSrcweir         }catch( Exception exception ) {
202cdf0e10cSrcweir             exception.printStackTrace(System.out);
203cdf0e10cSrcweir         }}
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         public void inspectOpenEmptyDocument(String _sApplicationDocUrl){
207cdf0e10cSrcweir             XComponent xComponent = getTDocSupplier().openEmptyDocument(_sApplicationDocUrl);
208cdf0e10cSrcweir             String sRootTitle = (String) aApplicationHashMap.get(_sApplicationDocUrl);
209cdf0e10cSrcweir             inspect(xComponent, sRootTitle);
210cdf0e10cSrcweir             aHiddenDocuments.add(xComponent);
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         public void inspectOpenDocument(String _sTDocUrl){
215cdf0e10cSrcweir             String sTreeNodeName = getTDocSupplier().getTitleByTDocUrl(_sTDocUrl);
216cdf0e10cSrcweir             XModel xTDocModel = getTDocSupplier().getXModelByTDocUrl(_sTDocUrl);
217cdf0e10cSrcweir             inspect(xTDocModel, sTreeNodeName);
218cdf0e10cSrcweir         }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         public void inspectSelectedNode(){
222cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
223cdf0e10cSrcweir             if (oInspectorPane != null){
224cdf0e10cSrcweir                 XUnoNode oUnoNode = oInspectorPane.getSelectedNode();
225cdf0e10cSrcweir                 Object oUnoObject = oUnoNode.getUnoObject();
226cdf0e10cSrcweir                 if (oUnoObject != null){
227cdf0e10cSrcweir                     String sNodeDescription = UnoNode.getNodeDescription(oUnoObject);
228cdf0e10cSrcweir                     inspect(oUnoObject, sNodeDescription);
229cdf0e10cSrcweir                 }
230cdf0e10cSrcweir             }
231cdf0e10cSrcweir         }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         public void addSourceCodeOfSelectedNode(){
235cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
236cdf0e10cSrcweir             if (oInspectorPane != null){
237cdf0e10cSrcweir                 oInspectorPane.addSourceCodeOfSelectedNode();
238cdf0e10cSrcweir             }
239cdf0e10cSrcweir         }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         public void invokeSelectedMethod(){
243cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
244cdf0e10cSrcweir             if (oInspectorPane != null){
245cdf0e10cSrcweir                 oInspectorPane.invokeSelectedMethodNode();
246cdf0e10cSrcweir             }
247cdf0e10cSrcweir         }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         public void setSourceCodeLanguage(final int _nLanguage){
251cdf0e10cSrcweir         try{
252cdf0e10cSrcweir             String sLanguage = "Java";
253cdf0e10cSrcweir             XNameAccess xNameAccess  = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
254cdf0e10cSrcweir             XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
255cdf0e10cSrcweir             switch (_nLanguage){
256cdf0e10cSrcweir                 case XLanguageSourceCodeGenerator.nJAVA:
257cdf0e10cSrcweir                     sLanguage = "Java";
258cdf0e10cSrcweir                     break;
259cdf0e10cSrcweir                 case XLanguageSourceCodeGenerator.nCPLUSPLUS:
260cdf0e10cSrcweir                     sLanguage = "CPlusPlus";
261cdf0e10cSrcweir                     break;
262cdf0e10cSrcweir                 case XLanguageSourceCodeGenerator.nBASIC:
263cdf0e10cSrcweir                     sLanguage = "Basic";
264cdf0e10cSrcweir                     break;
265cdf0e10cSrcweir                 default:
266cdf0e10cSrcweir                     System.out.println("Warning: Sourcecode language is not defined!");
267cdf0e10cSrcweir             }
268cdf0e10cSrcweir             xPropertySet.setPropertyValue("Language", sLanguage);
269cdf0e10cSrcweir             XChangesBatch xBatch = (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
270cdf0e10cSrcweir             xBatch.commitChanges();
271cdf0e10cSrcweir             for (int i = 0; i < m_oSwingDialogProvider.getInspectorPageCount(); i++){
272cdf0e10cSrcweir                 m_oSwingDialogProvider.getInspectorPage(i).convertCompleteSourceCode(_nLanguage);
273cdf0e10cSrcweir             }
274cdf0e10cSrcweir         }catch( Exception exception ) {
275cdf0e10cSrcweir             exception.printStackTrace(System.out);
276cdf0e10cSrcweir         }}
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         private TDocSupplier getTDocSupplier(){
280cdf0e10cSrcweir             if (oTDocSupplier == null){
281cdf0e10cSrcweir                 oTDocSupplier = new TDocSupplier(m_xComponentContext);
282cdf0e10cSrcweir             }
283cdf0e10cSrcweir             return oTDocSupplier;
284cdf0e10cSrcweir         }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         public String[] getTDocUrls(){
287cdf0e10cSrcweir             return getTDocSupplier().getTDocUrls();
288cdf0e10cSrcweir         }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
291cdf0e10cSrcweir         public String[] getTDocTitles(String[] _sTDocUrls){
292cdf0e10cSrcweir             return getTDocSupplier().getTDocTitles(_sTDocUrls);
293cdf0e10cSrcweir         }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         public String[][] getApplicationUrls(){
297cdf0e10cSrcweir             Set aSet = aApplicationHashMap.keySet();
298cdf0e10cSrcweir             String[][] sReturnList = new String[aSet.size()][];
299cdf0e10cSrcweir             int n= 0;
300cdf0e10cSrcweir             for ( Iterator i = aSet.iterator(); i.hasNext(); ){
301cdf0e10cSrcweir                 String[] sSingleApplication = new String[2];
302cdf0e10cSrcweir                 sSingleApplication[0] = (String) i.next();
303cdf0e10cSrcweir                 // assign the title in the second index
304cdf0e10cSrcweir                 sSingleApplication[1] = (String) aApplicationHashMap.get(sSingleApplication[0]);
305cdf0e10cSrcweir                 sReturnList[n++] = sSingleApplication;
306cdf0e10cSrcweir             }
307cdf0e10cSrcweir             return sReturnList;
308cdf0e10cSrcweir         }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 
311cdf0e10cSrcweir         public void disposeHiddenDocuments(){
312cdf0e10cSrcweir             int nHiddenCount = aHiddenDocuments.size();
313cdf0e10cSrcweir             if (nHiddenCount > 0){
314cdf0e10cSrcweir                 for (int i = nHiddenCount - 1; i >= 0; i--){
315cdf0e10cSrcweir                     XComponent xComponent = (XComponent) aHiddenDocuments.get(i);
316cdf0e10cSrcweir                     if (xComponent != null){
317cdf0e10cSrcweir                         try {
318cdf0e10cSrcweir                             XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xComponent);
319cdf0e10cSrcweir                             xCloseable.close(true);
320cdf0e10cSrcweir                             aHiddenDocuments.remove(i);
321cdf0e10cSrcweir                         } catch (CloseVetoException ex) {
322cdf0e10cSrcweir                             ex.printStackTrace();
323cdf0e10cSrcweir                         }
324cdf0e10cSrcweir                     }
325cdf0e10cSrcweir                 }
326cdf0e10cSrcweir             }
327cdf0e10cSrcweir         }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 
330cdf0e10cSrcweir         public static String[] getServiceNames() {
331cdf0e10cSrcweir             String[] sSupportedServiceNames = { __serviceName };
332cdf0e10cSrcweir             return sSupportedServiceNames;
333cdf0e10cSrcweir         }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir         // Implement the interface XServiceInfo
336cdf0e10cSrcweir         /** Get all supported service names.
337cdf0e10cSrcweir          * @return Supported service names.
338cdf0e10cSrcweir          */
339cdf0e10cSrcweir         public String[] getSupportedServiceNames() {
340cdf0e10cSrcweir             return getServiceNames();
341cdf0e10cSrcweir         }
342cdf0e10cSrcweir 
343cdf0e10cSrcweir         // Implement the interface XServiceInfo
344cdf0e10cSrcweir         /** Test, if the given service will be supported.
345cdf0e10cSrcweir          * @param sService Service name.
346cdf0e10cSrcweir          * @return Return true, if the service will be supported.
347cdf0e10cSrcweir          */
348cdf0e10cSrcweir         public boolean supportsService( String sServiceName ) {
349cdf0e10cSrcweir             return sServiceName.equals( __serviceName );
350cdf0e10cSrcweir         }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         // Implement the interface XServiceInfo
353cdf0e10cSrcweir         /** Get the implementation name of the component.
354cdf0e10cSrcweir          * @return Implementation name of the component.
355cdf0e10cSrcweir          */
356cdf0e10cSrcweir         public String getImplementationName() {
357cdf0e10cSrcweir             return _Inspector.class.getName();
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 
361cdf0e10cSrcweir         private int getSourceCodeLanguage(){
362cdf0e10cSrcweir         int nLanguage = XLanguageSourceCodeGenerator.nJAVA;
363cdf0e10cSrcweir         try{
364cdf0e10cSrcweir             XNameAccess xNameAccess  = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", false);
365cdf0e10cSrcweir             String sLanguage = (String) xNameAccess.getByName("Language");
366cdf0e10cSrcweir             if (sLanguage.toUpperCase().equals("JAVA")){
367cdf0e10cSrcweir                 nLanguage = XLanguageSourceCodeGenerator.nJAVA;
368cdf0e10cSrcweir             }
369cdf0e10cSrcweir             else if (sLanguage.toUpperCase().equals("BASIC")){
370cdf0e10cSrcweir                 nLanguage = XLanguageSourceCodeGenerator.nBASIC;
371cdf0e10cSrcweir             }
372cdf0e10cSrcweir             else if (sLanguage.toUpperCase().equals("CPLUSPLUS")){
373cdf0e10cSrcweir                 nLanguage = XLanguageSourceCodeGenerator.nCPLUSPLUS;
374cdf0e10cSrcweir             }
375cdf0e10cSrcweir             else{
376cdf0e10cSrcweir                 System.out.println("Warning: Sourcecode language " + sLanguage + " is not defined!");
377cdf0e10cSrcweir             }
378cdf0e10cSrcweir             m_oSwingDialogProvider.selectSourceCodeLanguage(nLanguage);
379cdf0e10cSrcweir         }catch( Exception exception ) {
380cdf0e10cSrcweir             exception.printStackTrace(System.out);
381cdf0e10cSrcweir         }
382cdf0e10cSrcweir             return nLanguage;
383cdf0e10cSrcweir         }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 
386cdf0e10cSrcweir         public XNameAccess getConfigurationAccess(boolean _bUpdate){
387cdf0e10cSrcweir             return getConfigurationAccess("org.openoffice.inspector.ObjectInspector", _bUpdate);
388cdf0e10cSrcweir         }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 
391cdf0e10cSrcweir         public XNameAccess getConfigurationAccess(String _sNodePath, boolean update) {
392cdf0e10cSrcweir         XNameAccess xNameAccess = null;
393cdf0e10cSrcweir         try {
394cdf0e10cSrcweir             String sAccess = "";
395cdf0e10cSrcweir             if (update) {
396cdf0e10cSrcweir                 sAccess = "com.sun.star.configuration.ConfigurationUpdateAccess";
397cdf0e10cSrcweir             }
398cdf0e10cSrcweir             else{
399cdf0e10cSrcweir                 sAccess = "com.sun.star.configuration.ConfigurationAccess";
400cdf0e10cSrcweir             }
401cdf0e10cSrcweir             XMultiComponentFactory xMCF = m_xComponentContext.getServiceManager();
402cdf0e10cSrcweir             Object oDefaultProvider = xMCF.createInstanceWithContext("com.sun.star.configuration.DefaultProvider", this.getXComponentContext());
403cdf0e10cSrcweir             XMultiServiceFactory xMSFCfg = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDefaultProvider);
404cdf0e10cSrcweir             Object oAccess = xMSFCfg.createInstanceWithArguments(sAccess, new Object[]{new NamedValue("nodepath", _sNodePath)});
405cdf0e10cSrcweir             xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oAccess);
406cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
407cdf0e10cSrcweir         }
408cdf0e10cSrcweir         return xNameAccess;
409cdf0e10cSrcweir         }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir // end of inner class
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     /**
418cdf0e10cSrcweir      * Gives a factory for creating the service.
419cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
420cdf0e10cSrcweir      * <p>
421cdf0e10cSrcweir      * @return  returns a <code>XSingleComponentFactory</code> for creating
422cdf0e10cSrcweir      *          the component
423cdf0e10cSrcweir      * @param   sImplName the name of the implementation for which a
424cdf0e10cSrcweir      *          service is desired
425cdf0e10cSrcweir      * @see     com.sun.star.comp.loader.JavaLoader
426cdf0e10cSrcweir      */
427cdf0e10cSrcweir     public static XSingleComponentFactory __getComponentFactory( String sImplName )
428cdf0e10cSrcweir     {
429cdf0e10cSrcweir         XSingleComponentFactory xFactory = null;
430cdf0e10cSrcweir         if ( sImplName.equals( _Inspector.class.getName() ) )
431cdf0e10cSrcweir             xFactory = Factory.createComponentFactory(_Inspector.class, _Inspector.getServiceNames());
432cdf0e10cSrcweir         if ( xFactory == null )
433cdf0e10cSrcweir             xFactory = InspectorAddon.__getComponentFactory(sImplName);
434cdf0e10cSrcweir         return xFactory;
435cdf0e10cSrcweir     }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     /**
438cdf0e10cSrcweir      * Writes the service information into the given registry key.
439cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
440cdf0e10cSrcweir      * <p>
441cdf0e10cSrcweir      * @return  returns true if the operation succeeded
442cdf0e10cSrcweir      * @param   regKey the registryKey
443cdf0e10cSrcweir      * @see     com.sun.star.comp.loader.JavaLoader
444cdf0e10cSrcweir      */
445cdf0e10cSrcweir     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
446cdf0e10cSrcweir         return (Factory.writeRegistryServiceInfo(_Inspector.class.getName(), _Inspector.getServiceNames(), regKey)
447cdf0e10cSrcweir                 && InspectorAddon.__writeRegistryServiceInfo(regKey));
448cdf0e10cSrcweir     }
449cdf0e10cSrcweir }
450cdf0e10cSrcweir 
451