tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / javaunohelper / test / com / sun / star / lib / uno / helper / ProxyProvider.java
bloba28794434e9f88b9470f50f3c5ed9ff48eca7d4c
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com.sun.star.lib.uno.helper;
20 import com.sun.star.uno.Type;
21 import com.sun.star.lib.uno.typedesc.TypeDescription;
22 import com.sun.star.uno.UnoRuntime;
23 import com.sun.star.lang.XEventListener;
24 import com.sun.star.uno.IQueryInterface;
25 import com.sun.star.lib.uno.environments.java.java_environment;
28 public class ProxyProvider
30 private static java_environment env= new java_environment(null);
32 /** returns Holder proxy objects for the specified interface. If the method is called
33 * several times with the same arguments then each time a new HolderProxy is returned.
34 * Then all HolderProxy s refer to the same Proxy object.
35 * The proxy can be queried for XEventListener. On the returned proxy disposing can be called
38 public static Object createProxy(Object obj, Class iface)
41 Object retVal= null;
42 if (obj == null || iface == null || !iface.isInstance(obj) )
43 return retVal;
45 Type type= new Type(TypeDescription.getTypeDescription(iface));
46 new Type(TypeDescription.getTypeDescription(com.sun.star.lang.XEventListener.class));
47 // find the object identifier
48 String sOid= UnoRuntime.generateOid(obj);
49 retVal= env.getRegisteredInterface(sOid, type);
50 // if retVal == null then probably not registered
51 if (retVal == null)
53 Object aProxy = new Proxy(sOid);
54 String[] arOid = new String[]
55 {sOid};
56 retVal= env.registerInterface(aProxy, arOid, type);
58 return retVal;
62 class Proxy implements IQueryInterface, XEventListener
64 private String oid;
65 Proxy(String oid) {
66 this.oid = oid;
69 public String getOid() {
70 return oid;
73 public boolean isSame(Object object) {
74 if (object instanceof IQueryInterface)
76 IQueryInterface iquery = (IQueryInterface) object;
77 return iquery.getOid().equals(oid);
80 String oidObj = UnoRuntime.generateOid(object);
81 return oidObj.equals(oid);
84 public Object queryInterface(Type type) {
85 return null;
88 public void disposing(com.sun.star.lang.EventObject eventObject) {