I have class Button in package "pl.components" and I created interface IButoon in package "pl.icomponents". I would like to create a button based on this interface. This button only has methods that are in the interface.
public class Button extends com.vaadin.ui.Button implements IButton
{
public String setEnabledRole(){}
public void setToolTip(String txt) {}
}
public interface IButton
{
public void setToolTip(String txt) {}
}
So, I guess when I do
IButton ibutton = new Button();
Then my ibutton will only be able to use setToolTip. The only problem I have to do is have classNameSpaces only. Because I want to do this for a few components. And I don't want to make a few ifs that check it. So far I have done something like that:
// classNamespace - example: pl.icomponents.IButton
private Object createClass(String classNamespace, Element xml)
{
if (classNamespace.contains("pl.icomponents."))
{
int lenght = classNamespace.length();
int lenght2 = "pl.icomponents.".length();
String interfaceName = classNamespace.substring(lenght2, lenght);
String className = interfaceName.substring(1);
classNamespace = "pl.components." + className;
Class<?> cls = Class.forName(classNamespace);
Object object = cls.newInstance();
Object iObject = cls.getInterfaces();
iObject = cls.newInstance();
return iObject;
}
}
Unfortunately, the method returns Object Button that has access to setEnabledRole and setToolTip.
Do you have any ideas? Maybe the "Class <?>" class has something like that? Unfortunately, I could not find anything.