protected Object newInstance()

in jelly-tags/jface/src/main/java/org/apache/commons/jelly/tags/jface/preference/FieldEditorTag.java [65:106]


    protected Object newInstance(Class theClass, Map attributes, XMLOutput output)
        throws JellyTagException {

        if (theClass == null) {
            throw new JellyTagException("No Class available to create the FieldEditor");
        }

        String name = (String) attributes.get("name");
        if (name == null) {
            throw new MissingAttributeException("name");
        }

        String labelText = (String) attributes.get("labelText");
        if (labelText == null) {
            throw new MissingAttributeException("labelText");
        }

        Composite parentComposite = (Composite) attributes.get("parentComposite");
        if (parentComposite == null) {
            throw new MissingAttributeException("parentComposite");
        }

        // let's try to call a constructor
        try {
            Class[] types = { String.class, String.class, Composite.class };
            Constructor constructor = theClass.getConstructor(types);
            if (constructor != null) {
                Object[] arguments = { name, labelText, parentComposite };
                return constructor.newInstance(arguments);
            }
            return theClass.getConstructor().newInstance();

        } catch (NoSuchMethodException e) {
            throw new JellyTagException(e);
        } catch (InstantiationException e) {
            throw new JellyTagException(e);
        } catch (IllegalAccessException e) {
            throw new JellyTagException(e);
        } catch (InvocationTargetException e) {
            throw new JellyTagException(e);
        }
    }