in atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/plugins/activator/InvocatingBundleActivatorPlugin.java [29:121]
public void doBundleActivator(Class<?> bundleActivatorClass, Context context,
ClassLoader classLoader)
{
try
{
Object o = bundleActivatorClass.getConstructor().newInstance();
Method startMethod = null;
for (Method m : bundleActivatorClass.getMethods())
{
if (m.getName().equals("start") && m.getReturnType().equals(void.class)
&& m.getParameterCount() == 1
&& m.getParameters()[0].getParameterizedType().getTypeName().equals(
"org.osgi.framework.BundleContext"))
{
startMethod = m;
break;
}
}
if (startMethod != null)
{
InvocationHandler invocationHandler = new InvocationHandler()
{
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
try
{
if (method.getName().equals("registerService")
&& method.getParameterCount() == 3
&& method.getParameters()[1].getType().getTypeName().equals(
"java.lang.Object")
&& method.getParameters()[2].getType().getTypeName().equals(
"java.util.Dictionary"))
{
RegisterServiceCallImpl registerServiceCallImpl = new RegisterServiceCallImpl(
args);
if (registerServiceCallImpl.isValid())
{
context.addRegisterServiceCalls(
registerServiceCallImpl);
}
}
if (method.getName().equals("getBundleId"))
{
return 1L;
}
if (method.getName().equals("getVersion"))
{
return classLoader.loadClass(
"org.osgi.framework.Version").getConstructor(
int.class, int.class, int.class).newInstance(0, 0,
0);
}
else if (method.getReturnType().isInterface())
{
return Proxy.newProxyInstance(classLoader,
new Class[] { method.getReturnType() }, this);
}
}
catch (Exception e)
{
// expected
//e.printStackTrace();
}
return null;
}
};
Object p = Proxy.newProxyInstance(classLoader,
new Class[] {
classLoader.loadClass("org.osgi.framework.BundleContext") },
invocationHandler);
startMethod.invoke(o, p);
}
}
catch (Exception e)
{ // expected
// TODO Log and maybe show cp errors
// e.printStackTrace();
}
catch (Throwable e)
{
// TODO: handle exception
}
}