1 | /* |
2 | * $Id: ComInProcGroups.java,v 1.1 2005/12/14 03:20:38 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.platform_sdk.component_services; |
13 | |
14 | import java.net.MalformedURLException; |
15 | import java.net.URLClassLoader; |
16 | import java.util.HashMap; |
17 | import java.util.Map; |
18 | import java.util.prefs.BackingStoreException; |
19 | |
20 | /** |
21 | * Manage COM in-process groups. |
22 | * Free threaded. |
23 | * |
24 | * @author Hastings |
25 | */ |
26 | public class ComInProcGroups { |
27 | |
28 | private static final ComInProcGroups s_inst = new ComInProcGroups(); |
29 | |
30 | private Map m_group_map = new HashMap(); |
31 | |
32 | private ComInProcGroups() { |
33 | } |
34 | |
35 | public static ComInProcGroups instance() { |
36 | return s_inst; |
37 | } |
38 | |
39 | public Class getClass(GUID clsid, String class_name) throws ClassNotFoundException, MalformedURLException, BackingStoreException { |
40 | String group = COM.findComServerValue(clsid, "Group"); |
41 | ClassLoader child = getClassLoader(group); |
42 | return Class.forName(class_name, true, child); |
43 | } |
44 | |
45 | public synchronized ClassLoader getClassLoader(String group_name) throws MalformedURLException, BackingStoreException { |
46 | ClassLoader l = (ClassLoader)m_group_map.get(group_name); |
47 | if (l == null) { |
48 | l = makeLoader(group_name); |
49 | m_group_map.put(group_name, l); |
50 | } |
51 | return l; |
52 | } |
53 | |
54 | private ClassLoader makeLoader(String group_name) throws MalformedURLException, BackingStoreException { |
55 | ComClassPathBuilder b = new ComClassPathBuilder(group_name); |
56 | return new URLClassLoader(b.buildClassPath()); |
57 | } |
58 | |
59 | } |