<commit_before>/*******************************************************************************
 * Copyright (C) 2007 The University of Manchester   
 * 
 *  Modifications to the initial code base are copyright of their
 *  respective authors, or their employers as appropriate.
 * 
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1 of
 *  the License, or (at your option) any later version.
 *    
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *    
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 ******************************************************************************/
package net.sf.taverna.t2.activities.beanshell;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;

import net.sf.taverna.raven.repository.Artifact;
import net.sf.taverna.raven.repository.ArtifactNotFoundException;
import net.sf.taverna.raven.repository.ArtifactStateException;
import net.sf.taverna.raven.repository.Repository;
import net.sf.taverna.raven.repository.impl.LocalArtifactClassLoader;

public class BeanshellClassloader extends URLClassLoader {
	private List<Artifact> artifacts;
	private Repository repo;

	public BeanshellClassloader(List<Artifact> artifacts) {
		super(new URL[] {});
		this.artifacts = artifacts;
		if (this.getClass().getClassLoader() instanceof LocalArtifactClassLoader) {

			repo = ((LocalArtifactClassLoader) this.getClass()
					.getClassLoader()).getRepository();
			for (Artifact a : artifacts) {
				repo.addArtifact(a);
			}
			repo.update();
		}
	}

	@Override
	protected Class<?> findClass(String classname) throws ClassNotFoundException {
		if (repo!=null) {
			for (Artifact a : artifacts) {
				ClassLoader cl;
				try {
					cl = repo.getLoader(a, null);
					Class<?> result = cl.loadClass(classname);
					return result;
				} catch (ArtifactNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ArtifactStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					
				}
			}
			throw new ClassNotFoundException("No class found for:"+classname);
			
		}
		else {
			return this.getClass().getClassLoader().loadClass(classname);
		}
	}
	
	
}
<commit_msg>Changed printStackTrace to go to a logger as per T2-578<commit_after>/*******************************************************************************
 * Copyright (C) 2007 The University of Manchester   
 * 
 *  Modifications to the initial code base are copyright of their
 *  respective authors, or their employers as appropriate.
 * 
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1 of
 *  the License, or (at your option) any later version.
 *    
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *    
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 ******************************************************************************/
package net.sf.taverna.t2.activities.beanshell;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;

import net.sf.taverna.raven.repository.Artifact;
import net.sf.taverna.raven.repository.ArtifactNotFoundException;
import net.sf.taverna.raven.repository.ArtifactStateException;
import net.sf.taverna.raven.repository.Repository;
import net.sf.taverna.raven.repository.impl.LocalArtifactClassLoader;

import org.apache.log4j.Logger;

public class BeanshellClassloader extends URLClassLoader {
	private List<Artifact> artifacts;
	private Repository repo;

	private static Logger logger = Logger
	.getLogger(BeanshellClassloader.class);
	
	public BeanshellClassloader(List<Artifact> artifacts) {
		super(new URL[] {});
		this.artifacts = artifacts;
		if (this.getClass().getClassLoader() instanceof LocalArtifactClassLoader) {

			repo = ((LocalArtifactClassLoader) this.getClass()
					.getClassLoader()).getRepository();
			for (Artifact a : artifacts) {
				repo.addArtifact(a);
			}
			repo.update();
		}
	}

	@Override
	protected Class<?> findClass(String classname) throws ClassNotFoundException {
		if (repo!=null) {
			for (Artifact a : artifacts) {
				ClassLoader cl;
				try {
					cl = repo.getLoader(a, null);
					Class<?> result = cl.loadClass(classname);
					return result;
				} catch (ArtifactNotFoundException e) {
					logger.error("Could not find " + a, e);
				} catch (ArtifactStateException e) {
					logger.error("Invalid  " + a, e);
				} catch (ClassNotFoundException e) {
					
				}
			}
			throw new ClassNotFoundException("No class found for:"+classname);
			
		}
		else {
			return this.getClass().getClassLoader().loadClass(classname);
		}
	}
	
	
}

{'fraction_non_alphanumeric': 0.14174206138016676, 'fraction_numerical': 0.008337768316480398, 'mean_word_length': 4.12079927338783, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3405977', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1541, 'n_words': 499}