net.javamud.run
Class ClassMapper

java.lang.Object
  |
  +--net.javamud.run.ClassMapper

public class ClassMapper
extends Object

Maps simple or "old" names to a full class name.

Author:
Timothy Hinchcliffe
See Also:
Default ClassMap
Created On:
11 June 2002

Field Summary
protected  Properties classMap
          Map of simple or "old" names to full names.
 
Constructor Summary
ClassMapper(InputStream sysClassMap, InputStream userClassMap)
          Constructor for the ClassMapper object.
 
Method Summary
 Class forName(String className)
          Returns the Class for the mapped className .
 Object lazyNew(String className)
          Version of New which throws Error instead of Exception
 Object lazyNew(String className, Class[] paramTypes, Object[] params)
          Version of New which throws Error instead of Exception
 Object lazyNew(String className, Object[] params)
          Version of New which throws Error instead of Exception
 Object lazyNew(String className, String identity)
          Version of New which throws Error instead of Exception
 String map(String from)
          Returned the Mapped name.
 Object New(String className)
          Return a new instance of the given className (subject to mapping).
 Object New(String className, Class[] paramTypes, Object[] params)
          Return a new instance of the given className (subject to mapping).
 Object New(String className, Object[] params)
          Return a new instance of the given className (subject to mapping).
 Object New(String className, String identity)
          Create a new Object with identity as the first paramater.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classMap

protected Properties classMap
Map of simple or "old" names to full names.

Constructor Detail

ClassMapper

public ClassMapper(InputStream sysClassMap,
                   InputStream userClassMap)
            throws IOException
Constructor for the ClassMapper object.

If you can figure out where a resource should be stored (preferably in a Jar file) I will add an implementation of public ClassMapper(InputStream userClassMap) which will use this.getClass().getResourceAsStream("ClassMapper.properties") to get the default mappings.

Parameters:
sysClassMap - Default ClassMap (Probably from JAR file).
userClassMap - Current (User) ClassMap file (or null). (Probably from file system).
Throws:
IOException - Description of the Exception
See Also:
Default ClassMap
Method Detail

New

public Object New(String className)
           throws ClassNotFoundException,
                  InstantiationException,
                  IllegalAccessException
Return a new instance of the given className (subject to mapping).

Parameters:
className - Class to try to load (mapped first).
Returns:
New Object
Throws:
ClassNotFoundException - Thrown if class could not be found.
InstantiationException - Could not create an instance of the class.
IllegalAccessException - Illegal access.
See Also:
Class.forName(String), Class.newInstance(), map(String)

New

public Object New(String className,
                  Class[] paramTypes,
                  Object[] params)
           throws IllegalAccessException,
                  ClassNotFoundException,
                  InstantiationException,
                  NoSuchMethodException,
                  InvocationTargetException
Return a new instance of the given className (subject to mapping).

Parameters:
className - Class to load via Mapping.
paramTypes - Parameter Types
params - Parameter Values
Returns:
New Object
Throws:
NoSuchMethodException - No matching constructor.
InvocationTargetException - Constructor threw an Exception.
ClassNotFoundException - Well Duh!
InstantiationException - What you doing instantiating an abstract class?
IllegalAccessException - Give me more permisions you fool.

New

public Object New(String className,
                  Object[] params)
           throws IllegalAccessException,
                  ClassNotFoundException,
                  InstantiationException,
                  NoSuchMethodException,
                  InvocationTargetException
Return a new instance of the given className (subject to mapping).

Parameters:
className - Class to load via Mapping.
params - Parameter Values
Returns:
New Object
Throws:
NoSuchMethodException - No matching constructor.
InvocationTargetException - Constructor threw an Exception.
ClassNotFoundException - Well Duh!
InstantiationException - What you doing instantiating an abstract class?
IllegalAccessException - Give me more permisions you fool.

New

public Object New(String className,
                  String identity)
           throws IllegalAccessException,
                  ClassNotFoundException,
                  InstantiationException,
                  NoSuchMethodException,
                  InvocationTargetException
Create a new Object with identity as the first paramater. Uses New(String,Object[]).

Parameters:
className - Name of MudObject class.
identity - Identity to assign.
Returns:
New Object.
Throws:
IllegalAccessException - See New(String,Object[]).
ClassNotFoundException - See New(String,Object[]).
InstantiationException - See New(String,Object[]).
NoSuchMethodException - See New(String,Object[]).
InvocationTargetException - See New(String,Object[]).

forName

public Class forName(String className)
              throws ClassNotFoundException
Returns the Class for the mapped className .

Parameters:
className - className to look up.
Returns:
Class as looked up.
Throws:
ClassNotFoundException - Description of the Exception

lazyNew

public Object lazyNew(String className)
Version of New which throws Error instead of Exception

Parameters:
className - className to look up.
Returns:
New Object.

lazyNew

public Object lazyNew(String className,
                      Object[] params)
Version of New which throws Error instead of Exception

Parameters:
className - className to look up.
params - Paramaters for constructor
Returns:
New Object.

lazyNew

public Object lazyNew(String className,
                      String identity)
Version of New which throws Error instead of Exception

Parameters:
className - className to look up.
identity - Identity for new Object.
Returns:
New Object.

lazyNew

public Object lazyNew(String className,
                      Class[] paramTypes,
                      Object[] params)
Version of New which throws Error instead of Exception

Parameters:
className - className to look up.
paramTypes - Paramater types.
params - Paramaters for constructor
Returns:
New Object.

map

public String map(String from)
Returned the Mapped name. Will return from if no map exists.

Parameters:
from - Key for classMap.Properties.getProperty(String)
Returns:
Mapped value.