134dd1e25SAndrew Rist /**************************************************************
234dd1e25SAndrew Rist  *
334dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
434dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
534dd1e25SAndrew Rist  * distributed with this work for additional information
634dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
734dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
834dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
934dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
1034dd1e25SAndrew Rist  *
1134dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1234dd1e25SAndrew Rist  *
1334dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1434dd1e25SAndrew Rist  * software distributed under the License is distributed on an
1534dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1634dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
1734dd1e25SAndrew Rist  * specific language governing permissions and limitations
1834dd1e25SAndrew Rist  * under the License.
1934dd1e25SAndrew Rist  *
2034dd1e25SAndrew Rist  *************************************************************/
2134dd1e25SAndrew Rist 
2234dd1e25SAndrew 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 */
_Inspector(XComponentContext _xComponentContext)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 
getXComponentContext()94cdf0e10cSrcweir         public XComponentContext getXComponentContext(){
95cdf0e10cSrcweir             return m_xComponentContext;
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
getInspectorPages()99cdf0e10cSrcweir         public HashMap getInspectorPages(){
100cdf0e10cSrcweir             return aInspectorPanes;
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 
getSDKPath()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 
getIDLPath()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 
openIdlFileforSelectedNode()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 
assignSDKPath()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 
showErrorMessageBox(XWindowPeer _xWindowPeer, String _sTitle, String _sMessage)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);
181*5bf47815SAriel Constenla-Haile             XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(_xWindowPeer, com.sun.star.awt.MessageBoxType.ERRORBOX, com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, _sTitle, _sMessage);
182cdf0e10cSrcweir             XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox);
183cdf0e10cSrcweir             if (xMessageBox != null){
184cdf0e10cSrcweir                 short nResult = xMessageBox.execute();
185cdf0e10cSrcweir                 xComponent.dispose();
186cdf0e10cSrcweir             }
187cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception ex) {
188cdf0e10cSrcweir             ex.printStackTrace(System.out);
189cdf0e10cSrcweir         }}
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 
inspect(java.lang.Object _oUserDefinedObject, String _sTitle)192cdf0e10cSrcweir         public void inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
193cdf0e10cSrcweir         try {
194cdf0e10cSrcweir             int nPageIndex = m_oSwingDialogProvider.getInspectorPageCount();
195cdf0e10cSrcweir             SwingTreeControlProvider oSwingTreeControlProvider = new SwingTreeControlProvider(m_oSwingDialogProvider);
196cdf0e10cSrcweir             InspectorPane oInspectorPane = new InspectorPane(getXComponentContext(), m_oSwingDialogProvider, oSwingTreeControlProvider, getSourceCodeLanguage());
197cdf0e10cSrcweir             oInspectorPane.inspect(_oUserDefinedObject, _sTitle);
198cdf0e10cSrcweir             getInspectorPages().put(_sTitle, oInspectorPane);
199cdf0e10cSrcweir             m_oSwingDialogProvider.show(nPageIndex);
200cdf0e10cSrcweir         }catch( Exception exception ) {
201cdf0e10cSrcweir             exception.printStackTrace(System.out);
202cdf0e10cSrcweir         }}
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 
inspectOpenEmptyDocument(String _sApplicationDocUrl)205cdf0e10cSrcweir         public void inspectOpenEmptyDocument(String _sApplicationDocUrl){
206cdf0e10cSrcweir             XComponent xComponent = getTDocSupplier().openEmptyDocument(_sApplicationDocUrl);
207cdf0e10cSrcweir             String sRootTitle = (String) aApplicationHashMap.get(_sApplicationDocUrl);
208cdf0e10cSrcweir             inspect(xComponent, sRootTitle);
209cdf0e10cSrcweir             aHiddenDocuments.add(xComponent);
210cdf0e10cSrcweir         }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 
inspectOpenDocument(String _sTDocUrl)213cdf0e10cSrcweir         public void inspectOpenDocument(String _sTDocUrl){
214cdf0e10cSrcweir             String sTreeNodeName = getTDocSupplier().getTitleByTDocUrl(_sTDocUrl);
215cdf0e10cSrcweir             XModel xTDocModel = getTDocSupplier().getXModelByTDocUrl(_sTDocUrl);
216cdf0e10cSrcweir             inspect(xTDocModel, sTreeNodeName);
217cdf0e10cSrcweir         }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 
inspectSelectedNode()220cdf0e10cSrcweir         public void inspectSelectedNode(){
221cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
222cdf0e10cSrcweir             if (oInspectorPane != null){
223cdf0e10cSrcweir                 XUnoNode oUnoNode = oInspectorPane.getSelectedNode();
224cdf0e10cSrcweir                 Object oUnoObject = oUnoNode.getUnoObject();
225cdf0e10cSrcweir                 if (oUnoObject != null){
226cdf0e10cSrcweir                     String sNodeDescription = UnoNode.getNodeDescription(oUnoObject);
227cdf0e10cSrcweir                     inspect(oUnoObject, sNodeDescription);
228cdf0e10cSrcweir                 }
229cdf0e10cSrcweir             }
230cdf0e10cSrcweir         }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 
addSourceCodeOfSelectedNode()233cdf0e10cSrcweir         public void addSourceCodeOfSelectedNode(){
234cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
235cdf0e10cSrcweir             if (oInspectorPane != null){
236cdf0e10cSrcweir                 oInspectorPane.addSourceCodeOfSelectedNode();
237cdf0e10cSrcweir             }
238cdf0e10cSrcweir         }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 
invokeSelectedMethod()241cdf0e10cSrcweir         public void invokeSelectedMethod(){
242cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
243cdf0e10cSrcweir             if (oInspectorPane != null){
244cdf0e10cSrcweir                 oInspectorPane.invokeSelectedMethodNode();
245cdf0e10cSrcweir             }
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 
setSourceCodeLanguage(final int _nLanguage)249cdf0e10cSrcweir         public void setSourceCodeLanguage(final int _nLanguage){
250cdf0e10cSrcweir         try{
251cdf0e10cSrcweir             String sLanguage = "Java";
252cdf0e10cSrcweir             XNameAccess xNameAccess  = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
253cdf0e10cSrcweir             XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
254cdf0e10cSrcweir             switch (_nLanguage){
255cdf0e10cSrcweir                 case XLanguageSourceCodeGenerator.nJAVA:
256cdf0e10cSrcweir                     sLanguage = "Java";
257cdf0e10cSrcweir                     break;
258cdf0e10cSrcweir                 case XLanguageSourceCodeGenerator.nCPLUSPLUS:
259cdf0e10cSrcweir                     sLanguage = "CPlusPlus";
260cdf0e10cSrcweir                     break;
261cdf0e10cSrcweir                 case XLanguageSourceCodeGenerator.nBASIC:
262cdf0e10cSrcweir                     sLanguage = "Basic";
263cdf0e10cSrcweir                     break;
264cdf0e10cSrcweir                 default:
265cdf0e10cSrcweir                     System.out.println("Warning: Sourcecode language is not defined!");
266cdf0e10cSrcweir             }
267cdf0e10cSrcweir             xPropertySet.setPropertyValue("Language", sLanguage);
268cdf0e10cSrcweir             XChangesBatch xBatch = (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
269cdf0e10cSrcweir             xBatch.commitChanges();
270cdf0e10cSrcweir             for (int i = 0; i < m_oSwingDialogProvider.getInspectorPageCount(); i++){
271cdf0e10cSrcweir                 m_oSwingDialogProvider.getInspectorPage(i).convertCompleteSourceCode(_nLanguage);
272cdf0e10cSrcweir             }
273cdf0e10cSrcweir         }catch( Exception exception ) {
274cdf0e10cSrcweir             exception.printStackTrace(System.out);
275cdf0e10cSrcweir         }}
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 
getTDocSupplier()278cdf0e10cSrcweir         private TDocSupplier getTDocSupplier(){
279cdf0e10cSrcweir             if (oTDocSupplier == null){
280cdf0e10cSrcweir                 oTDocSupplier = new TDocSupplier(m_xComponentContext);
281cdf0e10cSrcweir             }
282cdf0e10cSrcweir             return oTDocSupplier;
283cdf0e10cSrcweir         }
284cdf0e10cSrcweir 
getTDocUrls()285cdf0e10cSrcweir         public String[] getTDocUrls(){
286cdf0e10cSrcweir             return getTDocSupplier().getTDocUrls();
287cdf0e10cSrcweir         }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 
getTDocTitles(String[] _sTDocUrls)290cdf0e10cSrcweir         public String[] getTDocTitles(String[] _sTDocUrls){
291cdf0e10cSrcweir             return getTDocSupplier().getTDocTitles(_sTDocUrls);
292cdf0e10cSrcweir         }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 
getApplicationUrls()295cdf0e10cSrcweir         public String[][] getApplicationUrls(){
296cdf0e10cSrcweir             Set aSet = aApplicationHashMap.keySet();
297cdf0e10cSrcweir             String[][] sReturnList = new String[aSet.size()][];
298cdf0e10cSrcweir             int n= 0;
299cdf0e10cSrcweir             for ( Iterator i = aSet.iterator(); i.hasNext(); ){
300cdf0e10cSrcweir                 String[] sSingleApplication = new String[2];
301cdf0e10cSrcweir                 sSingleApplication[0] = (String) i.next();
302cdf0e10cSrcweir                 // assign the title in the second index
303cdf0e10cSrcweir                 sSingleApplication[1] = (String) aApplicationHashMap.get(sSingleApplication[0]);
304cdf0e10cSrcweir                 sReturnList[n++] = sSingleApplication;
305cdf0e10cSrcweir             }
306cdf0e10cSrcweir             return sReturnList;
307cdf0e10cSrcweir         }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 
disposeHiddenDocuments()310cdf0e10cSrcweir         public void disposeHiddenDocuments(){
311cdf0e10cSrcweir             int nHiddenCount = aHiddenDocuments.size();
312cdf0e10cSrcweir             if (nHiddenCount > 0){
313cdf0e10cSrcweir                 for (int i = nHiddenCount - 1; i >= 0; i--){
314cdf0e10cSrcweir                     XComponent xComponent = (XComponent) aHiddenDocuments.get(i);
315cdf0e10cSrcweir                     if (xComponent != null){
316cdf0e10cSrcweir                         try {
317cdf0e10cSrcweir                             XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xComponent);
318cdf0e10cSrcweir                             xCloseable.close(true);
319cdf0e10cSrcweir                             aHiddenDocuments.remove(i);
320cdf0e10cSrcweir                         } catch (CloseVetoException ex) {
321cdf0e10cSrcweir                             ex.printStackTrace();
322cdf0e10cSrcweir                         }
323cdf0e10cSrcweir                     }
324cdf0e10cSrcweir                 }
325cdf0e10cSrcweir             }
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 
getServiceNames()329cdf0e10cSrcweir         public static String[] getServiceNames() {
330cdf0e10cSrcweir             String[] sSupportedServiceNames = { __serviceName };
331cdf0e10cSrcweir             return sSupportedServiceNames;
332cdf0e10cSrcweir         }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir         // Implement the interface XServiceInfo
335cdf0e10cSrcweir         /** Get all supported service names.
336cdf0e10cSrcweir          * @return Supported service names.
337cdf0e10cSrcweir          */
getSupportedServiceNames()338cdf0e10cSrcweir         public String[] getSupportedServiceNames() {
339cdf0e10cSrcweir             return getServiceNames();
340cdf0e10cSrcweir         }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir         // Implement the interface XServiceInfo
343cdf0e10cSrcweir         /** Test, if the given service will be supported.
344cdf0e10cSrcweir          * @param sService Service name.
345cdf0e10cSrcweir          * @return Return true, if the service will be supported.
346cdf0e10cSrcweir          */
supportsService( String sServiceName )347cdf0e10cSrcweir         public boolean supportsService( String sServiceName ) {
348cdf0e10cSrcweir             return sServiceName.equals( __serviceName );
349cdf0e10cSrcweir         }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir         // Implement the interface XServiceInfo
352cdf0e10cSrcweir         /** Get the implementation name of the component.
353cdf0e10cSrcweir          * @return Implementation name of the component.
354cdf0e10cSrcweir          */
getImplementationName()355cdf0e10cSrcweir         public String getImplementationName() {
356cdf0e10cSrcweir             return _Inspector.class.getName();
357cdf0e10cSrcweir         }
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 
getSourceCodeLanguage()360cdf0e10cSrcweir         private int getSourceCodeLanguage(){
361cdf0e10cSrcweir         int nLanguage = XLanguageSourceCodeGenerator.nJAVA;
362cdf0e10cSrcweir         try{
363cdf0e10cSrcweir             XNameAccess xNameAccess  = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", false);
364cdf0e10cSrcweir             String sLanguage = (String) xNameAccess.getByName("Language");
365cdf0e10cSrcweir             if (sLanguage.toUpperCase().equals("JAVA")){
366cdf0e10cSrcweir                 nLanguage = XLanguageSourceCodeGenerator.nJAVA;
367cdf0e10cSrcweir             }
368cdf0e10cSrcweir             else if (sLanguage.toUpperCase().equals("BASIC")){
369cdf0e10cSrcweir                 nLanguage = XLanguageSourceCodeGenerator.nBASIC;
370cdf0e10cSrcweir             }
371cdf0e10cSrcweir             else if (sLanguage.toUpperCase().equals("CPLUSPLUS")){
372cdf0e10cSrcweir                 nLanguage = XLanguageSourceCodeGenerator.nCPLUSPLUS;
373cdf0e10cSrcweir             }
374cdf0e10cSrcweir             else{
375cdf0e10cSrcweir                 System.out.println("Warning: Sourcecode language " + sLanguage + " is not defined!");
376cdf0e10cSrcweir             }
377cdf0e10cSrcweir             m_oSwingDialogProvider.selectSourceCodeLanguage(nLanguage);
378cdf0e10cSrcweir         }catch( Exception exception ) {
379cdf0e10cSrcweir             exception.printStackTrace(System.out);
380cdf0e10cSrcweir         }
381cdf0e10cSrcweir             return nLanguage;
382cdf0e10cSrcweir         }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 
getConfigurationAccess(boolean _bUpdate)385cdf0e10cSrcweir         public XNameAccess getConfigurationAccess(boolean _bUpdate){
386cdf0e10cSrcweir             return getConfigurationAccess("org.openoffice.inspector.ObjectInspector", _bUpdate);
387cdf0e10cSrcweir         }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 
getConfigurationAccess(String _sNodePath, boolean update)390cdf0e10cSrcweir         public XNameAccess getConfigurationAccess(String _sNodePath, boolean update) {
391cdf0e10cSrcweir         XNameAccess xNameAccess = null;
392cdf0e10cSrcweir         try {
393cdf0e10cSrcweir             String sAccess = "";
394cdf0e10cSrcweir             if (update) {
395cdf0e10cSrcweir                 sAccess = "com.sun.star.configuration.ConfigurationUpdateAccess";
396cdf0e10cSrcweir             }
397cdf0e10cSrcweir             else{
398cdf0e10cSrcweir                 sAccess = "com.sun.star.configuration.ConfigurationAccess";
399cdf0e10cSrcweir             }
400cdf0e10cSrcweir             XMultiComponentFactory xMCF = m_xComponentContext.getServiceManager();
401cdf0e10cSrcweir             Object oDefaultProvider = xMCF.createInstanceWithContext("com.sun.star.configuration.DefaultProvider", this.getXComponentContext());
402cdf0e10cSrcweir             XMultiServiceFactory xMSFCfg = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDefaultProvider);
403cdf0e10cSrcweir             Object oAccess = xMSFCfg.createInstanceWithArguments(sAccess, new Object[]{new NamedValue("nodepath", _sNodePath)});
404cdf0e10cSrcweir             xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oAccess);
405cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
406cdf0e10cSrcweir         }
407cdf0e10cSrcweir         return xNameAccess;
408cdf0e10cSrcweir         }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 
411cdf0e10cSrcweir     }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir // end of inner class
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     /**
417cdf0e10cSrcweir      * Gives a factory for creating the service.
418cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
419cdf0e10cSrcweir      * <p>
420cdf0e10cSrcweir      * @return  returns a <code>XSingleComponentFactory</code> for creating
421cdf0e10cSrcweir      *          the component
422cdf0e10cSrcweir      * @param   sImplName the name of the implementation for which a
423cdf0e10cSrcweir      *          service is desired
424cdf0e10cSrcweir      * @see     com.sun.star.comp.loader.JavaLoader
425cdf0e10cSrcweir      */
__getComponentFactory( String sImplName )426cdf0e10cSrcweir     public static XSingleComponentFactory __getComponentFactory( String sImplName )
427cdf0e10cSrcweir     {
428cdf0e10cSrcweir         XSingleComponentFactory xFactory = null;
429cdf0e10cSrcweir         if ( sImplName.equals( _Inspector.class.getName() ) )
430cdf0e10cSrcweir             xFactory = Factory.createComponentFactory(_Inspector.class, _Inspector.getServiceNames());
431cdf0e10cSrcweir         if ( xFactory == null )
432cdf0e10cSrcweir             xFactory = InspectorAddon.__getComponentFactory(sImplName);
433cdf0e10cSrcweir         return xFactory;
434cdf0e10cSrcweir     }
435cdf0e10cSrcweir 
436cdf0e10cSrcweir     /**
437cdf0e10cSrcweir      * Writes the service information into the given registry key.
438cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
439cdf0e10cSrcweir      * <p>
440cdf0e10cSrcweir      * @return  returns true if the operation succeeded
441cdf0e10cSrcweir      * @param   regKey the registryKey
442cdf0e10cSrcweir      * @see     com.sun.star.comp.loader.JavaLoader
443cdf0e10cSrcweir      */
__writeRegistryServiceInfo(XRegistryKey regKey)444cdf0e10cSrcweir     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
445cdf0e10cSrcweir         return (Factory.writeRegistryServiceInfo(_Inspector.class.getName(), _Inspector.getServiceNames(), regKey)
446cdf0e10cSrcweir                 && InspectorAddon.__writeRegistryServiceInfo(regKey));
447cdf0e10cSrcweir     }
448cdf0e10cSrcweir }
449cdf0e10cSrcweir 
450