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