myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r698808 - in /myfaces/extensions/validator/branches/jsf_1.1: component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/initializer/trinidad/ core/src/main/config/ core/src/main/java/org/apache/myfaces/extensio...
Date Thu, 25 Sep 2008 03:59:59 GMT
Author: gpetracek
Date: Wed Sep 24 20:59:58 2008
New Revision: 698808

URL: http://svn.apache.org/viewvc?rev=698808&view=rev
Log:
renderer-interceptor mechanism and extval-context

Added:
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/AbstractRendererInterceptor.java
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValValidationInterceptor.java
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InitExtValValidationPhaseListener.java
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/RendererInterceptor.java
Modified:
    myfaces/extensions/validator/branches/jsf_1.1/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/initializer/trinidad/InitTrinidadModulePhaseListener.java
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/config/faces-config.xml
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValRendererWrapper.java
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
    myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java

Modified: myfaces/extensions/validator/branches/jsf_1.1/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/initializer/trinidad/InitTrinidadModulePhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/initializer/trinidad/InitTrinidadModulePhaseListener.java?rev=698808&r1=698807&r2=698808&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/initializer/trinidad/InitTrinidadModulePhaseListener.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/initializer/trinidad/InitTrinidadModulePhaseListener.java
Wed Sep 24 20:59:58 2008
@@ -20,10 +20,10 @@
 
 import org.apache.myfaces.extensions.validator.core.AbstractStartupConfigListener;
 import org.apache.myfaces.extensions.validator.core.ExtValValidationPhaseListener;
+import org.apache.myfaces.extensions.validator.core.ExtValContext;
 import org.apache.myfaces.extensions.validator.initializer.trinidad.component.TrinidadComponentInitializer;
 import org.apache.myfaces.extensions.validator.internal.Priority;
 import org.apache.myfaces.extensions.validator.internal.ToDo;
-import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 
 import javax.faces.lifecycle.LifecycleFactory;
 import javax.faces.lifecycle.Lifecycle;
@@ -72,7 +72,7 @@
 
         if(deactivateClientSideValidation == null || !deactivateClientSideValidation.equalsIgnoreCase("true"))
         {
-            ExtValUtils.addComponentInitializer(new TrinidadComponentInitializer());
+            ExtValContext.getContext().addComponentInitializer(new TrinidadComponentInitializer());
         }
     }
 }

Modified: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/config/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/config/faces-config.xml?rev=698808&r1=698807&r2=698808&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/config/faces-config.xml (original)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/config/faces-config.xml Wed
Sep 24 20:59:58 2008
@@ -26,4 +26,8 @@
     <lifecycle>
         <phase-listener>org.apache.myfaces.extensions.validator.core.ExtValValidationPhaseListener</phase-listener>
     </lifecycle>
+
+    <lifecycle>
+        <phase-listener>org.apache.myfaces.extensions.validator.core.InitExtValValidationPhaseListener</phase-listener>
+    </lifecycle>
 </faces-config>
\ No newline at end of file

Added: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/AbstractRendererInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/AbstractRendererInterceptor.java?rev=698808&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/AbstractRendererInterceptor.java
(added)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/AbstractRendererInterceptor.java
Wed Sep 24 20:59:58 2008
@@ -0,0 +1,108 @@
+/*
+ * 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.extensions.validator.core;
+
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import javax.faces.convert.ConverterException;
+import javax.faces.render.Renderer;
+import java.io.IOException;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public abstract class AbstractRendererInterceptor implements RendererInterceptor
+{
+    public final String getInterceptorId()
+    {
+        return getClass().getName();
+    }
+
+    /*
+    * before
+    */
+    public void beforeDecode(FacesContext facesContext, UIComponent uiComponent, Renderer
wrapped)
+    {
+    }
+
+    public void beforeEncodeBegin(FacesContext facesContext, UIComponent uiComponent, Renderer
wrapped)
+        throws IOException
+    {
+    }
+
+    public void beforeEncodeChildren(FacesContext facesContext, UIComponent uiComponent,
Renderer wrapped)
+        throws IOException
+    {
+    }
+
+    public void beforeEncodeEnd(FacesContext facesContext, UIComponent uiComponent, Renderer
wrapped)
+        throws IOException
+    {
+    }
+
+    public void beforeConvertClientId(FacesContext facesContext, String s, Renderer wrapped)
+    {
+    }
+
+    public void beforeGetRendersChildren(Renderer wrapped)
+    {
+    }
+
+    public void beforeGetConvertedValue(FacesContext facesContext, UIComponent uiComponent,
Object o, Renderer wrapped)
+        throws ConverterException
+    {
+    }
+
+    public void afterDecode(FacesContext facesContext, UIComponent uiComponent, Renderer
wrapped)
+    {
+    }
+
+    public void afterEncodeBegin(FacesContext facesContext, UIComponent uiComponent, Renderer
wrapped)
+        throws IOException
+    {
+    }
+
+    public void afterEncodeChildren(FacesContext facesContext, UIComponent uiComponent, Renderer
wrapped)
+        throws IOException
+    {
+    }
+
+    public void afterEncodeEnd(FacesContext facesContext, UIComponent uiComponent, Renderer
wrapped)
+        throws IOException
+    {
+    }
+
+    public void afterConvertClientId(FacesContext facesContext, String s, Renderer wrapped)
+    {
+    }
+
+    public void afterGetRendersChildren(Renderer wrapped)
+    {
+    }
+
+    public void afterGetConvertedValue(FacesContext facesContext, UIComponent uiComponent,
Object o, Renderer wrapped)
+        throws ConverterException
+    {
+    }
+}

Added: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java?rev=698808&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
(added)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
Wed Sep 24 20:59:58 2008
@@ -0,0 +1,103 @@
+/*
+ * 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.extensions.validator.core;
+
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.core.initializer.rendering.RenderingContextInitializer;
+import org.apache.myfaces.extensions.validator.core.initializer.rendering.DefaultRenderingContextInitializer;
+import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
+import org.apache.myfaces.extensions.validator.core.initializer.component.DefaultComponentInitializer;
+import org.apache.myfaces.extensions.validator.util.ClassUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.API)
+public class ExtValContext
+{
+    private static ExtValContext extValContext = new ExtValContext();
+
+    private Map<String, RendererInterceptor> rendererInterceptors = new HashMap<String,
RendererInterceptor>();
+    private List<String> deniedInterceptors = new ArrayList<String>();
+
+    public static ExtValContext getContext()
+    {
+        return extValContext;
+    }
+
+    public List<RendererInterceptor> getRendererInterceptors()
+    {
+        return new ArrayList<RendererInterceptor>(rendererInterceptors.values());
+    }
+
+    public boolean registerRendererInterceptors(RendererInterceptor rendererInterceptor)
+    {
+        synchronized (ExtValContext.class)
+        {
+            if(deniedInterceptors.contains(rendererInterceptor.getInterceptorId()))
+            {
+                return false;
+            }
+
+            rendererInterceptors.put(rendererInterceptor.getInterceptorId(), rendererInterceptor);
+        }
+        return true;
+    }
+
+    public void deregisterRendererInterceptor(Class rendererInterceptorClass)
+    {
+        RendererInterceptor rendererInterceptor =
+            (RendererInterceptor) ClassUtils.tryToInstantiateClass(rendererInterceptorClass);
+
+        synchronized (ExtValContext.class)
+        {
+            rendererInterceptors.remove(rendererInterceptor.getInterceptorId());
+        }
+    }
+
+    //if an interceptor hasn't been registered so far, it should be denied at future registrations
+    public void denyRendererInterceptor(Class rendererInterceptorClass)
+    {
+        RendererInterceptor rendererInterceptor =
+            (RendererInterceptor) ClassUtils.tryToInstantiateClass(rendererInterceptorClass);
+
+        synchronized (ExtValContext.class)
+        {
+            deniedInterceptors.add(rendererInterceptor.getInterceptorId());
+        }
+        deregisterRendererInterceptor(rendererInterceptorClass);
+    }
+
+    public static void addRenderingContextInitializer(RenderingContextInitializer renderingContextInitializer)
+    {
+        DefaultRenderingContextInitializer.addRenderingContextInitializer(renderingContextInitializer);
+    }
+
+    public void addComponentInitializer(ComponentInitializer componentInitializer)
+    {
+        DefaultComponentInitializer.addComponentInitializer(componentInitializer);
+    }
+}

Modified: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValRendererWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValRendererWrapper.java?rev=698808&r1=698807&r2=698808&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValRendererWrapper.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValRendererWrapper.java
Wed Sep 24 20:59:58 2008
@@ -18,26 +18,14 @@
  */
 package org.apache.myfaces.extensions.validator.core;
 
-import org.apache.myfaces.extensions.validator.core.annotation.AnnotationEntry;
-import org.apache.myfaces.extensions.validator.core.annotation.extractor.AnnotationExtractor;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
-import org.apache.myfaces.extensions.validator.core.metadata.extractor.MetaDataExtractor;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
-import org.apache.myfaces.extensions.validator.util.ClassUtils;
-import org.apache.myfaces.extensions.validator.util.FactoryUtils;
-import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
-import org.apache.myfaces.extensions.validator.util.ValidationUtils;
 
-import javax.faces.component.EditableValueHolder;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.convert.ConverterException;
 import javax.faces.render.Renderer;
 import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.HashMap;
 
 /**
  * Default approach to avoid proxies for converters and the adapter fallback.
@@ -55,123 +43,132 @@
 @UsageInformation(UsageCategory.INTERNAL)
 public class ExtValRendererWrapper extends Renderer
 {
-    private static Boolean isAlternativeAvailable = null;
     protected Renderer wrapped;
+    protected ExtValContext extValContext = ExtValContext.getContext();
 
     public ExtValRendererWrapper(Renderer wrapped)
     {
         this.wrapped = wrapped;
     }
 
-    public void decode(FacesContext facesContext, UIComponent uiComponent)
+    @Override
+    public final void decode(FacesContext facesContext, UIComponent uiComponent)
     {
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.beforeDecode(facesContext, uiComponent, this.wrapped);
+        }
+
         wrapped.decode(facesContext, uiComponent);
-    }
 
-    public void encodeBegin(FacesContext facesContext, UIComponent uiComponent)
-        throws IOException
-    {
-        initComponent(facesContext, uiComponent);
-        wrapped.encodeBegin(facesContext, uiComponent);
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.afterDecode(facesContext, uiComponent, this.wrapped);
+        }
     }
 
-    protected void initComponent(FacesContext facesContext, UIComponent uiComponent)
+    @Override
+    public final void encodeBegin(FacesContext facesContext, UIComponent uiComponent)
+        throws IOException
     {
-        if(!(uiComponent instanceof EditableValueHolder))
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
         {
-            return;
+            rendererInterceptor.beforeEncodeBegin(facesContext, uiComponent, this.wrapped);
         }
 
-        ValidationStrategy validationStrategy;
-        MetaDataExtractor metaDataExtractor;
-
-        AnnotationExtractor annotationExtractor = FactoryUtils.getComponentAnnotationExtractorFactory().create();
+        wrapped.encodeBegin(facesContext, uiComponent);
 
-        Map<String, Object> metaData;
-        for (AnnotationEntry entry : annotationExtractor.extractAnnotations(facesContext,
uiComponent))
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
         {
-            validationStrategy = FactoryUtils.getValidationStrategyFactory().create(entry.getAnnotation());
-
-            if (validationStrategy != null)
-            {
-                metaDataExtractor = FactoryUtils.getMetaDataExtractorFactory().create(validationStrategy);
-
-                if(metaDataExtractor != null)
-                {
-                    metaData = metaDataExtractor.extractMetaData(entry.getAnnotation());
-                }
-                else
-                {
-                    metaData = null;
-                }
-
-                if(metaData == null)
-                {
-                    metaData = new HashMap<String, Object>();
-                }
-
-                FactoryUtils.getComponentInitializerFactory().create(uiComponent)
-                    .configureComponent(facesContext, uiComponent, metaData);
-            }
+            rendererInterceptor.afterEncodeBegin(facesContext, uiComponent, this.wrapped);
         }
     }
 
-    public void encodeChildren(FacesContext facesContext, UIComponent uiComponent)
+    @Override
+    public final void encodeChildren(FacesContext facesContext, UIComponent uiComponent)
         throws IOException
     {
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.beforeEncodeChildren(facesContext, uiComponent, this.wrapped);
+        }
+
         wrapped.encodeChildren(facesContext, uiComponent);
+
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.afterEncodeChildren(facesContext, uiComponent, this.wrapped);
+        }
     }
 
-    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
+    @Override
+    public final void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
         throws IOException
     {
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.beforeEncodeEnd(facesContext, uiComponent, this.wrapped);
+        }
+
         wrapped.encodeEnd(facesContext, uiComponent);
-    }
 
-    public String convertClientId(FacesContext facesContext, String s)
-    {
-        return wrapped.convertClientId(facesContext, s);
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.afterEncodeEnd(facesContext, uiComponent, this.wrapped);
+        }
     }
 
-    public boolean getRendersChildren()
+    @Override
+    public final String convertClientId(FacesContext facesContext, String s)
     {
-        return wrapped.getRendersChildren();
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.beforeConvertClientId(facesContext, s, this.wrapped);
+        }
+
+        String clientId = wrapped.convertClientId(facesContext, s);
+
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.afterConvertClientId(facesContext, s, this.wrapped);
+        }
+
+        return clientId;
     }
 
-    public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object
o)
-        throws ConverterException
+    @Override
+    public final boolean getRendersChildren()
     {
-        Object convertedObject = wrapped.getConvertedValue(facesContext, uiComponent, o);
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.beforeGetRendersChildren(this.wrapped);
+        }
 
-        checkForAlternative();
+        boolean rendersChildren = wrapped.getRendersChildren();
 
-        //if the user activated an alternative mode, cancel here (in order to avoid double
validation)
-        if (Boolean.TRUE.equals(isAlternativeAvailable))
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
         {
-            return convertedObject;
+            rendererInterceptor.afterGetRendersChildren(this.wrapped);
         }
 
-        ValidationUtils.processExtValValidation(facesContext, uiComponent, convertedObject);
-
-        return convertedObject;
+        return rendersChildren;
     }
 
-    private void checkForAlternative()
+    public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object
o)
+        throws ConverterException
     {
-        //to avoid a config parameter (but not nice)
-        if(isAlternativeAvailable == null)
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
         {
-            Class extValApplicationFactoryClass = ClassUtils.tryToLoadClassForName(
-                "org.apache.myfaces.extensions.validator.core.proxy.ExtValApplicationFactory");
+            rendererInterceptor.beforeGetConvertedValue(facesContext, uiComponent, o, this.wrapped);
+        }
+
+        Object convertedObject = wrapped.getConvertedValue(facesContext, uiComponent, o);
 
-            Method isActiveMethod = ReflectionUtils.tryToGetMethod(extValApplicationFactoryClass,
"isActive", null);
-            isAlternativeAvailable = (Boolean)ReflectionUtils
-                .tryToInvokeMethodOfClass(extValApplicationFactoryClass, isActiveMethod);
-
-            if(isAlternativeAvailable == null)
-            {
-                isAlternativeAvailable = false;
-            }
+        for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+        {
+            rendererInterceptor.afterGetConvertedValue(facesContext, uiComponent, o, this.wrapped);
         }
+
+        return convertedObject;
     }
 }

Added: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValValidationInterceptor.java?rev=698808&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValValidationInterceptor.java
(added)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValValidationInterceptor.java
Wed Sep 24 20:59:58 2008
@@ -0,0 +1,133 @@
+/*
+ * 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.extensions.validator.core;
+
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
+import org.apache.myfaces.extensions.validator.core.metadata.extractor.MetaDataExtractor;
+import org.apache.myfaces.extensions.validator.core.annotation.extractor.AnnotationExtractor;
+import org.apache.myfaces.extensions.validator.core.annotation.AnnotationEntry;
+import org.apache.myfaces.extensions.validator.util.FactoryUtils;
+import org.apache.myfaces.extensions.validator.util.ValidationUtils;
+import org.apache.myfaces.extensions.validator.util.ClassUtils;
+import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
+
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.convert.ConverterException;
+import javax.faces.render.Renderer;
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+import java.lang.reflect.Method;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class ExtValValidationInterceptor extends AbstractRendererInterceptor
+{
+    private static Boolean isAlternativeAvailable = null;
+
+    @Override
+    public void beforeEncodeBegin(FacesContext facesContext, UIComponent uiComponent, Renderer
wrapped)
+        throws IOException
+    {
+        initComponent(facesContext, uiComponent);
+    }
+
+    protected void initComponent(FacesContext facesContext, UIComponent uiComponent)
+    {
+        if(!(uiComponent instanceof EditableValueHolder))
+        {
+            return;
+        }
+
+        ValidationStrategy validationStrategy;
+        MetaDataExtractor metaDataExtractor;
+
+        AnnotationExtractor annotationExtractor = FactoryUtils.getComponentAnnotationExtractorFactory().create();
+
+        Map<String, Object> metaData;
+        for (AnnotationEntry entry : annotationExtractor.extractAnnotations(facesContext,
uiComponent))
+        {
+            validationStrategy = FactoryUtils.getValidationStrategyFactory().create(entry.getAnnotation());
+
+            if (validationStrategy != null)
+            {
+                metaDataExtractor = FactoryUtils.getMetaDataExtractorFactory().create(validationStrategy);
+
+                if(metaDataExtractor != null)
+                {
+                    metaData = metaDataExtractor.extractMetaData(entry.getAnnotation());
+                }
+                else
+                {
+                    metaData = null;
+                }
+
+                if(metaData == null)
+                {
+                    metaData = new HashMap<String, Object>();
+                }
+
+                FactoryUtils.getComponentInitializerFactory().create(uiComponent)
+                    .configureComponent(facesContext, uiComponent, metaData);
+            }
+        }
+    }
+
+    @Override
+    public void beforeGetConvertedValue(FacesContext facesContext, UIComponent uiComponent,
Object o, Renderer wrapped)
+        throws ConverterException
+    {
+        checkForAlternative();
+
+        //if the user activated an alternative mode, cancel here (in order to avoid double
validation)
+        if (Boolean.TRUE.equals(isAlternativeAvailable))
+        {
+            return;
+        }
+
+        Object convertedObject = wrapped.getConvertedValue(facesContext, uiComponent, o);
+        ValidationUtils.processExtValValidation(facesContext, uiComponent, convertedObject);
+    }
+
+    private void checkForAlternative()
+    {
+        //to avoid a config parameter (but not nice)
+        if(isAlternativeAvailable == null)
+        {
+            Class extValApplicationFactoryClass = ClassUtils.tryToLoadClassForName(
+                "org.apache.myfaces.extensions.validator.core.proxy.ExtValApplicationFactory");
+
+            Method isActiveMethod = ReflectionUtils.tryToGetMethod(extValApplicationFactoryClass,
"isActive", null);
+            isAlternativeAvailable = (Boolean)ReflectionUtils
+                .tryToInvokeMethodOfClass(extValApplicationFactoryClass, isActiveMethod);
+
+            if(isAlternativeAvailable == null)
+            {
+                isAlternativeAvailable = false;
+            }
+        }
+    }
+}

Added: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InitExtValValidationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InitExtValValidationPhaseListener.java?rev=698808&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InitExtValValidationPhaseListener.java
(added)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InitExtValValidationPhaseListener.java
Wed Sep 24 20:59:58 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.extensions.validator.core;
+
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class InitExtValValidationPhaseListener extends AbstractStartupConfigListener
+{
+    protected void init()
+    {
+        ExtValContext.getContext().registerRendererInterceptors(new ExtValValidationInterceptor());
+    }
+}

Added: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/RendererInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/RendererInterceptor.java?rev=698808&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/RendererInterceptor.java
(added)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/RendererInterceptor.java
Wed Sep 24 20:59:58 2008
@@ -0,0 +1,83 @@
+/*
+ * 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.extensions.validator.core;
+
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import javax.faces.convert.ConverterException;
+import javax.faces.render.Renderer;
+import java.io.IOException;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.API)
+public interface RendererInterceptor
+{
+    String getInterceptorId();
+    /*
+     * before
+     */
+    void beforeDecode(FacesContext facesContext, UIComponent uiComponent, Renderer renderer);
+
+    void beforeEncodeBegin(FacesContext facesContext, UIComponent uiComponent, Renderer renderer)
+        throws IOException;
+
+    void beforeEncodeChildren(FacesContext facesContext, UIComponent uiComponent, Renderer
renderer)
+        throws IOException;
+
+    void beforeEncodeEnd(FacesContext facesContext, UIComponent uiComponent, Renderer renderer)
+        throws IOException;
+
+    void beforeConvertClientId(FacesContext facesContext, String s, Renderer renderer);
+
+    void beforeGetRendersChildren(Renderer renderer);
+
+    void beforeGetConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object
o, Renderer renderer)
+        throws ConverterException;
+
+    /*
+     * before delegation
+     */
+
+    /*
+     * after
+     */
+    void afterDecode(FacesContext facesContext, UIComponent uiComponent, Renderer renderer);
+
+    void afterEncodeBegin(FacesContext facesContext, UIComponent uiComponent, Renderer renderer)
+        throws IOException;
+
+    void afterEncodeChildren(FacesContext facesContext, UIComponent uiComponent, Renderer
renderer)
+        throws IOException;
+
+    void afterEncodeEnd(FacesContext facesContext, UIComponent uiComponent, Renderer renderer)
+        throws IOException;
+
+    void afterConvertClientId(FacesContext facesContext, String s, Renderer renderer);
+
+    void afterGetRendersChildren(Renderer renderer);
+
+    void afterGetConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object
o, Renderer renderer)
+        throws ConverterException;
+}

Modified: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java?rev=698808&r1=698807&r2=698808&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
Wed Sep 24 20:59:58 2008
@@ -21,10 +21,6 @@
 import org.apache.myfaces.extensions.validator.core.InformationProviderBean;
 import org.apache.myfaces.extensions.validator.core.ProcessedInformationEntry;
 import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
-import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
-import org.apache.myfaces.extensions.validator.core.initializer.component.DefaultComponentInitializer;
-import org.apache.myfaces.extensions.validator.core.initializer.rendering.RenderingContextInitializer;
-import org.apache.myfaces.extensions.validator.core.initializer.rendering.DefaultRenderingContextInitializer;
 import org.apache.myfaces.extensions.validator.internal.ToDo;
 import org.apache.myfaces.extensions.validator.internal.Priority;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
@@ -126,10 +122,8 @@
         return bean;
     }
 
-    private static InformationProviderBean initInformationProviderBean(
-        Map applicationMap)
+    private static InformationProviderBean initInformationProviderBean(Map applicationMap)
     {
-
         List<String> informationProviderBeanClassNames = new ArrayList<String>();
 
         informationProviderBeanClassNames
@@ -203,14 +197,4 @@
             .put(VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY,
                 new HashMap<String, ProcessedInformationEntry>());
     }
-
-    public static void addRenderingContextInitializer(RenderingContextInitializer renderingContextInitializer)
-    {
-        DefaultRenderingContextInitializer.addRenderingContextInitializer(renderingContextInitializer);
-    }
-
-    public static void addComponentInitializer(ComponentInitializer componentInitializer)
-    {
-        DefaultComponentInitializer.addComponentInitializer(componentInitializer);
-    }
 }

Modified: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java?rev=698808&r1=698807&r2=698808&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java
Wed Sep 24 20:59:58 2008
@@ -20,6 +20,7 @@
 
 import org.apache.myfaces.extensions.validator.baseval.WebXmlParameter;
 import org.apache.myfaces.extensions.validator.core.AbstractStartupConfigListener;
+import org.apache.myfaces.extensions.validator.core.ExtValContext;
 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 import org.apache.myfaces.extensions.validator.internal.ToDo;
 import org.apache.myfaces.extensions.validator.internal.Priority;
@@ -54,6 +55,6 @@
     @ToDo(value = Priority.MEDIUM, description = "web.xml parameter to deactivate it")
     private void initDefaultComponentInitializerName()
     {
-        ExtValUtils.addComponentInitializer(new HtmlCoreComponentsComponentInitializer());
+        ExtValContext.getContext().addComponentInitializer(new HtmlCoreComponentsComponentInitializer());
     }
 }



Mime
View raw message