Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2005, 2010 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
package org.eclipse.osgi.internal.loader.buddy;
public class SystemPolicy implements IBuddyPolicy {
	private static class ParentClassLoader extends ClassLoader {
		protected ParentClassLoader() {
			super(Object.class.getClassLoader());
		}
	}
	public static final byte BOOT = 0;
	public static final byte EXT = 1;
	public static final byte APP = 2;
	private static SystemPolicy[] instances = new SystemPolicy[3];
	public static SystemPolicy getInstance(final byte type) {
		if ([type] == null) {
			[type] = new SystemPolicy();
			[type]. = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
				public Object run() {
					return createClassLoader(type);
				}
			});
		}
		return [type];
	}
	public SystemPolicy() {
		//Nothing to do
	}
	public SystemPolicy(ClassLoader parent) {
		 = parent;
	}
	static ClassLoader createClassLoader(byte type) {
		switch (type) {
			case  :
				if (ClassLoader.getSystemClassLoader() != null)
					return ClassLoader.getSystemClassLoader();
				return new ParentClassLoader();
			case  :
				return new ParentClassLoader();
			case  :
				if (ClassLoader.getSystemClassLoader() != null)
					return ClassLoader.getSystemClassLoader().getParent();
				return new ParentClassLoader();
		}
		return null;
	}
	public Class loadClass(String name) {
		try {
			return .loadClass(name);
catch (ClassNotFoundException e) {
			return null;
		}
	}
	public URL loadResource(String name) {
		return .getResource(name);
	}
	public Enumeration loadResources(String name) {
		try {
			return .getResources(name);
catch (IOException e) {
			return null;
		}
	}
New to GrepCode? Check out our FAQ X