Class ConfigurableFactoryHelper
java.lang.Object
games.stendhal.server.core.config.factory.ConfigurableFactoryHelper
A utility class for creating objects using ConfigurableFactory.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
A wrapper factory for aConfigurableFactoryContext
parameter constructor.protected static class
A wrapper factory that uses the default constructor of a class. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
create(ConfigurableFactory factory, ConfigurableFactoryContext ctx, Class<?> clazz)
A class type safe wrapper for a ConfigurableFactory that takes a desired target class and returnsnull
if the factory returns an incompatible object.static ConfigurableFactory
getFactory(String className)
Create an object factory using a [logical] class name.
-
Constructor Details
-
ConfigurableFactoryHelper
public ConfigurableFactoryHelper()
-
-
Method Details
-
create
public static Object create(ConfigurableFactory factory, ConfigurableFactoryContext ctx, Class<?> clazz)A class type safe wrapper for a ConfigurableFactory that takes a desired target class and returnsnull
if the factory returns an incompatible object. This allows the called to cast the return values without worrying about ClassCastExceptions.- Parameters:
factory
- Object factory.ctx
- Configuration context.clazz
- The target class.- Returns:
- A new object, or
null
if allowed by the factory type, or of the wrong class. - Throws:
IllegalArgumentException
- If there is a problem with the attributes. The exception message should be a value suitable for meaningful user interpretation.
-
getFactory
Create an object factory using a [logical] class name.This will attempt to create a factory for the class in the following order:
- If a class named <class-name>
Factory
exists and implementsConfigurableFactory
, return an instance of it. - If a class named <class-name> exists and implements
ConfigurableFactory
, return an instance of it. - If a class named <class-name> exists and accepts a constructor with ConfigurableFactoryContext, return a factory that creates an instance with that constructor when used.
- If a class named <class-name> exists and has a default constructor, return a factory that creates an instance with that constructor when used.
- Returns
null
,
- Parameters:
className
- A base class name to load.- Returns:
- A factory, or
null
if no valid class was found.
- If a class named <class-name>
-