Class ConfigurableFactoryHelper
java.lang.Object
games.stendhal.server.core.config.factory.ConfigurableFactoryHelper
A utility class for creating objects using ConfigurableFactory.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA wrapper factory for aConfigurableFactoryContextparameter constructor.protected static classA wrapper factory that uses the default constructor of a class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Objectcreate(ConfigurableFactory factory, ConfigurableFactoryContext ctx, Class<?> clazz) A class type safe wrapper for a ConfigurableFactory that takes a desired target class and returnsnullif the factory returns an incompatible object.static ConfigurableFactorygetFactory(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 returnsnullif 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
nullif 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>
Factoryexists 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
nullif no valid class was found.
- If a class named <class-name>
-