// Get the component class name
final String classname = tag.getAttributes().getString("class");
if ((classname == null) || (classname.trim().length() == 0))
{
throw new MarkupException("Tag <wicket:component> must have attribute 'class'");
}
// construct the component. It must have a constructor with a single
// String (componentId) parameter.
final Component component;
try
{
// Load the class. In case a Groovy Class Resolver has been provided,
// the name might be a Groovy file.
// Note: Spring based components are not supported this way. May be we
// should provide a ComponentFactory like we provide a PageFactory.
final Class<?> componentClass = container.getSession()
.getClassResolver()
.resolveClass(classname);
final Constructor<?> constructor = componentClass.getConstructor(new Class[] { String.class });
component = (Component)constructor.newInstance(componentId);
}
catch (ClassNotFoundException e)
{
throw new MarkupException("Unable to create Component from wicket tag: Cause: " +
e.getMessage());
}
catch (NoSuchMethodException e)
{
throw new MarkupException("Unable to create Component from wicket tag: Cause: " +
e.getMessage());
}
catch (InvocationTargetException e)
{
throw new MarkupException("Unable to create Component from wicket tag: Cause: " +
e.getMessage());
}
catch (IllegalAccessException e)
{
throw new MarkupException("Unable to create Component from wicket tag: Cause: " +
e.getMessage());
}
catch (InstantiationException e)
{
throw new MarkupException("Unable to create Component from wicket tag: Cause: " +
e.getMessage());
}
catch (ClassCastException e)
{
throw new MarkupException("Unable to create Component from wicket tag: Cause: " +
e.getMessage());
}
catch (SecurityException e)
{
throw new MarkupException("Unable to create Component from wicket tag: Cause: " +
e.getMessage());
}
// Get all remaining attributes and invoke the component's setters
for (Map.Entry<String, Object> entry : tag.getAttributes().entrySet())