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