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 com.sun.star.comp.beans; 29 30 import com.sun.star.uno.UnoRuntime; 31 32 //========================================================================== 33 /** Wrapper base class for UNO services which emulates the upcoming 34 mode of automatic runtime Java classes to get rid of the need for 35 queryInterface. 36 37 Because its not worth the efford to create a runtime generated wrapper 38 for this purpose, as it might be for OOo 2.0, you still have to use 39 UnoRuntime.queryInterface() for interfaces which are optional or come 40 from a subclass. But for non optional interfaces you can already 41 directly call their methods. 42 43 This wrapper will only work for UNO objects via a bridge, not for 44 direct Java objects. 45 46 @since OOo 2.0.0 47 */ 48 class Wrapper 49 implements 50 com.sun.star.lib.uno.Proxy, 51 // see the comment in com.sun.star.lib.uno.bridges.java_remote 52 // .java_remote_bridge.mapInterfaceTo for the consequences of this 53 // hack 54 com.sun.star.uno.IQueryInterface, 55 com.sun.star.lang.XComponent 56 { 57 private com.sun.star.uno.IQueryInterface xQueryInterface; 58 private com.sun.star.lang.XComponent xComponent; 59 60 public Wrapper( com.sun.star.uno.XInterface xProxy ) 61 { 62 xQueryInterface = (com.sun.star.uno.IQueryInterface) xProxy; 63 xComponent = (com.sun.star.lang.XComponent) 64 UnoRuntime.queryInterface( 65 com.sun.star.lang.XComponent.class, xProxy ); 66 } 67 68 //============================================================== 69 // com.sun.star.uno.IQueryInterface 70 //-------------------------------------------------------------- 71 72 public String getOid() 73 { 74 return xQueryInterface.getOid(); 75 } 76 77 public boolean isSame( Object aObject ) 78 { 79 return xQueryInterface.isSame( aObject ); 80 } 81 82 public Object queryInterface( com.sun.star.uno.Type aType ) 83 { 84 //System.err.println( "Wrapper::queryInterface(" + aType + ")" ); 85 return xQueryInterface.queryInterface( aType ); 86 } 87 88 //============================================================== 89 // com.sun.star.lang.XComponent 90 //-------------------------------------------------------------- 91 92 public void dispose( ) 93 { 94 xComponent.dispose(); 95 } 96 97 public void addEventListener( /*IN*/ com.sun.star.lang.XEventListener xListener ) 98 { 99 xComponent.addEventListener( xListener ); 100 } 101 102 public void removeEventListener( /*IN*/ com.sun.star.lang.XEventListener xListener ) 103 { 104 xComponent.removeEventListener( xListener ); 105 } 106 }; 107 108 109