JBoss Rich Faces SVN: r15056 - root/framework/trunk/impl/src/main/java/org/ajax4jsf/event.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-07-30 06:06:57 -0400 (Thu, 30 Jul 2009)
New Revision: 15056
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java
Log:
use CacheManager destroy method to unregister and stop caches
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java 2009-07-30 10:05:32 UTC (rev 15055)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java 2009-07-30 10:06:57 UTC (rev 15056)
@@ -1,15 +1,11 @@
package org.ajax4jsf.event;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import java.util.Map.Entry;
-import javax.faces.context.FacesContext;
import javax.faces.event.SystemEvent;
import org.ajax4jsf.cache.Cache;
-import org.ajax4jsf.cache.CacheFactory;
import org.ajax4jsf.cache.CacheManager;
/**
@@ -20,40 +16,23 @@
@Override
public void init(SystemEvent event) {
-
-// CacheManager cacheManager = CacheManager.getInstance();
-// FacesContext facesContext = FacesContext.getCurrentInstance();
-//
-// Map<?,?> envMap = facesContext.getExternalContext().getInitParameterMap();
-// CacheFactory cacheFactory = cacheManager.getCacheFactory(envMap);
-// Cache cache = cacheFactory.createCache(envMap);
-//
-// if(cache != null) {
-// String cacheName = cache.getClass().getName();
-// cacheManager.registerCache(cacheName, cache);
-// cache.start();
-// }
-//
+ //TODO read configuration ??
}
- //stop and remove all caches instances
+
@Override
public void destroy(SystemEvent event) {
-
CacheManager cacheManager = CacheManager.getInstance();
Map <String, Cache> caches = cacheManager.getCaches();
- System.out.println("CacheInitializationListener.destroy()");
if(!caches.isEmpty()) {
-
- Iterator <Map.Entry<String, Cache>> iterator = caches.entrySet().iterator();
- while(iterator.hasNext()) {
- Entry <String, Cache> entry = iterator.next();
- Cache cache = entry.getValue();
- cache.stop();
- iterator.remove();
+ Set <String> cacheNames = caches.keySet();
+ for(String cacheName: cacheNames) {
+ try {
+ cacheManager.destroyCache(cacheName);
+ } catch (Exception e) {
+ looger.error("Error during stop cache " + cacheName, e);
+ }
}
-
}
-
- }
+ }
}
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java 2009-07-30 10:05:32 UTC (rev 15055)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java 2009-07-30 10:06:57 UTC (rev 15056)
@@ -7,6 +7,9 @@
import javax.faces.event.SystemEvent;
import javax.faces.event.SystemEventListener;
+import org.richfaces.util.RichfacesLogger;
+import org.slf4j.Logger;
+
/**
* framework initialization listener
* @author Anton Belevich
@@ -14,7 +17,8 @@
*/
public abstract class InitializationListener implements SystemEventListener {
-
+ protected static final Logger looger = RichfacesLogger.CACHE.getLogger();
+
public boolean isListenerForSource(Object source) {
return source instanceof Application ? true : false;
}
15 years, 5 months
JBoss Rich Faces SVN: r15055 - root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-07-30 06:05:32 -0400 (Thu, 30 Jul 2009)
New Revision: 15055
Removed:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/AbstractCacheFactory.java
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/CacheManager.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/EhCacheCacheFactory.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/JBossCacheCacheFactory.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/LRUMapCacheFactory.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/OSCacheCacheFactory.java
Log:
remove AbstractCacheFactory
Deleted: root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/AbstractCacheFactory.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/AbstractCacheFactory.java 2009-07-30 10:03:47 UTC (rev 15054)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/AbstractCacheFactory.java 2009-07-30 10:05:32 UTC (rev 15055)
@@ -1,34 +0,0 @@
-package org.ajax4jsf.cache;
-
-import java.util.Map;
-
-/**
- * @author Anton Belevich
- *
- */
-public abstract class AbstractCacheFactory implements CacheFactory {
-
- private RegisterCallback registerCallback;
-
- public Cache createCache(String cacheName, Map<?,?> env) {
- Cache cache = createCache(env);
- if(registerCallback != null) {
- if(cacheName == null) {
- cacheName = cache.getClass().getName();
- }
- registerCallback.register(cacheName, cache);
- }
- return cache;
- }
-
- public abstract Cache createCache(Map <?,?> env);
-
- public RegisterCallback getRegisterCallback() {
- return registerCallback;
- }
-
- public void setRegisterCallback(RegisterCallback registerCallback) {
- this.registerCallback = registerCallback;
- }
-
-}
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/CacheManager.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/CacheManager.java 2009-07-30 10:03:47 UTC (rev 15054)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/CacheManager.java 2009-07-30 10:05:32 UTC (rev 15055)
@@ -51,14 +51,6 @@
// Should this be a HashMap<String, WeakReference<Cache>>?
private final Map <String, Cache> caches = Collections.synchronizedMap(new HashMap<String, Cache>());
-
- private RegisterCallback _registerCallback = new RegisterCallback() {
-
- public void register(String cacheName, Cache cache) {
- registerCache(cacheName, cache);
- }
-
- };
/**
* Returns the singleton CacheManager
*/
@@ -74,7 +66,19 @@
caches.put(cacheName, cache);
}
- public AbstractCacheFactory getCacheFactory(Map env , boolean registerCacheOnCreate) {
+ public void createCache(String cacheName, Map <?,?> env) {
+ CacheFactory factory = getCacheFactory(env);
+ Cache cache = factory.createCache(env);
+ registerCache(cacheName, cache);
+ cache.start();
+ }
+
+ public void destroyCache(String cacheName) {
+ Cache cache = caches.remove(cacheName);
+ cache.stop();
+ }
+
+ public CacheFactory getCacheFactory(Map <?,?> env ) {
String[] factories;
String configuredFactoryName = findFactory(FACTORY_PROPERTY_NAME, env);
@@ -89,14 +93,10 @@
for (String factoryName : factories) {
try {
Class<?> spiClass = Class.forName(factoryName, true, loader);
- //CacheFactory cacheFactory = CacheFactory.class.cast(spiClass.newInstance());
- AbstractCacheFactory cacheFactory = AbstractCacheFactory.class.cast(spiClass.newInstance());
- if(registerCacheOnCreate) {
- cacheFactory.setRegisterCallback(_registerCallback);
- }
-
+ CacheFactory cacheFactory = CacheFactory.class.cast(spiClass.newInstance());
+
log.info("Selected [" + factoryName + "]");
-
+
return cacheFactory;
} catch (Throwable iae) {
//TODO log debug
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/EhCacheCacheFactory.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/EhCacheCacheFactory.java 2009-07-30 10:03:47 UTC (rev 15054)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/EhCacheCacheFactory.java 2009-07-30 10:05:32 UTC (rev 15055)
@@ -12,7 +12,7 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class EhCacheCacheFactory extends AbstractCacheFactory {
+public class EhCacheCacheFactory implements CacheFactory {
private static final Log log = LogFactory.getLog(EhCacheCacheFactory.class);
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/JBossCacheCacheFactory.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/JBossCacheCacheFactory.java 2009-07-30 10:03:47 UTC (rev 15054)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/JBossCacheCacheFactory.java 2009-07-30 10:05:32 UTC (rev 15055)
@@ -25,7 +25,7 @@
*/
//TODO - to doc - no max size eviction support
-public class JBossCacheCacheFactory extends AbstractCacheFactory {
+public class JBossCacheCacheFactory implements CacheFactory {
private org.jboss.cache.CacheFactory<String, Object> cacheFactory;
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/LRUMapCacheFactory.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/LRUMapCacheFactory.java 2009-07-30 10:03:47 UTC (rev 15054)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/LRUMapCacheFactory.java 2009-07-30 10:05:32 UTC (rev 15055)
@@ -32,7 +32,7 @@
* created 01.05.2007
*
*/
-public class LRUMapCacheFactory extends AbstractCacheFactory {
+public class LRUMapCacheFactory implements CacheFactory {
private static final Log log = LogFactory.getLog(LRUMapCacheFactory.class);
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/OSCacheCacheFactory.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/OSCacheCacheFactory.java 2009-07-30 10:03:47 UTC (rev 15054)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/OSCacheCacheFactory.java 2009-07-30 10:05:32 UTC (rev 15055)
@@ -38,7 +38,7 @@
* created 01.05.2007
*
*/
-public class OSCacheCacheFactory extends AbstractCacheFactory {
+public class OSCacheCacheFactory implements CacheFactory {
private static final Log log = LogFactory.getLog(OSCacheCacheFactory.class);
15 years, 5 months
JBoss Rich Faces SVN: r15054 - root/framework/trunk/api/src/main/java/org/ajax4jsf/cache.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-07-30 06:03:47 -0400 (Thu, 30 Jul 2009)
New Revision: 15054
Removed:
root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/RegisterCallback.java
Modified:
root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/CacheFactory.java
Log:
new cache initialization
Modified: root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/CacheFactory.java
===================================================================
--- root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/CacheFactory.java 2009-07-30 00:37:59 UTC (rev 15053)
+++ root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/CacheFactory.java 2009-07-30 10:03:47 UTC (rev 15054)
@@ -39,7 +39,7 @@
* @return an implementation specific Cache object.
* @throws CacheException if any error occurs.
*/
- public Cache createCache(String cacheName, Map<?, ?> env);
+ public Cache createCache(Map<?, ?> env);
}
Deleted: root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/RegisterCallback.java
===================================================================
--- root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/RegisterCallback.java 2009-07-30 00:37:59 UTC (rev 15053)
+++ root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/RegisterCallback.java 2009-07-30 10:03:47 UTC (rev 15054)
@@ -1,9 +0,0 @@
-package org.ajax4jsf.cache;
-
-import org.ajax4jsf.cache.Cache;
-
-public interface RegisterCallback {
-
- public void register(String cacheName, Cache cache);
-
-}
15 years, 5 months
JBoss Rich Faces SVN: r15053 - root/cdk/trunk/plugins/generator.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2009-07-29 20:37:59 -0400 (Wed, 29 Jul 2009)
New Revision: 15053
Modified:
root/cdk/trunk/plugins/generator/pom.xml
Log:
Modified: root/cdk/trunk/plugins/generator/pom.xml
===================================================================
--- root/cdk/trunk/plugins/generator/pom.xml 2009-07-29 22:08:51 UTC (rev 15052)
+++ root/cdk/trunk/plugins/generator/pom.xml 2009-07-30 00:37:59 UTC (rev 15053)
@@ -68,7 +68,7 @@
<dependency>
<groupId>org.jboss.el</groupId>
<artifactId>jboss-el</artifactId>
- <version>2.0.1.GA</version>
+ <version>1.0_02.CR4</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
15 years, 5 months
JBoss Rich Faces SVN: r15052 - in branches/community/3.3.X: framework/impl/src/main/java/org/ajax4jsf/util and 8 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2009-07-29 18:08:51 -0400 (Wed, 29 Jul 2009)
New Revision: 15052
Added:
branches/community/3.3.X/ui/beanValidator/src/main/config/faces/cloned-object-resolver.xml
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/ClonedObjectResolver.java
branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneObjectValidationTest.java
branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneableBean.java
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/util/CapturingELResolver.java
branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/WEB-INF/faces-config.xml
branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/pages/graphValidation.xhtml
branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/src/org/richfaces/example/GraphValidatorBean.java
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/UIGraphValidator.java
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/ObjectValidator.java
branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/validator/ValidableBean.java
Log:
Validate 'Cloneable' objects by cloned copy.
Modified: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java 2009-07-29 18:13:35 UTC (rev 15051)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java 2009-07-29 22:08:51 UTC (rev 15052)
@@ -389,16 +389,25 @@
void writeAttribute(String name, Object value, String property)
throws IOException {
- attributes.addAttribute(getNamespaceURI(), name, name, "id".equalsIgnoreCase(name)?"ID":"CDATA", value.toString());
- }
+ if (null != value) {
+ attributes.addAttribute(getNamespaceURI(), name, name, "id"
+ .equalsIgnoreCase(name) ? "ID" : "CDATA", value
+ .toString());
+ }
+ }
+
void writeURIAttribute(String name, Object value, String property)
throws IOException {
- String uri = value.toString();
- // TODO - perform encodeActionURL() or ???
- attributes.addAttribute(getNamespaceURI(), name, name, "CDATA", uri);
- }
+ if (null != value) {
+ String uri = value.toString();
+ // TODO - perform encodeActionURL() or ???
+ attributes.addAttribute(getNamespaceURI(), name, name, "CDATA",
+ uri);
+ }
+ }
+
/*
* (non-Javadoc)
*
Modified: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/util/CapturingELResolver.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/util/CapturingELResolver.java 2009-07-29 18:13:35 UTC (rev 15051)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/util/CapturingELResolver.java 2009-07-29 22:08:51 UTC (rev 15052)
@@ -31,7 +31,7 @@
* @since 3.3.0
*/
-class CapturingELResolver extends ELResolverWrapper {
+public class CapturingELResolver extends ELResolverWrapper {
private Object base;
@@ -43,7 +43,7 @@
@Override
public Object getValue(ELContext context, Object base, Object property) {
- if (base != null && property != null) {
+ if (/*base != null && */property != null) {
this.base = base;
this.property = property;
}
@@ -53,7 +53,7 @@
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
- if (base != null && property != null) {
+ if (/*base != null &&*/ property != null) {
this.base = base;
this.property = property;
}
Modified: branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/WEB-INF/faces-config.xml 2009-07-29 18:13:35 UTC (rev 15051)
+++ branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/WEB-INF/faces-config.xml 2009-07-29 22:08:51 UTC (rev 15052)
@@ -54,6 +54,6 @@
<managed-bean>
<managed-bean-name>graphValidatorBean</managed-bean-name>
<managed-bean-class>org.richfaces.example.GraphValidatorBean</managed-bean-class>
- <managed-bean-scope>request</managed-bean-scope>
+ <managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
Modified: branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/pages/graphValidation.xhtml
===================================================================
--- branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/pages/graphValidation.xhtml 2009-07-29 18:13:35 UTC (rev 15051)
+++ branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/pages/graphValidation.xhtml 2009-07-29 22:08:51 UTC (rev 15052)
@@ -13,22 +13,38 @@
<!-- Page header -->
<ui:define name="header">
<h1><rich:graphValidator> usage</h1>
+ <p>In that sampe <rich:graphValidator> component appends JSR-299 or Hibernate validators to all enclosed input components
+ that check restrictions for field values, and, in addition, validates whole bean.</p>
+ <p>JSF bean fields are annotated with @Min/@Max restrictions and getter for the 'total' attribute is also annotated by the @Max</p>
+ <p>As a result, even valid field values would make whole bean an invalid. For example, values '2','7','15' are valid for fields values but their sum exceed maximum total value '20'</p>
+ <p>Validator assignes new values to a cloned bean instance hence model is not updated with invalid values.</p>
</ui:define>
<!-- content -->
<ui:define name="content">
<h:form id="form">
<rich:graphValidator value="#{graphValidatorBean}" id="validator" profiles="javax.validation.groups.Default">
- <h:panelGrid columns="3">
- <h:outputLabel for="value0" value="First value:" />
+ <h:panelGrid columns="4">
+ <h:outputText value=""/>
+ <h:outputText value="Input"/>
+ <h:outputText value="Message"/>
+ <h:outputText value="Model value"/>
+
+ <h:outputLabel for="value0" value="First value, integer from 0 to 10:" />
<h:inputText id="value0" value="#{graphValidatorBean.first}" label="First" />
<rich:message for="value0"/>
- <h:outputLabel for="value1" value="Second value:" />
+ <h:outputText value="#{graphValidatorBean.first}"/>
+
+ <h:outputLabel for="value1" value="Second value,integer from 5 to 15:" />
<h:inputText id="value1" value="#{graphValidatorBean.second}" label="First" />
<rich:message for="value1"/>
- <h:outputLabel for="value2" value="Third value:" />
+ <h:outputText value="#{graphValidatorBean.second}"/>
+
+ <h:outputLabel for="value2" value="Third value,integer from 0 to 20:" />
<h:inputText id="value2" value="#{graphValidatorBean.third}" label="First" />
<rich:message for="value2"/>
- <h:outputLabel for="total" value="Total:" />
+ <h:outputText value="#{graphValidatorBean.third}"/>
+
+ <h:outputLabel for="total" value="Total, should be no more then 20:" />
<h:outputText id="total" value="#{graphValidatorBean.summ}"/>
</h:panelGrid>
<h:commandButton value="Submit" action="#{graphValidatorBean.action}"></h:commandButton>
Modified: branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/src/org/richfaces/example/GraphValidatorBean.java
===================================================================
--- branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/src/org/richfaces/example/GraphValidatorBean.java 2009-07-29 18:13:35 UTC (rev 15051)
+++ branches/community/3.3.X/samples/beanValidatorSample/src/main/webapp/src/org/richfaces/example/GraphValidatorBean.java 2009-07-29 22:08:51 UTC (rev 15052)
@@ -10,17 +10,17 @@
* @author asmirnov
*
*/
-public class GraphValidatorBean {
+public class GraphValidatorBean implements Cloneable {
@Min(0)
@Max(10)
private int first ;
- @Min(0)
- @Max(10)
+ @Min(5)
+ @Max(15)
private int second ;
@Min(0)
- @Max(10)
+ @Max(20)
private int third ;
private String actionResult;
@@ -94,4 +94,13 @@
setActionResult("Data have been saved");
return "ok";
}
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException {
+ GraphValidatorBean cloned = (GraphValidatorBean) super.clone();
+ cloned.first = this.first;
+ cloned.second = this.second;
+ cloned.third = this.third;
+ return cloned;
+ }
}
Added: branches/community/3.3.X/ui/beanValidator/src/main/config/faces/cloned-object-resolver.xml
===================================================================
--- branches/community/3.3.X/ui/beanValidator/src/main/config/faces/cloned-object-resolver.xml (rev 0)
+++ branches/community/3.3.X/ui/beanValidator/src/main/config/faces/cloned-object-resolver.xml 2009-07-29 22:08:51 UTC (rev 15052)
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd" version="1.2">
+ <application>
+ <el-resolver>org.richfaces.component.ClonedObjectResolver</el-resolver>
+ </application>
+</faces-config>
\ No newline at end of file
Property changes on: branches/community/3.3.X/ui/beanValidator/src/main/config/faces/cloned-object-resolver.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/ClonedObjectResolver.java
===================================================================
--- branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/ClonedObjectResolver.java (rev 0)
+++ branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/ClonedObjectResolver.java 2009-07-29 22:08:51 UTC (rev 15052)
@@ -0,0 +1,103 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.component.UIGraphValidator.GraphValidatorState;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ClonedObjectResolver extends ELResolver {
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext, java.lang.Object)
+ */
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ // Do nothing
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext, java.lang.Object)
+ */
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
+ Object base) {
+ // do nothing
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ Object cloned = resolveCloned(context, base, property);
+ if(null != cloned){
+ context.setPropertyResolved(true);
+ return cloned.getClass();
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public Object getValue(ELContext context, Object base, Object property) {
+ Object cloned = resolveCloned(context, base, property);
+ if(null != cloned){
+ context.setPropertyResolved(true);
+ }
+ return cloned;
+ }
+
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void setValue(ELContext context, Object base, Object property,
+ Object value) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public static Object resolveCloned(ELContext context, Object base, Object property){
+ if(null != base || null != property){
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+ for (String key : requestMap.keySet()) {
+ if(null != key && key.startsWith(UIGraphValidator.STATE_ATTRIBUTE_PREFIX)){
+ UIGraphValidator.GraphValidatorState state = (GraphValidatorState) requestMap.get(key);
+ if(state.isSame(base, property)){
+ return state.getCloned();
+ }
+ }
+ }
+ }
+ return null;
+ }
+}
Property changes on: branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/ClonedObjectResolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/UIGraphValidator.java
===================================================================
--- branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/UIGraphValidator.java 2009-07-29 18:13:35 UTC (rev 15051)
+++ branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/UIGraphValidator.java 2009-07-29 22:08:51 UTC (rev 15052)
@@ -21,15 +21,19 @@
package org.richfaces.component;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import javax.el.ELContext;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.component.EditableValueHolder;
+import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIInput;
@@ -46,10 +50,12 @@
import org.ajax4jsf.component.AjaxSupport;
import org.ajax4jsf.component.EventValueExpression;
import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.el.ELContextWrapper;
import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.event.AjaxListener;
import org.ajax4jsf.renderkit.AjaxContainerRenderer;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.util.CapturingELResolver;
import org.richfaces.event.ValidationEvent;
import org.richfaces.validator.HibernateValidator;
import org.richfaces.validator.FacesBeanValidator;
@@ -66,6 +72,11 @@
public static final String COMPONENT_FAMILY = "org.richfaces.GraphValidator";
+ public static final String STATE_ATTRIBUTE_PREFIX = COMPONENT_TYPE+NamingContainer.SEPARATOR_CHAR;
+
+
+
+
/**
* Get object for validation
*
@@ -121,11 +132,79 @@
public abstract void setType(String newvalue);
+ @Override
+ public void processDecodes(FacesContext context) {
+ GraphValidatorState validatorState = null;
+ // Detect value EL-expression.
+ ValueExpression valueExpression = getValueExpression("value");
+ if (null != valueExpression) {
+
+ Object value = getValue();
+ if (null !=value && value instanceof Cloneable) {
+ try {
+ ELContext initialELContext = context.getELContext();
+
+ CapturingELResolver capturingELResolver = new CapturingELResolver(initialELContext.getELResolver());
+ Class<?> type = valueExpression.getType(new ELContextWrapper(initialELContext, capturingELResolver));
+ if(null != type) {
+ validatorState = new GraphValidatorState();
+ Method method = value.getClass().getDeclaredMethod("clone");
+ method.setAccessible(true);
+ validatorState.cloned = method.invoke(value);
+ validatorState.base = capturingELResolver.getBase();
+ validatorState.property = capturingELResolver.getProperty();
+ validatorState.active = true;
+ context.getExternalContext().getRequestMap().put(getStateId(context), validatorState);
+ }
+ } catch (NoSuchMethodException e) {
+ // do nothing, that is really not possible.
+ } catch (InvocationTargetException e) {
+ throw new FacesException(e);
+ } catch (IllegalArgumentException e) {
+ // do nothing, that is really not possible.
+ } catch (IllegalAccessException e) {
+ throw new FacesException(e);
+ }
+ }
+ }
+ super.processDecodes(context);
+ if(null != validatorState){
+ validatorState.active = false;
+ }
+ }
+
+ protected String getStateId(FacesContext context) {
+ String stateId = STATE_ATTRIBUTE_PREFIX+getClientId(context);
+ return stateId;
+ }
+
+ protected GraphValidatorState getValidatorState(FacesContext context){
+ return (GraphValidatorState) context.getExternalContext().getRequestMap().get(getStateId(context));
+ }
+
@Override
+ public void processValidators(FacesContext context) {
+ GraphValidatorState validatorState = getValidatorState(context);
+ if(null != validatorState){
+ validatorState.active = true;
+ }
+ super.processValidators(context);
+ if(null != validatorState){
+ validatorState.active = false;
+ validateObject(context, validatorState.cloned);
+ context.getExternalContext().getRequestMap().remove(getStateId(context));
+ }
+ }
+
+ @Override
public void processUpdates(FacesContext context) {
super.processUpdates(context);
Object value = getValue();
+ validateObject(context, value);
+ }
+
+ private void validateObject(FacesContext context, Object value) {
if (null != value) {
Validator validator = context.getApplication().createValidator(getType());
if (validator instanceof GraphValidator) {
@@ -205,5 +284,76 @@
public boolean getRendersChildren() {
return true;
}
+
+ public static final class GraphValidatorState {
+ private boolean active = false;
+ private Object cloned;
+ private Object base;
+ private Object property;
+ /**
+ * @return the active
+ */
+ public boolean isActive() {
+ return active;
+ }
+ /**
+ * @param active the active to set
+ */
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+ /**
+ * @return the cloned
+ */
+ public Object getCloned() {
+ return cloned;
+ }
+ /**
+ * @param cloned the cloned to set
+ */
+ public void setCloned(Object cloned) {
+ this.cloned = cloned;
+ }
+ /**
+ * @return the base
+ */
+ public Object getBase() {
+ return base;
+ }
+ /**
+ * @param base the base to set
+ */
+ public void setBase(Object base) {
+ this.base = base;
+ }
+ /**
+ * @return the property
+ */
+ public Object getProperty() {
+ return property;
+ }
+ /**
+ * @param property the property to set
+ */
+ public void setProperty(Object property) {
+ this.property = property;
+ }
+
+ public boolean isSameBase(Object base){
+ return (null == base && null == this.base)||(base == this.base);
+ }
+
+ public boolean isSameProperty(Object property){
+ if(null == this.property){
+ return null == property;
+ } else {
+ return this.property.equals(property);
+ }
+ }
+
+ public boolean isSame(Object base, Object property){
+ return isSameBase(base)&& isSameProperty(property)&& active;
+ }
+ }
}
Modified: branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/ObjectValidator.java
===================================================================
--- branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/ObjectValidator.java 2009-07-29 18:13:35 UTC (rev 15051)
+++ branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/ObjectValidator.java 2009-07-29 22:08:51 UTC (rev 15052)
@@ -23,6 +23,7 @@
import org.ajax4jsf.el.ELContextWrapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.richfaces.component.ClonedObjectResolver;
public abstract class ObjectValidator {
@@ -323,6 +324,8 @@
private FacesContext facesContext;
+ private boolean clonedObject = false;
+
/**
* @param parent
* @param context
@@ -382,7 +385,13 @@
* java.lang.Object, java.lang.Object)
*/
public Object getValue(ELContext context, Object base, Object property) {
- Object value = parent.getValue(context, base, property);
+ Object value = ClonedObjectResolver.resolveCloned(context, base, property);
+ if(null != value){
+ this.clonedObject =true;
+ context.setPropertyResolved(true);
+ } else {
+ value = parent.getValue(context, base, property);
+ }
valuesStack.push(new BasePropertyPair(base, property));
return value;
}
@@ -411,6 +420,10 @@
public void setValue(ELContext context, Object base, Object property,
Object value) {
if (null != base && null != property) {
+ // TODO - detect value object from inderect references ( e.g. data table variables ).
+ if(this.clonedObject){
+ parent.setValue(context, base, property, value);
+ }
context.setPropertyResolved(true);
// For Arrays, Collection or Map use parent base and property.
BasePropertyPair basePropertyPair = lookupBeanProperty(new BasePropertyPair(
Added: branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneObjectValidationTest.java
===================================================================
--- branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneObjectValidationTest.java (rev 0)
+++ branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneObjectValidationTest.java 2009-07-29 22:08:51 UTC (rev 15052)
@@ -0,0 +1,76 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import javax.el.ValueExpression;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIGraphValidator.GraphValidatorState;
+import org.richfaces.component.html.HtmlGraphValidator;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class CloneObjectValidationTest extends AbstractAjax4JsfTestCase {
+
+ UIGraphValidator validator;
+ /**
+ * @param name
+ */
+ public CloneObjectValidationTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ validator = new HtmlGraphValidator();
+ validator.setId("validator");
+ facesContext.getViewRoot().getChildren().add(validator);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ validator = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIGraphValidator#processDecodes(javax.faces.context.FacesContext)}.
+ */
+ public void testProcessDecodesFacesContext() {
+ ValueExpression valueExpression = application.getExpressionFactory().createValueExpression(facesContext.getELContext(),"#{cloneableBean}", CloneableBean.class);
+ validator.setValueExpression("value", valueExpression);
+ CloneableBean bean = new CloneableBean();
+ facesContext.getExternalContext().getSessionMap().put("cloneableBean", bean);
+ validator.processDecodes(facesContext);
+ GraphValidatorState validatorState = validator.getValidatorState(facesContext);
+ assertNotNull(validatorState);
+ assertNotSame(bean, validatorState.getCloned());
+ assertEquals(bean, validatorState.getCloned());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIGraphValidator#processValidators(javax.faces.context.FacesContext)}.
+ */
+ public void testProcessValidatorsFacesContext() {
+ ValueExpression valueExpression = application.getExpressionFactory().createValueExpression(facesContext.getELContext(),"#{cloneableBean}", CloneableBean.class);
+ validator.setValueExpression("value", valueExpression);
+ CloneableBean bean = new CloneableBean();
+ facesContext.getExternalContext().getSessionMap().put("cloneableBean", bean);
+ validator.processDecodes(facesContext);
+ GraphValidatorState validatorState = validator.getValidatorState(facesContext);
+ assertNotNull(validatorState);
+ assertNotSame(bean, validatorState.getCloned());
+ validator.processValidators(facesContext);
+ assertTrue(facesContext.getRenderResponse());
+ assertTrue(facesContext.getMessages().hasNext());
+ }
+
+}
Property changes on: branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneObjectValidationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneableBean.java
===================================================================
--- branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneableBean.java (rev 0)
+++ branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneableBean.java 2009-07-29 22:08:51 UTC (rev 15052)
@@ -0,0 +1,81 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+
+import org.richfaces.validator.ValidableBean;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class CloneableBean implements Cloneable {
+
+ private ValidableBean testBean;
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((testBean == null) ? 0 : testBean.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof CloneableBean))
+ return false;
+ CloneableBean other = (CloneableBean) obj;
+ if (testBean == null) {
+ if (other.testBean != null)
+ return false;
+ } else if (!testBean.equals(other.testBean))
+ return false;
+ return true;
+ }
+
+ public CloneableBean() {
+ this.testBean = new ValidableBean();
+ }
+
+ /**
+ * @return the testBean
+ */
+ public ValidableBean getTestBean() {
+ return testBean;
+ }
+
+ /**
+ * @param testBean the testBean to set
+ */
+ public void setTestBean(ValidableBean testBean) {
+ this.testBean = testBean;
+ }
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException {
+ CloneableBean clone = (CloneableBean) super.clone();
+ clone.testBean = new ValidableBean();
+ clone.testBean.setFoo(testBean.getFoo());
+ clone.testBean.setArray(testBean.getArray().clone());
+ clone.testBean.setIntegerProperty(testBean.getIntegerProperty());
+ clone.testBean.setList(new ArrayList<String>(testBean.getList()));
+ clone.testBean.setMap(new HashMap<String, String>(testBean.getMap()));
+ return clone;
+ }
+}
Property changes on: branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/component/CloneableBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/validator/ValidableBean.java
===================================================================
--- branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/validator/ValidableBean.java 2009-07-29 18:13:35 UTC (rev 15051)
+++ branches/community/3.3.X/ui/beanValidator/src/test/java/org/richfaces/validator/ValidableBean.java 2009-07-29 22:08:51 UTC (rev 15052)
@@ -21,6 +21,7 @@
package org.richfaces.validator;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -35,7 +36,7 @@
* @author asmirnov
*
*/
-public class ValidableBean {
+public class ValidableBean implements Cloneable {
@Min(2)
@Max(5)
@@ -143,4 +144,59 @@
this.foo = foo;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(array);
+ result = prime * result + ((foo == null) ? 0 : foo.hashCode());
+ result = prime * result + integerProperty;
+ result = prime * result + ((list == null) ? 0 : list.hashCode());
+ result = prime * result + ((map == null) ? 0 : map.hashCode());
+ result = prime * result + ((text == null) ? 0 : text.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof ValidableBean))
+ return false;
+ ValidableBean other = (ValidableBean) obj;
+ if (!Arrays.equals(array, other.array))
+ return false;
+ if (foo == null) {
+ if (other.foo != null)
+ return false;
+ } else if (!foo.equals(other.foo))
+ return false;
+ if (integerProperty != other.integerProperty)
+ return false;
+ if (list == null) {
+ if (other.list != null)
+ return false;
+ } else if (!list.equals(other.list))
+ return false;
+ if (map == null) {
+ if (other.map != null)
+ return false;
+ } else if (!map.equals(other.map))
+ return false;
+ if (text == null) {
+ if (other.text != null)
+ return false;
+ } else if (!text.equals(other.text))
+ return false;
+ return true;
+ }
+
}
15 years, 5 months
JBoss Rich Faces SVN: r15051 - root/examples/trunk/components/core-demo/src/main/webapp/WEB-INF.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-07-29 14:13:35 -0400 (Wed, 29 Jul 2009)
New Revision: 15051
Modified:
root/examples/trunk/components/core-demo/src/main/webapp/WEB-INF/faces-config.xml
Log:
Modified: root/examples/trunk/components/core-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- root/examples/trunk/components/core-demo/src/main/webapp/WEB-INF/faces-config.xml 2009-07-29 18:12:48 UTC (rev 15050)
+++ root/examples/trunk/components/core-demo/src/main/webapp/WEB-INF/faces-config.xml 2009-07-29 18:13:35 UTC (rev 15051)
@@ -8,6 +8,10 @@
<system-event-listener-class>org.richfaces.resource.MapBasedResourceCodecListener</system-event-listener-class>
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
</system-event-listener -->
+ <system-event-listener>
+ <system-event-listener-class>org.ajax4jsf.event.CacheInitializationListener</system-event-listener-class>
+ <system-event-class>javax.faces.event.PreDestroyApplicationEvent</system-event-class>
+ </system-event-listener>
</application>
<managed-bean>
@@ -15,5 +19,6 @@
<managed-bean-class>org.richfaces.resource.TestResource2</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
+
</faces-config>
\ No newline at end of file
15 years, 5 months
JBoss Rich Faces SVN: r15050 - root/framework/trunk/api/src/main/java/org/ajax4jsf/cache.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-07-29 14:12:48 -0400 (Wed, 29 Jul 2009)
New Revision: 15050
Added:
root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/RegisterCallback.java
Log:
Added: root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/RegisterCallback.java
===================================================================
--- root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/RegisterCallback.java (rev 0)
+++ root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/RegisterCallback.java 2009-07-29 18:12:48 UTC (rev 15050)
@@ -0,0 +1,9 @@
+package org.ajax4jsf.cache;
+
+import org.ajax4jsf.cache.Cache;
+
+public interface RegisterCallback {
+
+ public void register(String cacheName, Cache cache);
+
+}
15 years, 5 months
JBoss Rich Faces SVN: r15049 - root/framework/trunk/api/src/main/java/org/ajax4jsf/cache.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-07-29 14:12:21 -0400 (Wed, 29 Jul 2009)
New Revision: 15049
Modified:
root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/CacheFactory.java
Log:
Modified: root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/CacheFactory.java
===================================================================
--- root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/CacheFactory.java 2009-07-29 18:11:42 UTC (rev 15048)
+++ root/framework/trunk/api/src/main/java/org/ajax4jsf/cache/CacheFactory.java 2009-07-29 18:12:21 UTC (rev 15049)
@@ -39,5 +39,7 @@
* @return an implementation specific Cache object.
* @throws CacheException if any error occurs.
*/
- public Cache createCache(Map<?, ?> env);
+ public Cache createCache(String cacheName, Map<?, ?> env);
+
+
}
15 years, 5 months
JBoss Rich Faces SVN: r15048 - root/framework/trunk/impl/src/main/java/org/richfaces/resource.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-07-29 14:11:42 -0400 (Wed, 29 Jul 2009)
New Revision: 15048
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
Log:
Modified: root/framework/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2009-07-29 18:11:06 UTC (rev 15047)
+++ root/framework/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2009-07-29 18:11:42 UTC (rev 15048)
@@ -40,6 +40,7 @@
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
+import org.ajax4jsf.cache.AbstractCacheFactory;
import org.ajax4jsf.cache.Cache;
import org.ajax4jsf.cache.CacheFactory;
import org.ajax4jsf.cache.CacheManager;
@@ -60,6 +61,8 @@
public static final String HANDLER_START_TIME_ATTRIBUTE = ResourceHandlerImpl.class.getName() +
":StartTime";
+ public static final String HANDLER_CACHE_NAME = ResourceHandlerImpl.class.getName() + ":CACHE";
+
private static final Logger LOGGER = RichfacesLogger.RESOURCE.getLogger();
//TODO - review - do we need this?
@@ -97,11 +100,9 @@
private void initializeCache(FacesContext facesContext) {
CacheManager cacheManager = CacheManager.getInstance();
- Map<?, ?> envMap = facesContext.getExternalContext().getInitParameterMap();
-
- CacheFactory cacheFactory = cacheManager.getCacheFactory(envMap);
- this.cache = cacheFactory.createCache(envMap);
- //TODO - who is responsible for caches starting/stopping?
+ Map<?,?> envMap = facesContext.getExternalContext().getInitParameterMap();
+ AbstractCacheFactory factory = cacheManager.getCacheFactory(envMap, true);
+ this.cache = factory.createCache(HANDLER_CACHE_NAME, envMap);
this.cache.start();
}
15 years, 5 months
JBoss Rich Faces SVN: r15047 - root/framework/trunk/impl/src/main/java/org/ajax4jsf/event.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-07-29 14:11:06 -0400 (Wed, 29 Jul 2009)
New Revision: 15047
Added:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java
Log:
Added: root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java (rev 0)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java 2009-07-29 18:11:06 UTC (rev 15047)
@@ -0,0 +1,59 @@
+package org.ajax4jsf.event;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.SystemEvent;
+
+import org.ajax4jsf.cache.Cache;
+import org.ajax4jsf.cache.CacheFactory;
+import org.ajax4jsf.cache.CacheManager;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class CacheInitializationListener extends InitializationListener {
+
+ @Override
+ public void init(SystemEvent event) {
+
+// CacheManager cacheManager = CacheManager.getInstance();
+// FacesContext facesContext = FacesContext.getCurrentInstance();
+//
+// Map<?,?> envMap = facesContext.getExternalContext().getInitParameterMap();
+// CacheFactory cacheFactory = cacheManager.getCacheFactory(envMap);
+// Cache cache = cacheFactory.createCache(envMap);
+//
+// if(cache != null) {
+// String cacheName = cache.getClass().getName();
+// cacheManager.registerCache(cacheName, cache);
+// cache.start();
+// }
+//
+ }
+
+ //stop and remove all caches instances
+ @Override
+ public void destroy(SystemEvent event) {
+
+ CacheManager cacheManager = CacheManager.getInstance();
+ Map <String, Cache> caches = cacheManager.getCaches();
+ System.out.println("CacheInitializationListener.destroy()");
+ if(!caches.isEmpty()) {
+
+ Iterator <Map.Entry<String, Cache>> iterator = caches.entrySet().iterator();
+ while(iterator.hasNext()) {
+ Entry <String, Cache> entry = iterator.next();
+ Cache cache = entry.getValue();
+ cache.stop();
+ iterator.remove();
+ }
+
+ }
+
+ }
+}
Added: root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java (rev 0)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java 2009-07-29 18:11:06 UTC (rev 15047)
@@ -0,0 +1,34 @@
+package org.ajax4jsf.event;
+
+import javax.faces.application.Application;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.faces.event.PreDestroyApplicationEvent;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
+/**
+ * framework initialization listener
+ * @author Anton Belevich
+ *
+ */
+public abstract class InitializationListener implements SystemEventListener {
+
+
+ public boolean isListenerForSource(Object source) {
+ return source instanceof Application ? true : false;
+ }
+
+ public void processEvent(SystemEvent event) throws AbortProcessingException {
+ if(event instanceof PostConstructApplicationEvent) {
+ init(event);
+ } else if(event instanceof PreDestroyApplicationEvent) {
+ destroy(event);
+ }
+ }
+
+ public abstract void init(SystemEvent event);
+
+ public abstract void destroy(SystemEvent event);
+
+}
15 years, 5 months