Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / runner / util / InstCreator.java
blobb76066d7e95e713a78e562fa3c0850c85e03694a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package util;
30 import util.XInstCreator;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 import com.sun.star.text.XTextTablesSupplier;
36 import com.sun.star.text.XTextFramesSupplier;
37 import com.sun.star.text.XTextSectionsSupplier;
38 import com.sun.star.text.XFootnotesSupplier;
39 import com.sun.star.text.XBookmarksSupplier;
40 import com.sun.star.container.XNameAccess;
41 import com.sun.star.container.XIndexAccess;
44 public class InstCreator implements XInstCreator {
45 XInterface xParent;
46 XMultiServiceFactory xMSF;
47 XInterface xInstance;
48 XIndexAccess xIA;
49 InstDescr iDsc;
51 public InstCreator( XInterface xParent, InstDescr iDsc ) {
52 this.xParent = xParent;
53 this.iDsc = iDsc;
55 xMSF = (XMultiServiceFactory)UnoRuntime.queryInterface(
56 XMultiServiceFactory.class, xParent );
58 xInstance = createInstance();
59 xIA = createCollection();
61 public XInterface getInstance() {
62 return xInstance;
65 public XInterface createInstance() {
66 XInterface xIfc = null;
67 Object xObj = null;
69 xIfc = iDsc.createInstance( xMSF );
71 return xIfc;
74 public XIndexAccess getCollection() {
75 return xIA;
78 private XIndexAccess createCollection() {
79 XNameAccess oNA = null;
81 if ( iDsc instanceof TableDsc ) {
82 XTextTablesSupplier oTTS = (XTextTablesSupplier)
83 UnoRuntime.queryInterface(
84 XTextTablesSupplier.class, xParent );
86 oNA = oTTS.getTextTables();
88 if ( iDsc instanceof FrameDsc ) {
89 XTextFramesSupplier oTTS = (XTextFramesSupplier)
90 UnoRuntime.queryInterface(
91 XTextFramesSupplier.class, xParent );
93 oNA = oTTS.getTextFrames();
95 if ( iDsc instanceof BookmarkDsc ) {
96 XBookmarksSupplier oTTS = (XBookmarksSupplier)
97 UnoRuntime.queryInterface(
98 XBookmarksSupplier.class, xParent );
100 oNA = oTTS.getBookmarks();
103 if ( iDsc instanceof FootnoteDsc ) {
104 XFootnotesSupplier oTTS = (XFootnotesSupplier)
105 UnoRuntime.queryInterface(
106 XFootnotesSupplier.class, xParent );
108 return( oTTS.getFootnotes() );
111 if ( iDsc instanceof TextSectionDsc ) {
112 XTextSectionsSupplier oTSS = (XTextSectionsSupplier)
113 UnoRuntime.queryInterface(
114 XTextSectionsSupplier.class, xParent );
116 oNA = oTSS.getTextSections();
119 return (XIndexAccess)UnoRuntime.queryInterface(
120 XIndexAccess.class, oNA);