<commit_before>/**
 * 
 */
package org.selfip.bkimmel.rmi;

import java.nio.ByteBuffer;
import java.rmi.RemoteException;

import org.selfip.bkimmel.util.classloader.ClassLoaderStrategy;

/**
 * @author brad
 *
 */
public final class RMIClassLoaderStrategy implements ClassLoaderStrategy {
	
	private final ClassLoaderService service;
	
	public RMIClassLoaderStrategy(ClassLoaderService service) {
		this.service = service;
	}

	/* (non-Javadoc)
	 * @see org.selfip.bkimmel.util.classloader.ClassLoaderStrategy#getClassDefinition(java.lang.String)
	 */
	public ByteBuffer getClassDefinition(String name) {
		
		try {
			
			byte[] def = service.getClassDefinition(name);

			if (def != null) {
				return ByteBuffer.wrap(def);
			}
			
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
		return null;
		
	}

}
<commit_msg>Added constructor to RMIClassLoaderStrategy takes the URL of the remote interface as its parameter, and a default constructor that uses javax.jnlp.BasicService.getCodeBase() to get this URL.<commit_after>/**
 *
 */
package org.selfip.bkimmel.rmi;

import java.net.URL;
import java.nio.ByteBuffer;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import javax.jnlp.BasicService;
import javax.jnlp.ServiceManager;
import javax.jnlp.UnavailableServiceException;

import org.selfip.bkimmel.util.classloader.ClassLoaderStrategy;

/**
 * @author brad
 *
 */
public final class RMIClassLoaderStrategy implements ClassLoaderStrategy {

	private final ClassLoaderService service;
	
	public RMIClassLoaderStrategy() throws RemoteException, NotBoundException {
		this(getClassLoaderService());
	}

	public RMIClassLoaderStrategy(URL baseUrl) throws RemoteException, NotBoundException {
		this(getClassLoaderService(baseUrl));
	}

	public RMIClassLoaderStrategy(ClassLoaderService service) {
		this.service = service;
	}
	
	public static ClassLoaderService getClassLoaderService() throws RemoteException, NotBoundException {
		try {
			BasicService basic = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
			return getClassLoaderService(basic.getCodeBase());
		} catch (UnavailableServiceException e) {
			throw new IllegalStateException("javax.jnlp.BasicService is required.", e);
		}
	}
	
	public static ClassLoaderService getClassLoaderService(URL baseUrl) throws RemoteException, NotBoundException {
		Registry registry = LocateRegistry.getRegistry(baseUrl.getHost());
		return (ClassLoaderService) registry.lookup("ClassLoaderService");
	}

	/* (non-Javadoc)
	 * @see org.selfip.bkimmel.util.classloader.ClassLoaderStrategy#getClassDefinition(java.lang.String)
	 */
	public ByteBuffer getClassDefinition(String name) {

		try {

			byte[] def = service.getClassDefinition(name);

			if (def != null) {
				return ByteBuffer.wrap(def);
			}

		} catch (RemoteException e) {
			e.printStackTrace();
		}

		return null;

	}

}

{'fraction_non_alphanumeric': 0.09986504723346828, 'fraction_numerical': 0.0, 'mean_word_length': 4.94188376753507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '252064', 'n_tokens_mistral': 955, 'n_tokens_neox': 868, 'n_words': 184}