001/* Simple implementation based on Class.forName. 002 003Copyright (c) 2015-2016 The Regents of the University of California; iSencia Belgium NV. 004All rights reserved. 005 006Permission is hereby granted, without written agreement and without 007license or royalty fees, to use, copy, modify, and distribute this 008software and its documentation for any purpose, provided that the above 009copyright notice and the following two paragraphs appear in all copies 010of this software. 011 012IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA LIABLE TO ANY PARTY 013FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 014ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 015THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 016SUCH DAMAGE. 017 018THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 019INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 020MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 021PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 022CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 023ENHANCEMENTS, OR MODIFICATIONS. 024 025PT_COPYRIGHT_VERSION_2 026COPYRIGHTENDKEY 027*/ 028 029package org.ptolemy.classloading; 030 031import org.ptolemy.commons.VersionSpecification; 032 033import ptolemy.kernel.CompositeEntity; 034 035/** 036 * As the name says... a simple strategy implementation providing a bridge 037 * between the <code>ClassLoadingStrategy</code> approach and 038 * the usage of a plain <code>ClassLoader</code>, for loading Java classes. 039 * 040 * <p>REMARK: It does not support loading actor-oriented classes! </p> 041 * 042 * @author ErwinDL 043 * @version $Id$ 044 * @since Ptolemy II 11.0 045 * @Pt.ProposedRating Yellow (ErwinDL) 046 * @Pt.AcceptedRating Yellow (ErwinDL) 047 */ 048public class SimpleClassLoadingStrategy implements ClassLoadingStrategy { 049 050 /** 051 * Construct a strategy that uses the default class loader, 052 * i.e. the one with which this own class was loaded. 053 */ 054 public SimpleClassLoadingStrategy() { 055 _classLoader = getClass().getClassLoader(); 056 } 057 058 /** 059 * Construct a strategy that uses the given class loader. 060 * 061 * @param classLoader The class loader 062 */ 063 public SimpleClassLoadingStrategy(ClassLoader classLoader) { 064 _classLoader = classLoader; 065 } 066 067 /** 068 * Load a Java class. 069 * @param className The namee of the class. 070 * @param versionSpec The version 071 * @return the Class for the given name. 072 * @exception ClassNotFoundException If the class is not found. 073 */ 074 @Override 075 @SuppressWarnings("rawtypes") 076 public Class loadJavaClass(String className, 077 VersionSpecification versionSpec) throws ClassNotFoundException { 078 return Class.forName(className, true, _classLoader); 079 } 080 081 /** 082 * Load an actor-oriented class, which is typically a .moml file. 083 * @param className The namee of the class. 084 * @param versionSpec The version 085 * @return the Class for the given name. 086 * @exception ClassNotFoundException Always thrown in this base class. 087 */ 088 @Override 089 public CompositeEntity loadActorOrientedClass(String className, 090 VersionSpecification versionSpec) throws ClassNotFoundException { 091 throw new ClassNotFoundException(); 092 } 093 094 /////////////////////////////////////////////////////////////////// 095 //// private variables //// 096 private ClassLoader _classLoader; 097}