Mercurial > hg > blitz_stable
comparison src/org/dancres/jini/util/DiscoveryUtil.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.jini.util; | |
2 | |
3 import java.lang.reflect.Field; | |
4 | |
5 import java.rmi.RemoteException; | |
6 | |
7 import net.jini.core.lookup.ServiceRegistrar; | |
8 import net.jini.core.lookup.ServiceTemplate; | |
9 import net.jini.core.lookup.ServiceMatches; | |
10 import net.jini.core.lookup.ServiceItem; | |
11 | |
12 import net.jini.core.entry.Entry; | |
13 | |
14 public class DiscoveryUtil { | |
15 public static void dumpRegistrar(ServiceRegistrar aRegistrar) | |
16 throws RemoteException { | |
17 | |
18 String[] myGroups = aRegistrar.getGroups(); | |
19 | |
20 System.out.println("Registrar ServiceID: " + | |
21 aRegistrar.getServiceID()); | |
22 System.out.print("Groups: "); | |
23 for (int i = 0; i < myGroups.length; i++) { | |
24 System.out.print(myGroups[i] + " "); | |
25 } | |
26 System.out.println(); | |
27 System.out.println("LookupLocator: " + aRegistrar.getLocator()); | |
28 } | |
29 | |
30 public static void dumpContents(ServiceRegistrar aRegistrar) | |
31 throws RemoteException { | |
32 | |
33 ServiceTemplate myWildcard = new ServiceTemplate(null, null, null); | |
34 | |
35 ServiceMatches myMatches = aRegistrar.lookup(myWildcard, | |
36 Integer.MAX_VALUE); | |
37 | |
38 System.out.println("Total services: " + myMatches.totalMatches); | |
39 | |
40 for (int i = 0; i < myMatches.totalMatches; i++) { | |
41 ServiceItem myItem = myMatches.items[i]; | |
42 Object myProxy = myItem.service; | |
43 | |
44 System.out.println("ServiceId: " + myItem.serviceID); | |
45 System.out.println("Type: " + myProxy.getClass()); | |
46 System.out.print("Interfaces: "); | |
47 dumpInterfaces(myProxy); | |
48 | |
49 System.out.println("Total attributes: " + | |
50 myItem.attributeSets.length); | |
51 | |
52 dump(myItem.attributeSets); | |
53 | |
54 System.out.println(); | |
55 } | |
56 } | |
57 | |
58 public static ServiceMatches | |
59 findServicesOfType(Class aClass, | |
60 ServiceRegistrar aRegistrar) | |
61 throws RemoteException { | |
62 | |
63 ServiceTemplate myTemplate = | |
64 new ServiceTemplate(null, new Class[] {aClass}, null); | |
65 | |
66 ServiceMatches myServices = aRegistrar.lookup(myTemplate, 255); | |
67 | |
68 return myServices; | |
69 } | |
70 | |
71 public static void dump(Entry[] aListOfEntries) { | |
72 for (int i = 0; i < aListOfEntries.length; i++) { | |
73 System.out.println(" " + aListOfEntries[i].getClass().getName()); | |
74 dump(aListOfEntries[i]); | |
75 } | |
76 } | |
77 | |
78 public static void dump(Entry anEntry) { | |
79 Field[] myFields = anEntry.getClass().getFields(); | |
80 | |
81 for (int i = 0; i < myFields.length; i++) { | |
82 | |
83 try { | |
84 Object myValue = myFields[i].get(anEntry); | |
85 | |
86 System.out.println(myFields[i].getType().getName() + " " + | |
87 myFields[i].getName() + " = " + myValue); | |
88 } catch (IllegalAccessException anE) { | |
89 System.out.println(myFields[i].getType().getName() + " " + | |
90 myFields[i].getName() + " = IllegalAccessException"); | |
91 } | |
92 } | |
93 } | |
94 | |
95 public static void dump(ServiceMatches aMatches) { | |
96 System.out.println("Found " + aMatches.totalMatches); | |
97 | |
98 for (int i = 0; i < aMatches.totalMatches; i++) { | |
99 System.out.println("ServiceID: " + | |
100 aMatches.items[i].serviceID + ", " + | |
101 aMatches.items[i].service); | |
102 System.out.print("Interfaces: "); | |
103 dumpInterfaces(aMatches.items[i].service.getClass()); | |
104 } | |
105 } | |
106 | |
107 public static void dump(ServiceItem anItem) { | |
108 System.out.println("ServiceID: " + | |
109 anItem.serviceID + ", " + anItem.service); | |
110 System.out.print("Interfaces: "); | |
111 dumpInterfaces(anItem.service.getClass()); | |
112 } | |
113 | |
114 public static boolean hasInterface(Object anObject, Class anInterface) { | |
115 | |
116 Class myCurrentClass = anObject.getClass(); | |
117 | |
118 while (myCurrentClass != null) { | |
119 Class[] myInterfaces = myCurrentClass.getInterfaces(); | |
120 | |
121 for (int j = 0; j < myInterfaces.length; j++) { | |
122 if (myInterfaces[j].equals(anInterface)) | |
123 return true; | |
124 } | |
125 | |
126 myCurrentClass = myCurrentClass.getSuperclass(); | |
127 } | |
128 | |
129 return false; | |
130 } | |
131 | |
132 public static void dumpInterfaces(Object anObject) { | |
133 dumpInterfaces(anObject.getClass()); | |
134 } | |
135 | |
136 public static void dumpInterfaces(Class aClass) { | |
137 | |
138 Class[] myInterfaces = aClass.getInterfaces(); | |
139 | |
140 for (int j = 0; j < myInterfaces.length; j++) { | |
141 System.out.print(myInterfaces[j].getName() + | |
142 "(" + myInterfaces[j].getClassLoader() + ")" + " "); | |
143 } | |
144 | |
145 if (aClass.getSuperclass() != null) | |
146 dumpInterfaces(aClass.getSuperclass()); | |
147 else | |
148 System.out.println(); | |
149 } | |
150 } |