001    /*****************************************************************************
002     *                                                                           *
003     *  This file is part of the BeanShell Java Scripting distribution.          *
004     *  Documentation and updates may be found at http://www.beanshell.org/      *
005     *                                                                           *
006     *  Sun Public License Notice:                                               *
007     *                                                                           *
008     *  The contents of this file are subject to the Sun Public License Version  *
009     *  1.0 (the "License"); you may not use this file except in compliance with *
010     *  the License. A copy of the License is available at http://www.sun.com    * 
011     *                                                                           *
012     *  The Original Code is BeanShell. The Initial Developer of the Original    *
013     *  Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright     *
014     *  (C) 2000.  All Rights Reserved.                                          *
015     *                                                                           *
016     *  GNU Public License Notice:                                               *
017     *                                                                           *
018     *  Alternatively, the contents of this file may be used under the terms of  *
019     *  the GNU Lesser General Public License (the "LGPL"), in which case the    *
020     *  provisions of LGPL are applicable instead of those above. If you wish to *
021     *  allow use of your version of this file only under the  terms of the LGPL *
022     *  and not to allow others to use your version of this file under the SPL,  *
023     *  indicate your decision by deleting the provisions above and replace      *
024     *  them with the notice and other provisions required by the LGPL.  If you  *
025     *  do not delete the provisions above, a recipient may use your version of  *
026     *  this file under either the SPL or the LGPL.                              *
027     *                                                                           *
028     *  Patrick Niemeyer (pat@pat.net)                                           *
029     *  Author of Learning Java, O'Reilly & Associates                           *
030     *  http://www.pat.net/~pat/                                                 *
031     *                                                                           *
032     *****************************************************************************/
033    
034    package bsh;
035    
036    import bsh.Capabilities.Unavailable;
037    
038    /**
039            ReflectManager is a dynamically loaded extension that supports extended
040            reflection features supported by JDK1.2 and greater.
041    
042            In particular it currently supports accessible method and field access 
043            supported by JDK1.2 and greater.
044    */
045    public abstract class ReflectManager
046    {
047            private static ReflectManager rfm;
048    
049            /**
050                    Return the singleton bsh ReflectManager.
051                    @throws Unavailable
052            */
053            public static ReflectManager getReflectManager() 
054                    throws Unavailable
055            {
056                    if ( rfm == null ) 
057                    {
058                            Class clas;
059                            try {
060                                    clas = Class.forName( "bsh.reflect.ReflectManagerImpl" );
061                                    rfm = (ReflectManager)clas.newInstance();
062                            } catch ( Exception e ) {
063                                    throw new Unavailable("Reflect Manager unavailable: "+e);
064                            }
065                    }
066            
067                    return rfm;
068            }
069    
070            /**
071                    Reflect Manager Set Accessible.
072                    Convenience method to invoke the reflect manager.
073                    @throws Unavailable
074            */
075            public static boolean RMSetAccessible( Object obj ) 
076                    throws Unavailable
077            {
078                    return getReflectManager().setAccessible( obj );
079            }
080    
081            /**
082                    Set a java.lang.reflect Field, Method, Constructor, or Array of
083                    accessible objects to accessible mode.
084                    @return true if the object was accessible or false if it was not.
085            */
086            public abstract boolean setAccessible( Object o );
087    }
088