xref: /AOO41X/main/qadevOOo/runner/util/InstCreator.java (revision ef39d40d3f5e66cf3f035b3e93783012b340500d)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package util;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import util.XInstCreator;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30cdf0e10cSrcweir import com.sun.star.uno.XInterface;
31cdf0e10cSrcweir import com.sun.star.text.XTextTablesSupplier;
32cdf0e10cSrcweir import com.sun.star.text.XTextFramesSupplier;
33cdf0e10cSrcweir import com.sun.star.text.XTextSectionsSupplier;
34cdf0e10cSrcweir import com.sun.star.text.XFootnotesSupplier;
35cdf0e10cSrcweir import com.sun.star.text.XBookmarksSupplier;
36cdf0e10cSrcweir import com.sun.star.container.XNameAccess;
37cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir public class InstCreator implements XInstCreator {
41cdf0e10cSrcweir 	XInterface xParent;
42cdf0e10cSrcweir 	XMultiServiceFactory xMSF;
43cdf0e10cSrcweir 	XInterface xInstance;
44cdf0e10cSrcweir 	XIndexAccess xIA;
45cdf0e10cSrcweir 	InstDescr iDsc;
46cdf0e10cSrcweir 
InstCreator( XInterface xParent, InstDescr iDsc )47cdf0e10cSrcweir 	public InstCreator( XInterface xParent, InstDescr iDsc ) {
48cdf0e10cSrcweir 		this.xParent = xParent;
49cdf0e10cSrcweir 		this.iDsc = iDsc;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 		xMSF = (XMultiServiceFactory)UnoRuntime.queryInterface(
52cdf0e10cSrcweir 									XMultiServiceFactory.class, xParent );
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 		xInstance = createInstance();
55cdf0e10cSrcweir 		xIA = createCollection();
56cdf0e10cSrcweir 	}
getInstance()57cdf0e10cSrcweir 	public XInterface getInstance() {
58cdf0e10cSrcweir 		return xInstance;
59cdf0e10cSrcweir 	}
60cdf0e10cSrcweir 
createInstance()61cdf0e10cSrcweir 	public XInterface createInstance() {
62cdf0e10cSrcweir 		XInterface xIfc = null;
63cdf0e10cSrcweir 		Object xObj = null;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 		xIfc = iDsc.createInstance( xMSF );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 		return xIfc;
68cdf0e10cSrcweir 	}
69cdf0e10cSrcweir 
getCollection()70cdf0e10cSrcweir 	public XIndexAccess getCollection() {
71cdf0e10cSrcweir 		return xIA;
72cdf0e10cSrcweir 	}
73cdf0e10cSrcweir 
createCollection()74cdf0e10cSrcweir 	private XIndexAccess createCollection() {
75cdf0e10cSrcweir 		XNameAccess oNA = null;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 		if ( iDsc instanceof TableDsc ) {
78cdf0e10cSrcweir 			XTextTablesSupplier oTTS = (XTextTablesSupplier)
79cdf0e10cSrcweir 					UnoRuntime.queryInterface(
80cdf0e10cSrcweir 										XTextTablesSupplier.class, xParent );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 			oNA = oTTS.getTextTables();
83cdf0e10cSrcweir 		}
84cdf0e10cSrcweir 		if ( iDsc instanceof FrameDsc ) {
85cdf0e10cSrcweir 			XTextFramesSupplier oTTS = (XTextFramesSupplier)
86cdf0e10cSrcweir 					UnoRuntime.queryInterface(
87cdf0e10cSrcweir 										XTextFramesSupplier.class, xParent );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 			oNA = oTTS.getTextFrames();
90cdf0e10cSrcweir 		}
91cdf0e10cSrcweir 		if ( iDsc instanceof BookmarkDsc ) {
92cdf0e10cSrcweir 			XBookmarksSupplier oTTS = (XBookmarksSupplier)
93cdf0e10cSrcweir 					UnoRuntime.queryInterface(
94cdf0e10cSrcweir 										XBookmarksSupplier.class, xParent );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 			oNA = oTTS.getBookmarks();
97cdf0e10cSrcweir 		}
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 		if ( iDsc instanceof FootnoteDsc ) {
100cdf0e10cSrcweir 			XFootnotesSupplier oTTS = (XFootnotesSupplier)
101cdf0e10cSrcweir 					UnoRuntime.queryInterface(
102cdf0e10cSrcweir 										XFootnotesSupplier.class, xParent );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 			return( oTTS.getFootnotes() );
105cdf0e10cSrcweir 		}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		if ( iDsc instanceof TextSectionDsc ) {
108cdf0e10cSrcweir 			XTextSectionsSupplier oTSS = (XTextSectionsSupplier)
109cdf0e10cSrcweir 					UnoRuntime.queryInterface(
110cdf0e10cSrcweir 										XTextSectionsSupplier.class, xParent );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 			oNA = oTSS.getTextSections();
113cdf0e10cSrcweir 		}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		return (XIndexAccess)UnoRuntime.queryInterface(
116cdf0e10cSrcweir 													XIndexAccess.class, oNA);
117cdf0e10cSrcweir 	}
118cdf0e10cSrcweir }