KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > tools > OPP > srcgen > query > ReflectionClassQuery


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8
package org.ozoneDB.tools.OPP.srcgen.query;
9
10 import org.ozoneDB.tools.OPP.srcgen.ClassQuery;
11
12 /**
13  * User: Jocke
14  * Date: 2004-jan-02
15  * Time: 00:52:24
16  */

17 public class ReflectionClassQuery implements ClassQuery {
18     public boolean isAssignable(String JavaDoc itf, String JavaDoc from) throws ClassNotFoundException JavaDoc {
19         Class JavaDoc itfClass = Class.forName(itf);
20         Class JavaDoc fromClass = Class.forName(from);
21         return itfClass.isAssignableFrom(fromClass);
22     }
23
24     public String JavaDoc[] getInterfaces(String JavaDoc className) throws ClassNotFoundException JavaDoc {
25         Class JavaDoc clazz = Class.forName(className);
26         Class JavaDoc interfaces [] = clazz.getInterfaces();
27         return classesToStrings(interfaces);
28     }
29
30     public boolean isInterface(String JavaDoc className) throws ClassNotFoundException JavaDoc {
31         Class JavaDoc clazz = Class.forName(className);
32         return clazz.isInterface();
33     }
34
35
36     private String JavaDoc[] classesToStrings(Class JavaDoc classes[]) {
37         String JavaDoc names [] = new String JavaDoc[classes.length];
38         for (int i = 0; i < classes.length; i++) {
39             Class JavaDoc aClass = classes[i];
40             names[i] = aClass.getName();
41         }
42         return names;
43     }
44 }
45
Popular Tags