1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 package util;
29 
30 import util.XInstCreator;
31 
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;
42 
43 
44 public class InstCreator implements XInstCreator {
45 	XInterface xParent;
46 	XMultiServiceFactory xMSF;
47 	XInterface xInstance;
48 	XIndexAccess xIA;
49 	InstDescr iDsc;
50 
51 	public InstCreator( XInterface xParent, InstDescr iDsc ) {
52 		this.xParent = xParent;
53 		this.iDsc = iDsc;
54 
55 		xMSF = (XMultiServiceFactory)UnoRuntime.queryInterface(
56 									XMultiServiceFactory.class, xParent );
57 
58 		xInstance = createInstance();
59 		xIA = createCollection();
60 	}
61 	public XInterface getInstance() {
62 		return xInstance;
63 	}
64 
65 	public XInterface createInstance() {
66 		XInterface xIfc = null;
67 		Object xObj = null;
68 
69 		xIfc = iDsc.createInstance( xMSF );
70 
71 		return xIfc;
72 	}
73 
74 	public XIndexAccess getCollection() {
75 		return xIA;
76 	}
77 
78 	private XIndexAccess createCollection() {
79 		XNameAccess oNA = null;
80 
81 		if ( iDsc instanceof TableDsc ) {
82 			XTextTablesSupplier oTTS = (XTextTablesSupplier)
83 					UnoRuntime.queryInterface(
84 										XTextTablesSupplier.class, xParent );
85 
86 			oNA = oTTS.getTextTables();
87 		}
88 		if ( iDsc instanceof FrameDsc ) {
89 			XTextFramesSupplier oTTS = (XTextFramesSupplier)
90 					UnoRuntime.queryInterface(
91 										XTextFramesSupplier.class, xParent );
92 
93 			oNA = oTTS.getTextFrames();
94 		}
95 		if ( iDsc instanceof BookmarkDsc ) {
96 			XBookmarksSupplier oTTS = (XBookmarksSupplier)
97 					UnoRuntime.queryInterface(
98 										XBookmarksSupplier.class, xParent );
99 
100 			oNA = oTTS.getBookmarks();
101 		}
102 
103 		if ( iDsc instanceof FootnoteDsc ) {
104 			XFootnotesSupplier oTTS = (XFootnotesSupplier)
105 					UnoRuntime.queryInterface(
106 										XFootnotesSupplier.class, xParent );
107 
108 			return( oTTS.getFootnotes() );
109 		}
110 
111 		if ( iDsc instanceof TextSectionDsc ) {
112 			XTextSectionsSupplier oTSS = (XTextSectionsSupplier)
113 					UnoRuntime.queryInterface(
114 										XTextSectionsSupplier.class, xParent );
115 
116 			oNA = oTSS.getTextSections();
117 		}
118 
119 		return (XIndexAccess)UnoRuntime.queryInterface(
120 													XIndexAccess.class, oNA);
121 	}
122 }