Author: nbelaevski
Date: 2008-04-25 15:39:30 -0400 (Fri, 25 Apr 2008)
New Revision: 8202
Added:
trunk/framework/impl/src/main/java/org/richfaces/skin/DefaultSkinImpl.java
Modified:
trunk/framework/impl/src/main/java/org/richfaces/skin/AbstractChainableSkinImpl.java
trunk/framework/impl/src/main/java/org/richfaces/skin/BaseSkinImpl.java
trunk/framework/impl/src/main/java/org/richfaces/skin/BasicSkinImpl.java
trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java
trunk/framework/impl/src/main/java/org/richfaces/skin/SkinImpl.java
Log:
Skins implementation refeactored again, several issues fixed, tests added
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
19:39:22 UTC (rev 8201)
+++
trunk/framework/impl/src/main/java/org/richfaces/skin/AbstractChainableSkinImpl.java 2008-04-25
19:39:30 UTC (rev 8202)
@@ -35,39 +35,18 @@
public abstract class AbstractChainableSkinImpl extends BasicSkinImpl {
- protected SkinFactoryImpl factory;
-
- AbstractChainableSkinImpl(Map properties, SkinFactoryImpl factory) {
+ AbstractChainableSkinImpl(Map properties) {
super(properties);
- this.factory = factory;
}
- protected Skin getBaseSkin(FacesContext context) {
- Object object = getLocalParameter(context, Skin.baseSkin);
- boolean base = isBase();
- Skin skin = null;
-
- if (object != null) {
- skin = factory.getSkinByName(context, object, base);
- }
-
- if (skin == null) {
- if (base) {
- skin = factory.getDefaultSkin(context);
- } else {
- skin = factory.getBaseSkin(context);
- }
- }
-
- return skin;
- }
+ protected abstract Skin getBaseSkin(FacesContext context);
protected Object localResolveSkinParameter(FacesContext context, String name) {
- return super.resolveSkinParameter(context, name);
+ return getSkinParams().get(name);
}
protected boolean localContainsProperty(FacesContext context, String name) {
- return super.containsProperty(name);
+ return getSkinParams().containsKey(name);
}
private static abstract class Operation {
@@ -111,18 +90,17 @@
};
protected Object executeOperation(FacesContext context, Operation operation, String
name, int[] singleInt) {
+ if (singleInt[0]++ > 1000) {
+ throw new FacesException(Messages.getMessage(
+ Messages.SKIN_CYCLIC_REFERENCE, name));
+ }
+
Object object = operation.doLocalCall(context, this, name);
if (object == null) {
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));
- }
-
object = operation.doChainedCall(context, skinImpl, name, singleInt);
} else {
object = operation.doExternalCall(context, baseSkin, name);
@@ -148,7 +126,6 @@
while (resolvedParameter instanceof String) {
String string = (String) resolvedParameter;
if (string.length() > 0 && string.charAt(0) == '&') {
- singleInt[0]++;
resolvedParameter = resolveSkinParameter(context, string.substring(1), singleInt);
if (resolvedParameter == null) {
throw new FacesException(Messages.getMessage(
@@ -169,5 +146,14 @@
return containsProperty(FacesContext.getCurrentInstance(), name, new int[] {0});
}
- protected abstract boolean isBase();
+ protected int computeHashCode(FacesContext context) {
+ int hash = super.computeHashCode(context);
+ Skin baseSkin = getBaseSkin(context);
+ if (baseSkin != null) {
+ hash = 31*hash + baseSkin.hashCode(context);
+ }
+
+ return hash;
+ }
+
}
Modified: trunk/framework/impl/src/main/java/org/richfaces/skin/BaseSkinImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/skin/BaseSkinImpl.java 2008-04-25
19:39:22 UTC (rev 8201)
+++ trunk/framework/impl/src/main/java/org/richfaces/skin/BaseSkinImpl.java 2008-04-25
19:39:30 UTC (rev 8202)
@@ -23,6 +23,8 @@
import java.util.Map;
+import javax.faces.context.FacesContext;
+
/**
* @author nick belaevski
* @since 3.2
@@ -30,13 +32,27 @@
public class BaseSkinImpl extends AbstractChainableSkinImpl {
+ private SkinFactoryImpl factoryImpl;
+
BaseSkinImpl(Map properties, SkinFactoryImpl factory) {
- super(properties, factory);
+ super(properties);
+
+ this.factoryImpl = factory;
}
- @Override
- protected boolean isBase() {
- return true;
+ protected Skin getBaseSkin(FacesContext context) {
+ Object object = getLocalParameter(context, Skin.baseSkin);
+ Skin skin = null;
+
+ if (object != null) {
+ skin = factoryImpl.getSkinByName(context, object, true);
+ }
+
+ if (skin == null) {
+ skin = factoryImpl.getDefaultSkin(context);
+ }
+
+ return skin;
}
}
Modified: trunk/framework/impl/src/main/java/org/richfaces/skin/BasicSkinImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/skin/BasicSkinImpl.java 2008-04-25
19:39:22 UTC (rev 8201)
+++ trunk/framework/impl/src/main/java/org/richfaces/skin/BasicSkinImpl.java 2008-04-25
19:39:30 UTC (rev 8202)
@@ -39,7 +39,7 @@
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:59:41 $
*
*/
-public class BasicSkinImpl implements Skin {
+public abstract class BasicSkinImpl implements Skin {
public static final String RENDER_KIT_PARAMETER = "render.kit";
@@ -55,6 +55,10 @@
BasicSkinImpl(Map properties) {
this.skinParams = properties;
}
+
+ protected Map<String, Object> getSkinParams() {
+ return skinParams;
+ }
/* (non-Javadoc)
* @see org.richfaces.skin.Skin#getRenderKitId(javax.faces.context.FacesContext)
@@ -85,14 +89,8 @@
return getValueReference(context, skinParams.get(name));
}
- protected Object resolveSkinParameter(FacesContext context, String name) {
- return skinParams.get(name);
- }
+ protected abstract Object resolveSkinParameter(FacesContext context, String name);
- protected Skin getBaseSkin(FacesContext context) {
- return null;
- }
-
/**
* Calculate concrete value for property - if it stored as @see ValueBinding ,
* return interpreted value.
@@ -112,7 +110,19 @@
public String toString() {
return this.getClass().getSimpleName() + ": " + skinParams.toString();
}
+
+ protected int computeHashCode(FacesContext context) {
+ int hash = 0;
+ for (Iterator iter = skinParams.keySet().iterator(); iter.hasNext();) {
+ String key = (String) iter.next();
+ Object parameter = getParameter(context,key);
+ hash = 31*hash + key.hashCode();
+ hash = 31*hash + (parameter != null ? parameter.hashCode() : 0);
+ }
+ return hash;
+ }
+
/* (non-Javadoc)
* @see org.richfaces.skin.Skin#hashCode(javax.faces.context.FacesContext)
*/
@@ -130,28 +140,11 @@
Integer requestCode = (Integer) map.get(this);
if(null == requestCode){
- int hash = 0;
- for (Iterator iter = skinParams.keySet().iterator(); iter.hasNext();) {
- String key = (String) iter.next();
- Object parameter = getParameter(context,key);
- hash = 31*hash + key.hashCode();
- hash = 31*hash + (parameter != null ? parameter.hashCode() : 0);
- }
-
- Skin baseSkin = getBaseSkin(context);
- if (baseSkin != null) {
- hash = 31*hash + baseSkin.hashCode(context);
- }
-
- requestCode = new Integer(hash);
+ requestCode = new Integer(computeHashCode(context));
// store hash for this skin as request-skope parameter - not calculate on next calls
for same request
map.putIfAbsent(this, requestCode);
}
return requestCode.intValue();
}
- public boolean containsProperty(String name) {
- return skinParams.containsKey(name);
- }
-
}
Added: trunk/framework/impl/src/main/java/org/richfaces/skin/DefaultSkinImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/skin/DefaultSkinImpl.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/richfaces/skin/DefaultSkinImpl.java 2008-04-25
19:39:30 UTC (rev 8202)
@@ -0,0 +1,42 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.skin;
+
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author nick belaevski
+ * @since 3.2
+ */
+
+public class DefaultSkinImpl extends AbstractChainableSkinImpl {
+
+ DefaultSkinImpl(Map properties) {
+ super(properties);
+ }
+
+ protected Skin getBaseSkin(FacesContext context) {
+ return null;
+ }
+}
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
19:39:22 UTC (rev 8201)
+++ trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java 2008-04-25
19:39:30 UTC (rev 8202)
@@ -303,13 +303,16 @@
sourceProperties.put(name, skinParams);
}
+ BasicSkinImpl skinImpl;
if (DEFAULT_SKIN_NAME.equals(name)) {
- return new BasicSkinImpl(skinParams);
+ skinImpl = new DefaultSkinImpl(skinParams);
} else if (isBase) {
- return new BaseSkinImpl(skinParams, this);
+ skinImpl = new BaseSkinImpl(skinParams, this);
} else {
- return new SkinImpl(skinParams, this);
+ skinImpl = new SkinImpl(skinParams, this);
}
+
+ return skinImpl;
}
/**
Modified: trunk/framework/impl/src/main/java/org/richfaces/skin/SkinImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/skin/SkinImpl.java 2008-04-25
19:39:22 UTC (rev 8201)
+++ trunk/framework/impl/src/main/java/org/richfaces/skin/SkinImpl.java 2008-04-25
19:39:30 UTC (rev 8202)
@@ -23,18 +23,35 @@
import java.util.Map;
+import javax.faces.context.FacesContext;
+
/**
* @author nick belaevski
* @since 3.2
*/
public class SkinImpl extends AbstractChainableSkinImpl {
- SkinImpl(Map properties, SkinFactoryImpl factory) {
- super(properties, factory);
+ private SkinFactoryImpl factoryImpl;
+
+ SkinImpl(Map properties, SkinFactoryImpl factoryImpl) {
+ super(properties);
+
+ this.factoryImpl = factoryImpl;
}
- protected boolean isBase() {
- return false;
+ protected Skin getBaseSkin(FacesContext context) {
+ Object object = getLocalParameter(context, Skin.baseSkin);
+ Skin skin = null;
+
+ if (object != null) {
+ skin = factoryImpl.getSkinByName(context, object, false);
+ }
+
+ if (skin == null) {
+ skin = factoryImpl.getBaseSkin(context);
+ }
+
+ return skin;
}
}