myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r919198 - in /myfaces/extensions/scripting/trunk/core: core/src/main/java/org/apache/myfaces/scripting/api/ core/src/main/java/org/apache/myfaces/scripting/refresh/ core/src/test/java/org/apache/myfaces/scripting/core/refreshContext/ myface...
Date Thu, 04 Mar 2010 22:05:35 GMT
Author: werpu
Date: Thu Mar  4 22:05:34 2010
New Revision: 919198

URL: http://svn.apache.org/viewvc?rev=919198&view=rev
Log:
https://issues.apache.org/jira/browse/EXTSCRIPT-86

Dynamic component system events now work...

Added:
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ListenerForAnnotationHandler.java
  (with props)
Modified:
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/AnnotationScanListener.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/RefreshContext.java
    myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/scripting/core/refreshContext/RefreshContextTest.java
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/AnnotationScanListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/AnnotationScanListener.java?rev=919198&r1=919197&r2=919198&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/AnnotationScanListener.java
(original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/AnnotationScanListener.java
Thu Mar  4 22:05:34 2010
@@ -39,6 +39,15 @@
     public boolean supportsAnnotation(String annotation);
 
     /**
+     * returns true if the annotation marked by the incoming parameter is supported by this
scanner
+     *
+     * @param annotation the supported annotation as neutral string representation of its
class
+     * @return in case of support
+     */
+    public boolean supportsAnnotation(Class annotation);
+
+
+    /**
      * class file registration of the supported annotation
      *
      * @param clazz          the class to be registered

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/RefreshContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/RefreshContext.java?rev=919198&r1=919197&r2=919198&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/RefreshContext.java
(original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/RefreshContext.java
Thu Mar  4 22:05:34 2010
@@ -80,7 +80,6 @@
 
     private MasterDependencyRegistry _dependencyRegistry = new MasterDependencyRegistry();
 
-    
     /**
      * we keep a 10 minutes timeout period to keep the performance in place
      */
@@ -120,8 +119,6 @@
         }
     }
 
-
-
     /**
      * adds a new entry into our taint log
      * which allows us to access tainting data
@@ -154,13 +151,29 @@
     }
 
     /**
+     * returns the last noOfEntries entries in the taint history
+     *
+     * @param noOfEntries the number of entries to be delivered
+     * @return a collection of the last <noOfEntries> entries
+     */
+    public Collection<ReloadingMetadata> getLastTainted(int noOfEntries) {
+        Iterator<TaintingHistoryEntry> it = _taintLog.subList(Math.max(_taintLog.size()
- noOfEntries, 0), _taintLog.size()).iterator();
+        List<ReloadingMetadata> retVal = new LinkedList<ReloadingMetadata>();
+        while (it.hasNext()) {
+            TaintingHistoryEntry entry = it.next();
+            retVal.add(entry.getData());
+        }
+        return retVal;
+    }
+
+    /**
      * Returns a set of tainting data from a given point in time up until now
      *
      * @param timestamp the point in time from which the tainting data has to be derived
from
      * @return a set of entries which are a union of all points in time beginning from timestamp
      */
-    public Set<ReloadingMetadata> getTaintHistory(long timestamp) {
-        Set<ReloadingMetadata> retVal = new HashSet<ReloadingMetadata>();
+    public Collection<ReloadingMetadata> getTaintHistory(long timestamp) {
+        List<ReloadingMetadata> retVal = new LinkedList<ReloadingMetadata>();
         Iterator<TaintingHistoryEntry> it = _taintLog.iterator();
 
         while (it.hasNext()) {
@@ -341,6 +354,7 @@
 
     /**
      * getter for the taintlog timeout
+     *
      * @return the taintlog timeout
      */
     public long getTaintLogTimeout() {

Modified: myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/scripting/core/refreshContext/RefreshContextTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/scripting/core/refreshContext/RefreshContextTest.java?rev=919198&r1=919197&r2=919198&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/scripting/core/refreshContext/RefreshContextTest.java
(original)
+++ myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/scripting/core/refreshContext/RefreshContextTest.java
Thu Mar  4 22:05:34 2010
@@ -28,6 +28,7 @@
 import org.junit.Test;
 
 import java.io.File;
+import java.util.Collection;
 import java.util.Set;
 
 import static org.junit.Assert.assertTrue;
@@ -124,4 +125,28 @@
 
     }
 
+    @Test
+    public void testTaintHistoryLastNoOfEntroies() {
+        RefreshContext ctx = WeavingContext.getRefreshContext();
+        ctx.setTaintLogTimeout(3);
+
+        ReloadingMetadata data = new ReloadingMetadata();
+        data.setAClass(this.getClass());
+        data.setTainted(true);
+        data.setTimestamp(System.currentTimeMillis());
+
+        ctx.addTaintLogEntry(data);
+        ctx.addTaintLogEntry(data);
+        ctx.addTaintLogEntry(data);
+
+        Collection<ReloadingMetadata> result = ctx.getLastTainted(100);
+        assertTrue("Taint history size", result.size() == 3);
+        result = ctx.getLastTainted(2);
+        assertTrue("Taint history size", result.size() == 2);
+        result = ctx.getLastTainted(0);
+        assertTrue("Taint history size", result.size() == 0);
+
+    }
+
+
 }

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java?rev=919198&r1=919197&r2=919198&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
(original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
Thu Mar  4 22:05:34 2010
@@ -20,6 +20,7 @@
 
 import org.apache.myfaces.scripting.api.Decorated;
 import org.apache.myfaces.scripting.api.ScriptingConst;
+import org.apache.myfaces.scripting.core.util.ReflectUtil;
 import org.apache.myfaces.scripting.core.util.WeavingContext;
 import org.apache.myfaces.scripting.jsf2.annotation.purged.*;
 
@@ -31,10 +32,9 @@
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
 import javax.faces.el.*;
-import javax.faces.event.ActionListener;
-import javax.faces.event.SystemEvent;
-import javax.faces.event.SystemEventListener;
+import javax.faces.event.*;
 import javax.faces.validator.Validator;
+import java.lang.annotation.Annotation;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -54,11 +54,11 @@
     private static final String ERR_BEH_NOTFOUND = "Behavior annotation was moved but could
not be found";
 
     /*
-     * separate map needed for the behavior ids, because
-     * the original is immutable
-     * we have to do a double bookkeeping
-     * here
-     */
+    * separate map needed for the behavior ids, because
+    * the original is immutable
+    * we have to do a double bookkeeping
+    * here
+    */
     Map<String, String> _behaviors = new ConcurrentHashMap();
 
     public ApplicationProxy(Application delegate) {
@@ -103,9 +103,9 @@
         return _delegate.getResourceBundle(facesContext, s);
     }
 
-    public UIComponent createComponent(ValueExpression valueExpression, FacesContext facesContext,
String s) throws FacesException, NullPointerException {
+    public UIComponent createComponent(ValueExpression valueExpression, FacesContext facesContext,
String componentType) throws FacesException, NullPointerException {
         weaveDelegate();
-        UIComponent component = _delegate.createComponent(valueExpression, facesContext,
s);
+        UIComponent component = _delegate.createComponent(valueExpression, facesContext,
componentType);
         UIComponent oldComponent = component;
         //We can replace annotated components on the fly via
         //ApplicationImpl.addComponent(final String componentType, final String componentClassName)
@@ -125,13 +125,46 @@
 
         //we now have to check for an annotation change, but only in case a reload has happened
         if (component.getClass().hashCode() != oldComponent.getClass().hashCode()) {
-            return handeAnnotationChange(component, valueExpression, facesContext, s);
+            return handleAnnotationChange(component, valueExpression, facesContext, componentType);
         }
 
         return component;
 
     }
 
+    /**
+     * De-registers a single object entity from
+     * our listener event, the entity can implement either @ListenersFor or @ListenerFor
+     * The idea is that the annotation currently is mostly used on components and renderers
to keep
+     * track of changes. The components and renderers are dynamically refreshed but to keep
track of
+     * the listeners in our system we have to deregister the old instances upon refresh
+     * the new ones should be registered automatically by our code
+     *
+     * @param listener the listener object implementing our annotation
+     */
+    private void deregisterEventHandlers(Object listener) {
+        if (listener instanceof SystemEventListener && listener.getClass().isAnnotationPresent(ListenersFor.class))
{
+            ListenersFor listenerData = listener.getClass().getAnnotation(ListenersFor.class);
+            for (ListenerFor singleEntry : listenerData.value()) {
+                unsubscribeFromAnnotatedEvent(listener, singleEntry);
+            }
+        } else if (listener instanceof SystemEventListener && listener.getClass().isAnnotationPresent(ListenerFor.class))
{
+            ListenerFor listenerData = listener.getClass().getAnnotation(ListenerFor.class);
+            unsubscribeFromAnnotatedEvent(listener, listenerData);
+        }
+    }
+
+    /**
+     * De-registers a single listener entity which implements @ListenerFor
+     *
+     * @param listener     the listener object implementing the annotation
+     * @param listenerData the annotation data (we have it outside to cover both possible
listener cases
+     */
+    private void unsubscribeFromAnnotatedEvent(Object listener, ListenerFor listenerData)
{
+        Class systemEventClass = listenerData.systemEventClass();
+        unsubscribeFromEvent(systemEventClass, (SystemEventListener) listener);
+    }
+
     public ExpressionFactory getExpressionFactory() {
         weaveDelegate();
         return _delegate.getExpressionFactory();
@@ -250,7 +283,7 @@
         ViewHandler handler = _delegate.getViewHandler();
 
         /*
-        We proxy here to emable dynamic reloading for
+        We proxy here to enable dynamic reloading for
         methods in the long run, as soon as we hit
         java all our groovy reloading code is lost
         hence we have to work with proxies here
@@ -299,7 +332,7 @@
 
         //we now have to check for an annotation change, but only in case a reload has happened
         if (component.getClass().hashCode() != oldComponent.getClass().hashCode()) {
-            return handeAnnotationChange(component, componentType);
+            return handleAnnotationChange(component, componentType);
         }
 
         return component;
@@ -319,7 +352,7 @@
 
         //we now have to check for an annotation change, but only in case a reload has happened
         if (component.getClass().hashCode() != oldComponent.getClass().hashCode()) {
-            return handeAnnotationChange(component, valueBinding, facesContext, componentType);
+            return handleAnnotationChange(component, valueBinding, facesContext, componentType);
         }
 
         return component;
@@ -333,7 +366,7 @@
     public void addConverter(String converterId, String converterClass) {
         weaveDelegate();
         /* if (converterClass.equals(PurgedConverter.class.getName())) {
-            //purged case we do a full rescane
+            //purged case we do a full rescan
             WeavingContext.getWeaver().fullClassScan();
             Converter componentToChange = _delegate.createConverter(converterId);
             if (componentToChange instanceof PurgedConverter) {
@@ -455,7 +488,7 @@
         weaveDelegate();
 
         if (behaviorClass.equals(PurgedValidator.class.getName())) {
-            //purged case we do a full rescane
+            //purged case we do a full rescan
             WeavingContext.getWeaver().fullClassScan();
             Behavior behavior = (Behavior) _delegate.createBehavior(behaviorId);
             _behaviors.put(behaviorId, behaviorClass);
@@ -508,7 +541,7 @@
 
         //we now have to check for an annotation change, but only in case a reload has happened
         if (component.getClass().hashCode() != oldComponent.getClass().hashCode()) {
-            return handeAnnotationChange(component, facesContext, resource);
+            return handleAnnotationChange(component, facesContext, resource);
         }
 
         return component;
@@ -529,7 +562,7 @@
 
         //we now have to check for an annotation change, but only in case a reload has happened
         if (component.getClass().hashCode() != oldComponent.getClass().hashCode()) {
-            return handeAnnotationChange(component, facesContext, componentType, rendererType);
+            return handleAnnotationChange(component, facesContext, componentType, rendererType);
         }
 
         return component;
@@ -549,7 +582,7 @@
 
         //we now have to check for an annotation change, but only in case a reload has happened
         if (component.getClass().hashCode() != oldComponent.getClass().hashCode()) {
-            return handeAnnotationChange(component, valueExpression, facesContext, s, s1);
+            return handleAnnotationChange(component, valueExpression, facesContext, s, s1);
         }
 
         return component;
@@ -596,15 +629,15 @@
     }
 
     @Override
-    public void publishEvent(FacesContext facesContext, Class<? extends SystemEvent>
eventClass, Class<?> aClass, Object o) {
+    public void publishEvent(FacesContext facesContext, Class<? extends SystemEvent>
eventClass, Class<?> sourceBaseTye, Object source) {
         weaveDelegate();
-        _delegate.publishEvent(facesContext, eventClass, aClass, o);
+        _delegate.publishEvent(facesContext, eventClass, sourceBaseTye, source);
     }
 
     @Override
-    public void publishEvent(FacesContext facesContext, Class<? extends SystemEvent>
eventClass, Object o) {
+    public void publishEvent(FacesContext facesContext, Class<? extends SystemEvent>
eventClass, Object source) {
         weaveDelegate();
-        _delegate.publishEvent(facesContext, eventClass, o);
+        _delegate.publishEvent(facesContext, eventClass, source);
     }
 
     @Override
@@ -666,21 +699,20 @@
         return true;
     }
 
-    private UIComponent handeAnnotationChange(UIComponent oldComponent, ValueExpression valueExpression,
FacesContext facesContext, String componentType) {
+    private UIComponent handleAnnotationChange(UIComponent oldComponent, ValueExpression
valueExpression, FacesContext facesContext, String componentType) {
         UIComponent componentToChange = _delegate.createComponent(valueExpression, facesContext,
componentType);
         if (componentToChange instanceof PurgedComponent) {
             WeavingContext.getWeaver().fullClassScan();
             //via an additional create component we can check whether a purged component
             //was registered after the reload because the annotation has been removed
             componentToChange = _delegate.createComponent(valueExpression, facesContext,
componentType);
-            //TODO reregister the renderer for the component because otherwise we get an
npe here on renderkitlevel
 
             return componentToChange;
         }
         return oldComponent;
     }
 
-    private UIComponent handeAnnotationChange(UIComponent oldComponent, String componentType)
{
+    private UIComponent handleAnnotationChange(UIComponent oldComponent, String componentType)
{
         UIComponent componentToChange = _delegate.createComponent(componentType);
         if (componentToChange instanceof PurgedComponent) {
             WeavingContext.getWeaver().fullClassScan();
@@ -693,7 +725,7 @@
         return oldComponent;
     }
 
-    private UIComponent handeAnnotationChange(UIComponent oldComponent, ValueBinding valueBinding,
FacesContext context, String componentType) {
+    private UIComponent handleAnnotationChange(UIComponent oldComponent, ValueBinding valueBinding,
FacesContext context, String componentType) {
         UIComponent componentToChange = _delegate.createComponent(valueBinding, context,
componentType);
         if (componentToChange instanceof PurgedComponent) {
             WeavingContext.getWeaver().fullClassScan();
@@ -706,7 +738,7 @@
         return oldComponent;
     }
 
-    private UIComponent handeAnnotationChange(UIComponent oldComponent, FacesContext context,
Resource resource) {
+    private UIComponent handleAnnotationChange(UIComponent oldComponent, FacesContext context,
Resource resource) {
         UIComponent componentToChange = _delegate.createComponent(context, resource);
         if (componentToChange instanceof PurgedComponent) {
             WeavingContext.getWeaver().fullClassScan();
@@ -719,7 +751,7 @@
         return oldComponent;
     }
 
-    private UIComponent handeAnnotationChange(UIComponent oldComponent, FacesContext context,
String componentType, String rendererType) {
+    private UIComponent handleAnnotationChange(UIComponent oldComponent, FacesContext context,
String componentType, String rendererType) {
         UIComponent componentToChange = _delegate.createComponent(context, componentType,
rendererType);
         if (componentToChange instanceof PurgedComponent) {
             WeavingContext.getWeaver().fullClassScan();
@@ -732,7 +764,7 @@
         return oldComponent;
     }
 
-    private UIComponent handeAnnotationChange(UIComponent oldComponent, ValueExpression valueExpression,
FacesContext facesContext, String s, String s1) {
+    private UIComponent handleAnnotationChange(UIComponent oldComponent, ValueExpression
valueExpression, FacesContext facesContext, String s, String s1) {
         UIComponent componentToChange = _delegate.createComponent(valueExpression, facesContext,
s, s1);
         String family = oldComponent.getFamily();
         if (componentToChange instanceof PurgedComponent) {

Added: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ListenerForAnnotationHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ListenerForAnnotationHandler.java?rev=919198&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ListenerForAnnotationHandler.java
(added)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ListenerForAnnotationHandler.java
Thu Mar  4 22:05:34 2010
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.myfaces.scripting.jsf2.annotation;
+
+/**
+ * A generic system event listener which makes the system event
+ * annotations dynamic
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ListenerForAnnotationHandler {
+}

Propchange: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ListenerForAnnotationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ListenerForAnnotationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message