1 | /* |
2 | * $Id: DispatchJavaCoClass.java,v 1.3 2005/12/01 06:10:00 hastings Exp $ |
3 | * |
4 | * (c) Copyright, Moebius Solutions, Inc., 2004 |
5 | * |
6 | * All Rights Reserved |
7 | * |
8 | * This material may be reproduced by or for the U. S. Government |
9 | * pursuant to the copyright license under the clause at |
10 | * DFARS 252.227-7014 (OCT 2001). |
11 | */ |
12 | package com.moesol.bindings; |
13 | |
14 | import java.util.logging.Level; |
15 | import java.util.logging.Logger; |
16 | |
17 | import com.moesol.bindings.platform_sdk.component_services.GUID; |
18 | |
19 | public class DispatchJavaCoClass extends DispatchJavaCommon { |
20 | private static final Logger s_logger = Logger.getLogger(DispatchJavaCoClass.class.getName()); |
21 | |
22 | private GUID[] m_implemented_categories; |
23 | |
24 | protected DispatchJavaCoClass() { |
25 | } |
26 | |
27 | // |
28 | // TODO All Dispatch<*> classes should probably move to component_services |
29 | // since we should be able to use h-gen without COM. |
30 | // |
31 | |
32 | /** |
33 | * @param c class of the interface |
34 | * @return a DispatchJavaCoClass that describes {@code c}. |
35 | */ |
36 | public static DispatchJavaCoClass forClass(Class c) { |
37 | DispatchJavaCoClass r = new DispatchJavaCoClass(); |
38 | try { |
39 | r.fillLibraryInfo(c); |
40 | r.fillCoClassInfo(c); |
41 | r.fillImplementedCategories(c); |
42 | |
43 | return r; |
44 | } catch (SecurityException e) { |
45 | throw new RuntimeException(e); |
46 | } catch (IllegalArgumentException e) { |
47 | throw new RuntimeException(e); |
48 | } catch (ClassNotFoundException e) { |
49 | throw new RuntimeException(e); |
50 | } catch (NoSuchFieldException e) { |
51 | throw new RuntimeException(e); |
52 | } catch (IllegalAccessException e) { |
53 | throw new RuntimeException(e); |
54 | } |
55 | } |
56 | |
57 | private void fillCoClassInfo(Class c) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { |
58 | setUuid((GUID)getObjectField(c, "CLSID")); |
59 | } |
60 | |
61 | private void fillImplementedCategories(Class c) throws SecurityException, IllegalArgumentException, IllegalAccessException { |
62 | try { |
63 | m_implemented_categories = (GUID[])getObjectField(c, "IMPLEMENTS_CATEGORIES"); |
64 | } catch (NoSuchFieldException e) { |
65 | s_logger.log(Level.FINE, "{0} not have a static field IMPLEMENTS_CATEGORIES", c); |
66 | } |
67 | } |
68 | |
69 | public GUID[] getImplementedCategories() { |
70 | return m_implemented_categories; |
71 | } |
72 | } |