All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.org.retep.util.misc.Support Maven / Gradle / Ivy

/*
 * 

Copyright (c) 1998-2007, Peter T Mount
* All rights reserved.

* *

Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met:

* *
    *
  • Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer.
  • * *
  • Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution.
  • * *
  • Neither the name of the retep.org.uk nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission.
  • * *
* *

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/ package uk.org.retep.util.misc; /** This class provides some utility methods. These include alternatives to * Class.forName() etc. However because of problems when running under * different environments (NetBeans is the main one), the actual calls are * delegated to an alternative class. * * @author peter */ public final class Support { // The global singleton instance private static final Support SINGLETON = new Support(); // The current delegate private Delegate del; /** Private constructor - use getInstance() to retrieve the instance. */ private Support() { } public static Support getInstance() { return SINGLETON; } /** Return the delegate in use, auto detecting it if not set */ public Delegate getDelegate() { if(del==null) { synchronized(this) { if(del==null) { try { setDelegate((Support.Delegate) Class.forName("uk.org.retep.nb.NBSupport").newInstance()); } catch(Exception ex) { // Not found, so use default implementation setDelegate(new Support.Delegate()); } } } } return del; } /** Set the Support.Delegate to use. Normally this is detected automatically, * but you can overide it by using this method. Setting it to null will force * it to be re-detected. */ public void setDelegate(Support.Delegate aDelegate) { del = aDelegate; } public Class forName(String aName) throws ClassNotFoundException { return getDelegate().forName(aName); } public Object newInstance(Class aClass) throws InstantiationException, IllegalAccessException { return getDelegate().newInstance(aClass); } public Object newInstance(String aName) throws ClassNotFoundException,InstantiationException, IllegalAccessException { return newInstance(forName(aName)); } /** Default implementation of the delegate. Sub classes may overide individual * methods for special purposes. */ public static class Delegate { /** Constructor. Sub classes must call super() to cover future versions of this * class. */ public Delegate() { } public Class forName(String aName) throws ClassNotFoundException { return Class.forName(aName); } public Object newInstance(Class aClass) throws InstantiationException, IllegalAccessException { return aClass.newInstance(); } public ClassLoader getLoader() { return ClassLoader.getSystemClassLoader(); } } } /* * $Log: Support.java,v $ * Revision 1.4 2007/01/06 16:56:25 peter * Fixed copyright to account for 2007 * * Revision 1.3 2006/09/10 22:24:35 peter * Code cleanup and some changes to new package layout * * Revision 1.2 2003/06/26 11:18:10 petermount * Added license to classes. Added TreeNode * * Revision 1.1 2003/06/26 11:01:22 petermount * This class was missing from the CVS, althoug it's been here for at least 9 month! oops... * */




© 2015 - 2025 Weber Informatics LLC | Privacy Policy