Author: nbelaevski
Date: 2008-04-25 12:53:51 -0400 (Fri, 25 Apr 2008)
New Revision: 8199
Modified:
trunk/framework/impl/src/main/java/org/richfaces/skin/AbstractChainableSkinImpl.java
trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java
Log:
Skins implementation refeactored
Modified:
trunk/framework/impl/src/main/java/org/richfaces/skin/AbstractChainableSkinImpl.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/skin/AbstractChainableSkinImpl.java 2008-04-25
16:31:12 UTC (rev 8198)
+++
trunk/framework/impl/src/main/java/org/richfaces/skin/AbstractChainableSkinImpl.java 2008-04-25
16:53:51 UTC (rev 8199)
@@ -61,9 +61,57 @@
return skin;
}
+
+ protected Object localResolveSkinParameter(FacesContext context, String name) {
+ return super.resolveSkinParameter(context, name);
+ }
+
+ protected boolean localContainsProperty(FacesContext context, String name) {
+ return super.containsProperty(name);
+ }
- protected Object resolveSkinParameter(FacesContext context, String name, int[]
singleInt) {
- Object object = super.resolveSkinParameter(context, name);
+ private static abstract class Operation {
+ public Object doChainedCall(FacesContext context, AbstractChainableSkinImpl impl, String
name, int[] singleInt) {
+ return impl.executeOperation(context, this, name, singleInt);
+ }
+
+ public abstract Object doLocalCall(FacesContext context, AbstractChainableSkinImpl impl,
String name);
+
+ public abstract Object doExternalCall(FacesContext context, Skin impl, String name);
+ }
+
+ private static final Operation RESOLVE = new Operation() {
+
+ public Object doExternalCall(FacesContext context, Skin impl, String name) {
+ //TODO add warning because substitution can work incorrect and cyclic references
+ //won't be caught
+ return impl.getParameter(context, name);
+ }
+
+ public Object doLocalCall(FacesContext context, AbstractChainableSkinImpl impl, String
name) {
+ return impl.localResolveSkinParameter(context, name);
+ }
+
+ };
+
+ private static final Operation CONTAINS = new Operation() {
+
+ private Object wrapBoolean(boolean value) {
+ return value ? Boolean.TRUE : null;
+ }
+
+ public Object doExternalCall(FacesContext context, Skin impl, String name) {
+ return wrapBoolean(impl.containsProperty(name));
+ }
+
+ public Object doLocalCall(FacesContext context, AbstractChainableSkinImpl impl, String
name) {
+ return wrapBoolean(impl.localContainsProperty(context, name));
+ }
+
+ };
+
+ protected Object executeOperation(FacesContext context, Operation operation, String
name, int[] singleInt) {
+ Object object = operation.doLocalCall(context, this, name);
if (object == null) {
Skin baseSkin = getBaseSkin(context);
if (baseSkin != null) {
@@ -75,9 +123,9 @@
Messages.SKIN_CYCLIC_REFERENCE, name));
}
- object = skinImpl.resolveSkinParameter(context, name, singleInt);
+ object = operation.doChainedCall(context, skinImpl, name, singleInt);
} else {
- object = baseSkin.getParameter(context, name);
+ object = operation.doExternalCall(context, baseSkin, name);
}
}
}
@@ -85,38 +133,23 @@
return object;
}
+ protected Object resolveSkinParameter(FacesContext context, String name, int[]
singleInt) {
+ return executeOperation(context, RESOLVE, name, singleInt);
+ }
+
protected boolean containsProperty(FacesContext context, String name, int[]
singleInt) {
- boolean contains = super.containsProperty(name);
- if (!contains) {
- Skin baseSkin = getBaseSkin(context);
- if (baseSkin != null) {
- if (baseSkin instanceof AbstractChainableSkinImpl) {
- AbstractChainableSkinImpl skinImpl = (AbstractChainableSkinImpl) baseSkin;
-
- if (singleInt[0]++ > 1000) {
- throw new FacesException(Messages.getMessage(
- Messages.SKIN_CYCLIC_REFERENCE, name));
- }
-
- contains = skinImpl.containsProperty(context, name, singleInt);
- } else {
- contains = baseSkin.containsProperty(name);
- }
- }
- }
-
- return contains;
+ return Boolean.TRUE.equals(executeOperation(context, CONTAINS, name, singleInt));
}
protected Object resolveSkinParameter(FacesContext context, String name) {
int[] singleInt = new int[] {0};
- Object resolvedParameter = getValueReference(context, resolveSkinParameter(context,
name, singleInt));
+ Object resolvedParameter = resolveSkinParameter(context, name, singleInt);
while (resolvedParameter instanceof String) {
String string = (String) resolvedParameter;
if (string.length() > 0 && string.charAt(0) == '&') {
singleInt[0]++;
- resolvedParameter = getValueReference(context, resolveSkinParameter(context,
string.substring(1), singleInt));
+ resolvedParameter = resolveSkinParameter(context, string.substring(1), singleInt);
if (resolvedParameter == null) {
throw new FacesException(Messages.getMessage(
Messages.SKIN_ILLEGAL_REFERENCE, name));
Modified: trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java 2008-04-25
16:31:12 UTC (rev 8198)
+++ trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java 2008-04-25
16:53:51 UTC (rev 8199)
@@ -33,13 +33,13 @@
import javax.el.ELContext;
import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.context.FacesContext;
import javax.faces.el.ReferenceSyntaxException;
-import javax.faces.el.ValueBinding;
import org.ajax4jsf.Messages;
import org.ajax4jsf.resource.util.URLToStreamHelper;
@@ -94,9 +94,9 @@
private Properties defaultSkinProperties = null;
private String skinName = null;
- private ValueBinding skinBinding = null;
+ private ValueExpression skinBinding = null;
private String baseSkinName = null;
- private ValueBinding baseSkinBinding = null;
+ private ValueExpression baseSkinBinding = null;
private static final Log log = LogFactory.getLog(SkinFactoryImpl.class);
private static final String A4J_BASE_SKIN_PARAMETER =
"org.ajax4jsf.BASE_SKIN";
@@ -198,7 +198,7 @@
*/
protected Object getSkinOrName(FacesContext context, boolean useBase) {
// Detect skin name
- ValueBinding binding;
+ ValueExpression binding;
String skin;
synchronized (this) {
@@ -232,8 +232,9 @@
}
if (ELUtils.isValueReference(currentSkinName)) {
// For EL expression as skin name
- binding = context.getApplication().createValueBinding(
- currentSkinName);
+ binding = context.getApplication().getExpressionFactory().
+ createValueExpression(context.getELContext(),
+ currentSkinName, Object.class);
} else {
skin = currentSkinName;
}
@@ -250,7 +251,7 @@
// }
}
if (binding != null) {
- return binding.getValue(context);
+ return binding.getValue(context.getELContext());
} else {
return skin;
}