[jboss-cvs] JBossAS SVN: r95938 - in projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier: util and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 2 19:17:05 EST 2009
Author: pete.muir at jboss.org
Date: 2009-11-02 19:17:05 -0500 (Mon, 02 Nov 2009)
New Revision: 95938
Added:
projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/DummyELResolver.java
projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/ForwardingELResolver.java
Removed:
projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/util/BeanManagers.java
Modified:
projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/WeldApplication.java
Log:
WELD-202, and use it in integration code
Added: projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/DummyELResolver.java
===================================================================
--- projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/DummyELResolver.java (rev 0)
+++ projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/DummyELResolver.java 2009-11-03 00:17:05 UTC (rev 95938)
@@ -0,0 +1,48 @@
+package org.jboss.weld.integration.webtier.jsf;
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+
+
+public class DummyELResolver extends ELResolver
+{
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base)
+ {
+ return null;
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
+ {
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property)
+ {
+ return null;
+ }
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property)
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
+ return false;
+ }
+
+ @Override
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ {
+
+ }
+
+}
Property changes on: projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/DummyELResolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/ForwardingELResolver.java
===================================================================
--- projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/ForwardingELResolver.java (rev 0)
+++ projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/ForwardingELResolver.java 2009-11-03 00:17:05 UTC (rev 95938)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.integration.webtier.jsf;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+
+public abstract class ForwardingELResolver extends ELResolver
+{
+
+ protected abstract ELResolver delegate();
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base)
+ {
+ return delegate().getCommonPropertyType(context, base);
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
+ {
+ return delegate().getFeatureDescriptors(context, base);
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property)
+ {
+ return delegate().getType(context, base, property);
+ }
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property)
+ {
+ return delegate().getValue(context, base, property);
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
+ return delegate().isReadOnly(context, base, property);
+ }
+
+ @Override
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ {
+ delegate().setValue(context, base, property, value);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return this == obj || delegate().equals(obj);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return delegate().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return delegate().toString();
+ }
+
+}
Property changes on: projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/ForwardingELResolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/WeldApplication.java
===================================================================
--- projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/WeldApplication.java 2009-11-03 00:15:23 UTC (rev 95937)
+++ projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/jsf/WeldApplication.java 2009-11-03 00:17:05 UTC (rev 95938)
@@ -17,11 +17,13 @@
package org.jboss.weld.integration.webtier.jsf;
import javax.el.ELContextListener;
+import javax.el.ELResolver;
import javax.el.ExpressionFactory;
import javax.enterprise.inject.spi.BeanManager;
import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletContext;
-import org.jboss.weld.integration.webtier.util.BeanManagers;
import org.jboss.weld.integration.webtier.util.Reflections;
/**
@@ -31,50 +33,72 @@
public class WeldApplication extends ForwardingApplication
{
- private static final ELContextListener[] EMPTY_LISTENERS = {};
+ private static class AdjustableELResolver extends ForwardingELResolver
+ {
+
+ private ELResolver delegate;
+
+ public void setDelegate(ELResolver delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ @Override
+ protected ELResolver delegate()
+ {
+ return delegate;
+ }
+ }
+
private final Application application;
private ExpressionFactory expressionFactory;
+ private AdjustableELResolver elResolver;
+ private boolean intialized;
public WeldApplication(Application application)
{
this.application = application;
- BeanManager beanManager = BeanManagers.getBeanManager();
- if (beanManager != null)
+ application.addELContextListener(Reflections.<ELContextListener>newInstance("org.jboss.weld.el.WeldELContextListener"));
+ elResolver = new AdjustableELResolver();
+ elResolver.setDelegate(new DummyELResolver());
+ application.addELResolver(elResolver);
+ }
+
+ private void init()
+ {
+ if (!intialized && beanManager() != null)
{
- application.addELContextListener(Reflections.<ELContextListener>newInstance("org.jboss.weld.el.WeldELContextListener"));
- application.addELResolver(beanManager.getELResolver());
+ elResolver.setDelegate(beanManager().getELResolver());
+ this.expressionFactory = beanManager().wrapExpressionFactory(application.getExpressionFactory());
}
}
@Override
protected Application delegate()
{
+ init();
return application;
}
@Override
public ExpressionFactory getExpressionFactory()
{
- // Application is multi-threaded, but no need to guard against races (re-
- // creating the cached expression factory doesn't matter) or liveness
- // (the value read by all threads will be the same)
- // We have to do this lazily as Mojarra hasn't set the ExpressionFactory
- // when the object is created
- if (this.expressionFactory == null)
+ init();
+ return expressionFactory;
+ }
+
+ private static BeanManager beanManager()
+ {
+ if (FacesContext.getCurrentInstance() != null && FacesContext.getCurrentInstance().getExternalContext().getContext() instanceof ServletContext)
{
- BeanManager beanManager = BeanManagers.getBeanManager();
- if (beanManager != null)
- {
- this.expressionFactory = beanManager.wrapExpressionFactory(delegate().getExpressionFactory());
- }
- else
- {
- // WB failed to initialize properly
- this.expressionFactory = delegate().getExpressionFactory();
- }
+ ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
+ return (BeanManager) servletContext.getAttribute(BeanManager.class.getName());
}
- return expressionFactory;
+ else
+ {
+ return null;
+ }
}
-
+
}
Deleted: projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/util/BeanManagers.java
===================================================================
--- projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/util/BeanManagers.java 2009-11-03 00:15:23 UTC (rev 95937)
+++ projects/weld-int/trunk/webtier/src/main/java/org/jboss/weld/integration/webtier/util/BeanManagers.java 2009-11-03 00:17:05 UTC (rev 95938)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.integration.webtier.util;
-
-import javax.enterprise.inject.spi.BeanManager;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-/**
- * @author pmuir
- *
- */
-public class BeanManagers
-{
-
- public static BeanManager getBeanManager()
- {
- try
- {
- InitialContext context = new InitialContext();
- return (BeanManager) context.lookup("java:app/BeanManager");
- }
- catch (NamingException e)
- {
- return null;
- }
-
- }
-
-}
More information about the jboss-cvs-commits
mailing list