net.sf.mmm.util.reflect.base
Class MappedClassResolver

java.lang.Object
  extended by net.sf.mmm.util.reflect.base.MappedClassResolver
All Implemented Interfaces:
ClassResolver
Direct Known Subclasses:
JavaLangClassResolver

public class MappedClassResolver
extends Object
implements ClassResolver

This is an implementation of the ClassResolver interface that uses an internal Map to define specific mappings. If no mapping is found for the requested type the default strategy Class.forName(String) is used.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  Map<String,Class<?>> name2classMap
           
 
Fields inherited from interface net.sf.mmm.util.reflect.api.ClassResolver
CLASS_FOR_NAME_RESOLVER
 
Constructor Summary
MappedClassResolver()
          The constructor.
MappedClassResolver(MapFactory<? extends Map> mapFactory)
          The constructor.
 
Method Summary
 void addClassMapping(Class<?> type)
          This method adds a mapping for the given type using the simple-name.
 void addClassMapping(String name, Class<?> type)
          This method adds a mapping for the given type using the given name.
 Class<?> resolveClass(String name)
          This method resolves the class with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name2classMap

private final Map<String,Class<?>> name2classMap
See Also:
resolveClass(String)
Constructor Detail

MappedClassResolver

public MappedClassResolver()
The constructor.


MappedClassResolver

public MappedClassResolver(MapFactory<? extends Map> mapFactory)
The constructor.

Parameters:
mapFactory - the factory used to create the underlying Map.
Method Detail

addClassMapping

public void addClassMapping(Class<?> type)
This method adds a mapping for the given type using the simple-name.

Parameters:
type - is the type to add.

addClassMapping

public void addClassMapping(String name,
                            Class<?> type)
This method adds a mapping for the given type using the given name.

Parameters:
name - is the name under which the class is mapped.
type - is the mapped class.

resolveClass

public Class<?> resolveClass(String name)
This method resolves the class with the given name. In addition to a ClassLoader this method may also find types via a logical alias name.
The name can be the physical (fully qualified) classname (e.g. org.foo.BlobImpl) but this may also be a logical name depending on the implementation of this interface (e.g. Blob may point to the same type).

Specified by:
resolveClass in interface ClassResolver
Parameters:
name - is the logical or physical name of the requested type.
Returns:
the class reflecting the type with the given name.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.