summaryrefslogtreecommitdiffstats
path: root/kdejava/koala/org/kde/koala/Invocation.java
blob: a3814ef236d9985e14ad725e1c9bb403546b11ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/***************************************************************************
                            Invocation.java -  description
                             -------------------
    begin                : Tue Oct 31 06:12:14 2000
    copyright            : (C) Gert-Jan van der Heiden. All rights reserved.
    written by           : Gert-Jan van der Heiden.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as published by*
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

package org.kde.koala;

import java.util.*;
import java.lang.reflect.*;
import org.kde.qt.qtjava;

/** A utility class for creating a closure to invoke later
*/
class Invocation{
public static ArrayList invokeInterfaces(long qtObject){
	   return invokeArrayOperation(qtObject, "interfaces");
	}
	public static ArrayList invokeFunctions(long qtObject){
	   return invokeArrayOperation(qtObject, "functions");
	}
  public static ArrayList invokeArrayOperation(long qtObject, String operationName){
	  try{
      Object onThis = qtjava.objectForQtKey(qtObject, "java.lang.object", true);
			if(onThis != null){
				Object[] arguments = new Object[0];
	      Class[] objectTypes = new Class[0];
	      Method method = onThis.getClass().getMethod(operationName, objectTypes);
	      return (ArrayList) method.invoke(onThis,arguments);
			}else {
			  System.out.println("Invocation.invokeArrayOperation() : object not found!");
			}
	  }catch(Exception e){
	    e.printStackTrace();
	  }
		return new ArrayList();
	}
  public static DCOPAnswer invokeProcess(long qtObject, String fun, byte[] data){
	  try{
      Object onThis = qtjava.objectForQtKey(qtObject, "java.lang.object", true);
			if(onThis != null){
				Object[] arguments = {fun, data};
	      Class[] objectTypes = { String.class,
				                        data.getClass()};

	      Method method = onThis.getClass().getMethod("javaProcess", objectTypes);
	      return  (DCOPAnswer) method.invoke(onThis,arguments);
			}else {
			  System.out.println("Invocation.invokeArrayOperation() : object not found!");
			}
	  }catch(Exception e){
	    e.printStackTrace();
	  }
		DCOPAnswer answer = new DCOPAnswer();
		answer.setSucces(false);
		return answer;
	}
}