1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: InstCreator.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import util
.XInstCreator
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
38 import com
.sun
.star
.text
.XTextTablesSupplier
;
39 import com
.sun
.star
.text
.XTextFramesSupplier
;
40 import com
.sun
.star
.text
.XTextSectionsSupplier
;
41 import com
.sun
.star
.text
.XFootnotesSupplier
;
42 import com
.sun
.star
.text
.XBookmarksSupplier
;
43 import com
.sun
.star
.container
.XNameAccess
;
44 import com
.sun
.star
.container
.XIndexAccess
;
47 public class InstCreator
implements XInstCreator
{
49 XMultiServiceFactory xMSF
;
54 public InstCreator( XInterface xParent
, InstDescr iDsc
) {
55 this.xParent
= xParent
;
58 xMSF
= (XMultiServiceFactory
)UnoRuntime
.queryInterface(
59 XMultiServiceFactory
.class, xParent
);
61 xInstance
= createInstance();
62 xIA
= createCollection();
64 public XInterface
getInstance() {
68 public XInterface
createInstance() {
69 XInterface xIfc
= null;
72 xIfc
= iDsc
.createInstance( xMSF
);
77 public XIndexAccess
getCollection() {
81 private XIndexAccess
createCollection() {
82 XNameAccess oNA
= null;
84 if ( iDsc
instanceof TableDsc
) {
85 XTextTablesSupplier oTTS
= (XTextTablesSupplier
)
86 UnoRuntime
.queryInterface(
87 XTextTablesSupplier
.class, xParent
);
89 oNA
= oTTS
.getTextTables();
91 if ( iDsc
instanceof FrameDsc
) {
92 XTextFramesSupplier oTTS
= (XTextFramesSupplier
)
93 UnoRuntime
.queryInterface(
94 XTextFramesSupplier
.class, xParent
);
96 oNA
= oTTS
.getTextFrames();
98 if ( iDsc
instanceof BookmarkDsc
) {
99 XBookmarksSupplier oTTS
= (XBookmarksSupplier
)
100 UnoRuntime
.queryInterface(
101 XBookmarksSupplier
.class, xParent
);
103 oNA
= oTTS
.getBookmarks();
106 if ( iDsc
instanceof FootnoteDsc
) {
107 XFootnotesSupplier oTTS
= (XFootnotesSupplier
)
108 UnoRuntime
.queryInterface(
109 XFootnotesSupplier
.class, xParent
);
111 return( oTTS
.getFootnotes() );
114 if ( iDsc
instanceof TextSectionDsc
) {
115 XTextSectionsSupplier oTSS
= (XTextSectionsSupplier
)
116 UnoRuntime
.queryInterface(
117 XTextSectionsSupplier
.class, xParent
);
119 oNA
= oTSS
.getTextSections();
122 return (XIndexAccess
)UnoRuntime
.queryInterface(
123 XIndexAccess
.class, oNA
);