Class ConfigurableFactoryHelper

java.lang.Object
games.stendhal.server.core.config.factory.ConfigurableFactoryHelper

public class ConfigurableFactoryHelper extends Object
A utility class for creating objects using ConfigurableFactory.
  • 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 returns null 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

      public static ConfigurableFactory getFactory(String className)
      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 implements ConfigurableFactory, 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.