merge the formfield patch from ooo-build
[ooovba.git] / javaunohelper / test / com / sun / star / lib / uno / helper / ProxyProvider.java
blob015d43c5246502b4ebe28f1d252094cafa346430
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ProxyProvider.java,v $
10 * $Revision: 1.4 $
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)
59 Object retVal= null;
60 if (obj == null || iface == null || iface.isInstance(obj) == false )
61 return retVal;
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
69 if (retVal == null)
71 Object aProxy = new Proxy(sOid, type);
72 String[] arOid = new String[]
73 {sOid};
74 retVal= env.registerInterface(aProxy, arOid, type);
76 return retVal;
80 class Proxy implements IQueryInterface, XEventListener
82 String oid;
83 Type type;
84 Proxy(String oid, Type t) {
85 this.oid = oid;
86 this.type = t;
89 public String getOid() {
90 return oid;
93 public boolean isSame(Object object) {
94 if (object instanceof IQueryInterface)
96 IQueryInterface iquery = (IQueryInterface) object;
97 if (iquery != null)
99 if (iquery.getOid().equals(oid))
100 return true;
101 else
102 return false;
106 String oidObj = UnoRuntime.generateOid(object);
107 if (oidObj.equals(oid))
108 return true;
109 else
110 return false;
113 public Object queryInterface(Type type) {
114 return null;
117 public void disposing(com.sun.star.lang.EventObject eventObject) {
123 //class Requester //implements IRequester
125 // int _modus;
126 // boolean _virtual;
127 // boolean _forceSynchronous;
128 // boolean _passed = true;
130 // Object _xEventListenerProxy;
131 // int nDisposingCalled= 0;
133 // Requester(boolean virtual, boolean forceSynchronous, Object evtListener)
134 // {
135 // _virtual = virtual;
136 // _forceSynchronous = forceSynchronous;
137 // _xEventListenerProxy= evtListener;
139 // }
141 // public Object sendRequest(Object object,
142 // Type type,
143 // String operation,
144 // Object params[],
145 // Boolean synchron[],
146 // Boolean mustReply[]) throws Throwable
147 // {
149 // Object result = null;
150 // if (operation.equals("disposing"))
151 // {
152 // System.out.println("Disposing called on XEventListener proxy");
153 // nDisposingCalled++;
154 // }
155 // else if (operation.equals("queryInterface"))
156 // {
157 // if (params[0] instanceof Type)
158 // {
159 // Type t= (Type) params[0];
160 // if (t.equals( new Type("com.sun.star.lang.XEventListener")))
161 // result= _xEventListenerProxy;
162 // }
163 // }
164 // return result;
165 // }