New file |
0,0 → 1,65 |
package org.mentacontainer.impl; |
|
import java.lang.reflect.InvocationTargetException; |
import java.lang.reflect.Method; |
|
import org.mentacontainer.Component; |
import org.mentacontainer.util.FindMethod; |
|
public class GenericComponent implements Component { |
|
private final Object factory; |
|
private final String name; |
|
private final Method method; |
|
public GenericComponent(String name, Object factory, String methodName) { |
|
this.name = name; |
|
this.factory = factory; |
|
try { |
|
this.method = FindMethod.getMethod(factory.getClass(), methodName, new Class[] { }); |
|
this.method.setAccessible(true); |
|
} catch(Exception e) { |
|
throw new RuntimeException(e); |
} |
} |
|
public Object getInstance() throws InstantiationException { |
|
try { |
|
return method.invoke(factory, (Object[]) null); |
|
} catch(InvocationTargetException e) { |
|
throw new InstantiationException("InvocationTargetException: " + method.getName() + " / " + e.getMessage()); |
|
} catch(IllegalAccessException e) { |
|
throw new InstantiationException("IllegalAccessException: " + method.getName() + " / " + e.getMessage()); |
} |
} |
|
public String getName() { return name; } |
|
public Component addInitValue(Object value) { |
|
throw new UnsupportedOperationException(); |
} |
|
public Component addProperty(String name, Object value) { |
|
throw new UnsupportedOperationException(); |
} |
|
public boolean isSingleton() { return false; } |
|
} |