Debian Codegraph @

javaunohelper/test/com/sun/star/lib/uno/helper/ProxyProvider.java

raw
1 /*
2 * This file is part of the LibreOffice project.
3 *
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/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
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 .
17 */
18
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;
26
27
28 public class ProxyProvider
29 {
30 private static java_environment env= new java_environment(null);
31
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
36 *
37 */
38 public static Object createProxy(Object obj, Class iface)
39 {
40
41 Object retVal= null;
42 if (obj == null || iface == null || !iface.isInstance(obj) )
43 return retVal;
44
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)
52 {
53 Object aProxy = new Proxy(sOid);
54 String[] arOid = new String[]
55 {sOid};
56 retVal= env.registerInterface(aProxy, arOid, type);
57 }
58 return retVal;
59 }
60 }
61
62 class Proxy implements IQueryInterface, XEventListener
63 {
64 private String oid;
65 Proxy(String oid) {
66 this.oid = oid;
67 }
68
69 public String getOid() {
70 return oid;
71 }
72
73 public boolean isSame(Object object) {
74 if (object instanceof IQueryInterface)
75 {
76 IQueryInterface iquery = (IQueryInterface) object;
77 return iquery.getOid().equals(oid);
78 }
79
80 String oidObj = UnoRuntime.generateOid(object);
81 return oidObj.equals(oid);
82 }
83
84 public Object queryInterface(Type type) {
85 return null;
86 }
87
88 public void disposing(com.sun.star.lang.EventObject eventObject) {
89 }
90
91 }
92
93
94
95