KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > internal > baseadaptor > DevClassLoadingHook


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.osgi.internal.baseadaptor;
13
14 import java.security.ProtectionDomain JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import org.eclipse.osgi.baseadaptor.*;
17 import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
18 import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook;
19 import org.eclipse.osgi.baseadaptor.loader.*;
20 import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;
21 import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
22 import org.eclipse.osgi.framework.util.KeyedElement;
23
24 public class DevClassLoadingHook implements ClassLoadingHook, HookConfigurator, KeyedElement {
25     public static final String JavaDoc KEY = DevClassLoadingHook.class.getName();
26     public static final int HASHCODE = KEY.hashCode();
27
28     public byte[] processClass(String JavaDoc name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager) {
29         // Do nothing
30
return null;
31     }
32
33     public boolean addClassPathEntry(ArrayList JavaDoc cpEntries, String JavaDoc cp, ClasspathManager hostmanager, BaseData sourcedata, ProtectionDomain JavaDoc sourcedomain) {
34         // first check that we are in devmode for this sourcedata
35
String JavaDoc[] devClassPath = !DevClassPathHelper.inDevelopmentMode() ? null : DevClassPathHelper.getDevClassPath(sourcedata.getSymbolicName());
36         if (devClassPath == null || devClassPath.length == 0)
37             return false; // not in dev mode return
38
// check that dev classpath entries have not already been added; we mark this in the first entry below
39
if (cpEntries.size() > 0 && ((ClasspathEntry) cpEntries.get(0)).getUserObject(KEY) != null)
40             return false; // this source has already had its dev classpath entries added.
41
boolean result = false;
42         for (int i = 0; i < devClassPath.length; i++) {
43             if (ClasspathManager.addClassPathEntry(cpEntries, devClassPath[i], hostmanager, sourcedata, sourcedomain))
44                 result = true;
45             else {
46                 // if in dev mode, try using the cp as an absolute path
47
ClasspathEntry entry = hostmanager.getExternalClassPath(devClassPath[i], sourcedata, sourcedomain);
48                 if (entry != null) {
49                     cpEntries.add(entry);
50                     result = true;
51                 }
52             }
53         }
54         // mark the first entry of the list.
55
// This way we can quickly tell that dev classpath entries have been added to the list
56
if (result && cpEntries.size() > 0)
57             ((ClasspathEntry) cpEntries.get(0)).addUserObject(this);
58         return result;
59     }
60
61     public String JavaDoc findLibrary(BaseData data, String JavaDoc libName) {
62         // Do nothing
63
return null;
64     }
65
66     public ClassLoader JavaDoc getBundleClassLoaderParent() {
67         // Do nothing
68
return null;
69     }
70
71     public BaseClassLoader createClassLoader(ClassLoader JavaDoc parent, ClassLoaderDelegate delegate, BundleProtectionDomain domain, BaseData data, String JavaDoc[] bundleclasspath) {
72         // do nothing
73
return null;
74     }
75
76     public void initializedClassLoader(BaseClassLoader baseClassLoader, BaseData data) {
77         // do nothing
78
}
79
80     public void addHooks(HookRegistry hookRegistry) {
81         if (DevClassPathHelper.inDevelopmentMode())
82             // only add dev classpath manager if in dev mode
83
hookRegistry.addClassLoadingHook(new DevClassLoadingHook());
84
85     }
86
87     public boolean compare(KeyedElement other) {
88         return other.getKey() == KEY;
89     }
90
91     public Object JavaDoc getKey() {
92         return KEY;
93     }
94
95     public int getKeyHashCode() {
96         return HASHCODE;
97     }
98 }
99
Popular Tags