1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ProxyProvider.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.lib
.uno
.helper
;
32 import com
.sun
.star
.uno
.Type
;
33 import com
.sun
.star
.lib
.uno
.typedesc
.TypeDescription
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.lang
.XEventListener
;
36 import com
.sun
.star
.uno
.IQueryInterface
;
37 //import com.sun.star.lib.uno.environments.java.Proxy;
38 import com
.sun
.star
.lib
.uno
.environments
.java
.java_environment
;
39 //import com.sun.star.lib.uno.environments.java.IRequester;
42 public class ProxyProvider
44 static java_environment env
= new java_environment(null);
46 /** Creates a new instance of ProxyProvider */
47 public ProxyProvider()
50 /** returns Holder proxy objects for the specified interface. If the method is called
51 * several times with the same arguments then each time a new HolderProxy is returned.
52 * Then all HolderProxy s refer to the same Proxy object.
53 * The proxy can be queried for XEventListener. On the returned proxy disposing can be called
56 public static Object
createProxy(Object obj
, Class iface
)
60 if (obj
== null || iface
== null || iface
.isInstance(obj
) == false )
63 Type type
= new Type(TypeDescription
.getTypeDescription(iface
));
64 Type evtType
= new Type(TypeDescription
.getTypeDescription(com
.sun
.star
.lang
.XEventListener
.class));
65 // find the object identifier
66 String sOid
= UnoRuntime
.generateOid(obj
);
67 retVal
= env
.getRegisteredInterface(sOid
, type
);
68 // if retVal == null then probably not registered
71 Object aProxy
= new Proxy(sOid
, type
);
72 String
[] arOid
= new String
[]
74 retVal
= env
.registerInterface(aProxy
, arOid
, type
);
80 class Proxy
implements IQueryInterface
, XEventListener
84 Proxy(String oid
, Type t
) {
89 public String
getOid() {
93 public boolean isSame(Object object
) {
94 if (object
instanceof IQueryInterface
)
96 IQueryInterface iquery
= (IQueryInterface
) object
;
99 if (iquery
.getOid().equals(oid
))
106 String oidObj
= UnoRuntime
.generateOid(object
);
107 if (oidObj
.equals(oid
))
113 public Object
queryInterface(Type type
) {
117 public void disposing(com
.sun
.star
.lang
.EventObject eventObject
) {
123 //class Requester //implements IRequester
127 // boolean _forceSynchronous;
128 // boolean _passed = true;
130 // Object _xEventListenerProxy;
131 // int nDisposingCalled= 0;
133 // Requester(boolean virtual, boolean forceSynchronous, Object evtListener)
135 // _virtual = virtual;
136 // _forceSynchronous = forceSynchronous;
137 // _xEventListenerProxy= evtListener;
141 // public Object sendRequest(Object object,
145 // Boolean synchron[],
146 // Boolean mustReply[]) throws Throwable
149 // Object result = null;
150 // if (operation.equals("disposing"))
152 // System.out.println("Disposing called on XEventListener proxy");
153 // nDisposingCalled++;
155 // else if (operation.equals("queryInterface"))
157 // if (params[0] instanceof Type)
159 // Type t= (Type) params[0];
160 // if (t.equals( new Type("com.sun.star.lang.XEventListener")))
161 // result= _xEventListenerProxy;