String fieldName = config.getAttribute( "field" );
String fieldValue = config.getAttribute( "value" );
if ( className == null || className.trim( ).equals( "" ) )
{
throw new FactoryException( "no class name specified" );
}
if ( fieldName == null || fieldName.trim( ).equals( "" ) )
{
throw new FactoryException( "no field name specified" );
}
if ( fieldValue == null || fieldValue.trim( ).equals( "" ) )
{
throw new FactoryException( "no field value specified" );
}
Class clazz = null;
try
{
ClassLoader cl = (ClassLoader) context.get( "smf-classLoader" );
if ( cl == null )
{
cl = Thread.currentThread( ).getContextClassLoader( );
context.put( "smf-classLoader",
cl );
}
if ( cl == null )
{
cl = getClass( ).getClassLoader( );
context.put( "smf-classLoader",
cl );
}
Importer importer = rule.getImporter( );
clazz = importer.importClass( cl,
className );
// make sure field getter exists
clazz.getMethod( "get" + fieldName.toUpperCase( ).charAt( 0 ) + fieldName.substring( 1 ),
(Class[]) null );
}
catch ( SecurityException e )
{
throw new FactoryException( "Field '" + fieldName + "' is not accessible for Class '" + className + "'" );
}
catch ( NoSuchMethodException e )
{
throw new FactoryException( "Field '" + fieldName + "' does not exist for Class '" + className + "'" );
}
catch ( ClassNotFoundException e )
{
throw new FactoryException( e.getMessage( ) );
}
catch ( Error e )
{
throw new FactoryException( e.getMessage( ) );
}
return new ClassFieldObjectType( clazz,
fieldName,
fieldValue );