[jboss-dev-forums] [QA of JBoss Portal] - Injecting MC beans into the servlet context
julien@jboss.com
do-not-reply at jboss.com
Thu Jun 14 11:11:00 EDT 2007
- MC is able to pick beans from a factory.
- MC is able to inject beans into a Map.
given that we can have a bean factory that produces a POJO that has a Map as property. That Map is a wrapper around the ServletContext attributes.
| public class ServletContextAttributes
| {
| private final ServletContext context;
| public ServletContextAttributesInj(ServletContext context)
| {
| this.context = context;
| }
| public void setAttributes(Map attrs)
| {
| for (Iterator i = attrs.entrySet().iterator();i.hasNext();)
| {
| Map.Entry entry = (Map.Entry)i.next();
| String name = (String)entry.getKey();
| Object value = entry.getValue();
| context.setAttribute(name, value);
| }
| }
| }
|
For the bean factory one already exist in the test module : org.jboss.portal.test.framework.TestBeanFactory
Then at startup of the servlet context listener we would have something like:
| public void contextInitialized(ServletContextEvent event)
| {
| // Create wrapper that configures
| ServletContextAttributes attrs = new ServletContextAttributes(event.getServletContext());
|
| // Configure MC
| TestRuntimeContext runtimeContext = new TestRuntimeContext("jboss-beans.xml");
| runtimeContext.addBean("ServletContextAttributes", attrs);
| runtimeContext.start();
| }
|
and in jboss-beans.xml we would have something like :
| <deployment ...>
|
| ... <!-- Declare all beans that are wired like AuthorizationDomainRegistry, etc... -->
|
| <!-- That's one bean that interest us to be injected in the servlet context as an attribute -->
| <bean name="PortalObjectContainer" class="org.jboss.portal.core.impl.model.portal.PersistentPortalObjectContainer">
| <property name="sessionFactoryJNDIName">java:/SessionFactory</property>
| <property name="authorizationDomainRegistry"><inject bean="AuthorizationDomainRegistry"/></property>
| <property name="portalAuthorizationManagerFactory"><inject bean="AuthorizationManagerFactory"/></property>
| <property name="contentProviderRegistry"><inject bean="ContentProviderRegistry"/></property>
| </bean>
|
| <bean name="ServletContextAttributes" class="ServletContextAttributes">
| <constructor factoryMethod="getBean">
| <factory bean="BeanFactory"/>
| <parameter>ServletContextAttributes</parameter>
| </constructor>
| <property name="attributes">
| <map keyClass="java.lang.String">
| <entry>
| <key>PortalObjectContainer</key>
| <value><inject bean="PortalObjectContainer"/></value>
| </entry>
| </map>
| </property>
| </bean>
|
| </deployment>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4054428#4054428
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4054428
More information about the jboss-dev-forums
mailing list