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
)
42 if (obj
== null || iface
== null || !iface
.isInstance(obj
) )
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
53 Object aProxy
= new Proxy(sOid
);
54 String
[] arOid
= new String
[]
56 retVal
= env
.registerInterface(aProxy
, arOid
, type
);
62 class Proxy
implements IQueryInterface
, XEventListener
69 public String
getOid() {
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
) {
88 public void disposing(com
.sun
.star
.lang
.EventObject eventObject
) {