private final Status getStatus()

in velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java [226:292]


    private final Status getStatus()
    {
        if (this.status == null)
        {
            if (getClassname() == null)
            {
                this.status = Status.NONE;
            }
            else
            {
                try
                {
                    // make sure the classname resolves to a class we have
                    Class clazz = ClassUtils.getClass(getClassname());

                    // try hard to ensure we have all necessary supporting classes
                    digForDependencies(clazz);

                    // create an instance to make sure we can do that
                    if (factoryClassname == null)
                    {
                        clazz.newInstance();
                    }
                    else
                    {
                        Class factory = ClassUtils.getClass(getFactoryClassname());
                        Method factoryMethod = ClassUtils.findFactoryMethod(factory, clazz);
                        if (factoryMethod == null)
                        {
                            String target = clazz.getSimpleName();
                            throw new IllegalArgumentException("Factory class hasn't any method named create" + target + "(), new" + target + "() or get" + target + "()");
                        }
                        Object instance = factoryMethod.invoke(null, new Object[]{});
                        if (instance == null)
                        {
                            throw new WrongMethodTypeException("Factory method '" + factoryMethod.toString() + "' returned null");
                        }
                        Class instanceClass = instance.getClass();
                        if (!clazz.isAssignableFrom(instanceClass))
                        {
                            throw new WrongMethodTypeException("Factory method '" + factoryMethod + "' is expected to return an instance of class '" + getClassname() + "'");
                        }
                    }

                    this.status = Status.VALID;
                    this.problem = null;
                }
                catch (ClassNotFoundException cnfe)
                {
                    this.status = Status.MISSING;
                    this.problem = cnfe;
                }
                catch (NoClassDefFoundError ncdfe)
                {
                    this.status = Status.UNSUPPORTED;
                    this.problem = ncdfe;
                }
                catch (Throwable t)
                {
                    // for all other problems...
                    this.status = Status.UNINSTANTIABLE;
                    this.problem = t;
                }
            }
        }
        return this.status;
    }