1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package com.sun.star.lib.uno.helper; 25 import com.sun.star.uno.Type; 26 import com.sun.star.lib.uno.typedesc.TypeDescription; 27 import com.sun.star.uno.UnoRuntime; 28 import com.sun.star.lang.XEventListener; 29 import com.sun.star.uno.IQueryInterface; 30 //import com.sun.star.lib.uno.environments.java.Proxy; 31 import com.sun.star.lib.uno.environments.java.java_environment; 32 //import com.sun.star.lib.uno.environments.java.IRequester; 33 34 35 public class ProxyProvider 36 { 37 static java_environment env= new java_environment(null); 38 39 /** Creates a new instance of ProxyProvider */ ProxyProvider()40 public ProxyProvider() 41 { 42 } 43 /** returns Holder proxy objects for the specified interface. If the method is called 44 * several times with the same arguments then each time a new HolderProxy is returned. 45 * Then all HolderProxy s refer to the same Proxy object. 46 * The proxy can be queried for XEventListener. On the returned proxy disposing can be called 47 * 48 */ createProxy(Object obj, Class iface)49 public static Object createProxy(Object obj, Class iface) 50 { 51 52 Object retVal= null; 53 if (obj == null || iface == null || iface.isInstance(obj) == false ) 54 return retVal; 55 56 Type type= new Type(TypeDescription.getTypeDescription(iface)); 57 Type evtType= new Type(TypeDescription.getTypeDescription(com.sun.star.lang.XEventListener.class)); 58 // find the object identifier 59 String sOid= UnoRuntime.generateOid(obj); 60 retVal= env.getRegisteredInterface(sOid, type); 61 // if retVal == null then probably not registered 62 if (retVal == null) 63 { 64 Object aProxy = new Proxy(sOid, type); 65 String[] arOid = new String[] 66 {sOid}; 67 retVal= env.registerInterface(aProxy, arOid, type); 68 } 69 return retVal; 70 } 71 } 72 73 class Proxy implements IQueryInterface, XEventListener 74 { 75 String oid; 76 Type type; Proxy(String oid, Type t)77 Proxy(String oid, Type t) { 78 this.oid = oid; 79 this.type = t; 80 } 81 getOid()82 public String getOid() { 83 return oid; 84 } 85 isSame(Object object)86 public boolean isSame(Object object) { 87 if (object instanceof IQueryInterface) 88 { 89 IQueryInterface iquery = (IQueryInterface) object; 90 if (iquery != null) 91 { 92 if (iquery.getOid().equals(oid)) 93 return true; 94 else 95 return false; 96 } 97 } 98 99 String oidObj = UnoRuntime.generateOid(object); 100 if (oidObj.equals(oid)) 101 return true; 102 else 103 return false; 104 } 105 queryInterface(Type type)106 public Object queryInterface(Type type) { 107 return null; 108 } 109 disposing(com.sun.star.lang.EventObject eventObject)110 public void disposing(com.sun.star.lang.EventObject eventObject) { 111 } 112 113 } 114 115 116 //class Requester //implements IRequester 117 //{ 118 // int _modus; 119 // boolean _virtual; 120 // boolean _forceSynchronous; 121 // boolean _passed = true; 122 // 123 // Object _xEventListenerProxy; 124 // int nDisposingCalled= 0; 125 // 126 // Requester(boolean virtual, boolean forceSynchronous, Object evtListener) 127 // { 128 // _virtual = virtual; 129 // _forceSynchronous = forceSynchronous; 130 // _xEventListenerProxy= evtListener; 131 // 132 // } 133 // 134 // public Object sendRequest(Object object, 135 // Type type, 136 // String operation, 137 // Object params[], 138 // Boolean synchron[], 139 // Boolean mustReply[]) throws Throwable 140 // { 141 // 142 // Object result = null; 143 // if (operation.equals("disposing")) 144 // { 145 // System.out.println("Disposing called on XEventListener proxy"); 146 // nDisposingCalled++; 147 // } 148 // else if (operation.equals("queryInterface")) 149 // { 150 // if (params[0] instanceof Type) 151 // { 152 // Type t= (Type) params[0]; 153 // if (t.equals( new Type("com.sun.star.lang.XEventListener"))) 154 // result= _xEventListenerProxy; 155 // } 156 // } 157 // return result; 158 // } 159 //} 160 161 162