For instance:

I want to get a configured web-bean instance by class name in php file 
below:
=========================================
<?php
 echo java_bean("com.mycompany.MyBean");
?>
=========================================
package com.mycompany;
@Component
// no @Singleton
public class MyBean {
    private String greetings = "Hello world.";
    public MyBean() {
    }
    public String getGreetings() {
        return greetings;
    }
}
=========================================
It won't work because java_bean() method only accept a singleton bean name.


I tried to add a static method in com.caucho.quercus.lib.ResinModule like 
this:
=========================================
public class ResinModule extends AbstractQuercusModule {
    ...
 public static Object webbeans(String className)
 {
  System.out.println(className);
  WebBeansContainer _webBeans = WebBeansContainer.create();

  try {
   Class clazz = Class.forName(className);

    ComponentFactory component = _webBeans.resolveByType(clazz);

     if (component == null) {
      component = _webBeans.createTransient(clazz);
     }
     return component.get();
  } catch (Exception t) {
   t.printStackTrace(System.out);
   return null;
  }
 }

    ...
}
=========================================
<?php
 echo webbeans("com.mycompany.MyBean");
?>
=========================================


When refresh the php page, ResinModule cannot find the class, printing 
stacktrace:

--------------------------------------------------------------------
com.mycompany.MyBean
java.lang.ClassNotFoundException: com.mycompany.MyBean
 at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:169)
 at com.caucho.quercus.lib.ResinModule.webbeans(ResinModule.java:131)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at com.caucho.quercus.module.StaticFunction.invoke(StaticFunction.java:129)
 at com.caucho.quercus.env.JavaInvoker.callMethod(JavaInvoker.java:604)
 at com.caucho.quercus.env.JavaInvoker.call(JavaInvoker.java:539)
 at com.caucho.quercus.expr.FunctionExpr.evalImpl(FunctionExpr.java:182)
 at com.caucho.quercus.expr.FunctionExpr.eval(FunctionExpr.java:126)
 at com.caucho.quercus.expr.MethodCallExpr.eval(MethodCallExpr.java:92)
 at com.caucho.quercus.program.EchoStatement.execute(EchoStatement.java:57)
 at 
com.caucho.quercus.program.BlockStatement.execute(BlockStatement.java:99)
 at 
com.caucho.quercus.program.QuercusProgram.execute(QuercusProgram.java:239)
 at com.caucho.quercus.page.InterpretedPage.execute(InterpretedPage.java:61)
 at com.caucho.quercus.page.QuercusPage.executeTop(QuercusPage.java:119)
 at 
com.caucho.quercus.servlet.ResinQuercusServlet.service(ResinQuercusServlet.java:146)
 at 
com.caucho.quercus.servlet.QuercusServlet.service(QuercusServlet.java:353)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:91)
 at 
com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
 at 
com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:97)
 at 
com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:266)
 at 
com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:280)
 at 
com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:108)
 at 
org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:139)
 ....


It seems ResinModule runs in the Resin container and will not load classes 
in any webapp's library,
and  the WebBeansContainer only maintains singleton component instances and 
save them in
"private HashMap<String,ComponentImpl> _namedComponentMap".



_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to