myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r698125 - in /myfaces/extensions/validator/trunk: core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/ core/src/main/java/org/apache/myfaces/extensions/validator/util/ validation-modules/property-validation...
Date Tue, 23 Sep 2008 10:36:14 GMT
Author: gpetracek
Date: Tue Sep 23 03:36:14 2008
New Revision: 698125

URL: http://svn.apache.org/viewvc?rev=698125&view=rev
Log:
support for multiple DefaultComponentInitializer implementations

Added:
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
      - copied, changed from r698062, myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/DefaultMyFacesComponentInitializer.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java
Removed:
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/DefaultMyFacesComponentInitializer.java
Modified:
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java?rev=698125&r1=698124&r2=698125&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java
Tue Sep 23 03:36:14 2008
@@ -24,6 +24,8 @@
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * @author Gerhard Petracek
@@ -32,19 +34,22 @@
 @UsageInformation(UsageCategory.INTERNAL)
 public class DefaultComponentInitializer implements ComponentInitializer
 {
-    private static ComponentInitializer componentInitializer;
+    private static List<ComponentInitializer> componentInitializers = new ArrayList<ComponentInitializer>();
 
     public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
     {
-        if(componentInitializer != null)
+        for(ComponentInitializer componentInitializer : componentInitializers)
         {
             componentInitializer.configureComponent(facesContext, uiComponent, metaData);
         }
     }
 
     @UsageInformation(UsageCategory.INTERNAL)
-    public static void setComponentInitializer(ComponentInitializer componentInitializer)
+    public static void addComponentInitializer(ComponentInitializer componentInitializer)
     {
-        DefaultComponentInitializer.componentInitializer = componentInitializer;
+        synchronized (DefaultComponentInitializer.class)
+        {
+            componentInitializers.add(componentInitializer);
+        }
     }
 }

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java?rev=698125&r1=698124&r2=698125&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
Tue Sep 23 03:36:14 2008
@@ -21,6 +21,8 @@
 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.internal.ToDo;
 import org.apache.myfaces.extensions.validator.internal.Priority;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
@@ -201,4 +203,9 @@
             .put(VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY,
                 new HashMap<String, ProcessedInformationEntry>());
     }
+
+    public static void addComponentInitializer(ComponentInitializer componentInitializer)
+    {
+        DefaultComponentInitializer.addComponentInitializer(componentInitializer);
+    }
 }

Copied: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
(from r698062, myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/DefaultMyFacesComponentInitializer.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java?p2=myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java&p1=myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/DefaultMyFacesComponentInitializer.java&r1=698062&r2=698125&rev=698125&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/DefaultMyFacesComponentInitializer.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
Tue Sep 23 03:36:14 2008
@@ -18,7 +18,6 @@
  */
 package org.apache.myfaces.extensions.validator;
 
-import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
 import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
 
 import javax.faces.component.EditableValueHolder;
@@ -31,11 +30,8 @@
  * @author Gerhard Petracek
  * @since 1.x.1
  */
-public class DefaultMyFacesComponentInitializer implements ComponentInitializer
+public class HtmlCoreComponentsComponentInitializer implements ComponentInitializer
 {
-    private static final String TRINIDAD_CORE_INPUT_TEXT
-                                    = "org.apache.myfaces.trinidad.component.core.input.CoreInputText";
-
     public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
     {
         configureRequiredAttribute(facesContext, uiComponent, metaData);
@@ -48,7 +44,7 @@
     {
         if(metaData.containsKey(MetaDataKeys.REQUIRED))
         {
-            if((Boolean)metaData.get(MetaDataKeys.REQUIRED) && isComponentRequired(
uiComponent ))
+            if((Boolean)metaData.get(MetaDataKeys.REQUIRED) && Boolean.TRUE.equals(isComponentRequired(uiComponent)))
             {
                 ((EditableValueHolder)uiComponent).setRequired(true);
             }
@@ -62,23 +58,18 @@
      * @param uiComponent component which implements the EditableValueHolder interface
      * @return false to overrule the annotated property e.g. if component is readonly
      */
-    protected boolean isComponentRequired(UIComponent uiComponent)
+    protected Boolean isComponentRequired(UIComponent uiComponent)
     {
         if(uiComponent instanceof HtmlInputText)
         {
             HtmlInputText htmlInputText = (HtmlInputText)uiComponent;
-            return !(htmlInputText.isDisabled() || htmlInputText.isReadonly());
-        }
-        else if(TRINIDAD_CORE_INPUT_TEXT.equals(uiComponent.getClass().getName()))
-        {
-            return !(Boolean) ReflectionUtils
-                .tryToInvokeMethodOfClassAndMethodName(TRINIDAD_CORE_INPUT_TEXT, "isReadOnly");
+            return !(htmlInputText.isReadonly() || htmlInputText.isDisabled());
         }
 
-        return true;
+        return null;
     }
 
-    private void configureMaxLengthAttribute(FacesContext facesContext,
+    protected void configureMaxLengthAttribute(FacesContext facesContext,
                                              UIComponent uiComponent,
                                              Map<String, Object> metaData)
     {
@@ -91,13 +82,6 @@
                 HtmlInputText htmlInputText = (HtmlInputText)uiComponent;
                 htmlInputText.setMaxlength(maxLength);
             }
-            else if(TRINIDAD_CORE_INPUT_TEXT.equals(uiComponent.getClass().getName()))
-            {
-                ReflectionUtils
-                    .tryToInvokeMethodOfClassAndMethodName(TRINIDAD_CORE_INPUT_TEXT, "setMaximumLength",
-                        new Object[] {maxLength}, new Class[] {int.class});
-            }
-
         }
     }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java?rev=698125&r1=698124&r2=698125&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java
Tue Sep 23 03:36:14 2008
@@ -20,7 +20,6 @@
 
 import org.apache.myfaces.extensions.validator.baseval.WebXmlParameter;
 import org.apache.myfaces.extensions.validator.core.AbstractStartupConfigListener;
-import org.apache.myfaces.extensions.validator.core.initializer.component.DefaultComponentInitializer;
 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 import org.apache.myfaces.extensions.validator.internal.ToDo;
 import org.apache.myfaces.extensions.validator.internal.Priority;
@@ -55,6 +54,7 @@
     @ToDo(value = Priority.MEDIUM, description = "web.xml parameter to deactivate it")
     private void initDefaultComponentInitializerName()
     {
-        DefaultComponentInitializer.setComponentInitializer(new DefaultMyFacesComponentInitializer());
+        ExtValUtils.addComponentInitializer(new HtmlCoreComponentsComponentInitializer());
+        ExtValUtils.addComponentInitializer(new TrinidadComponentInitializer());
     }
 }

Added: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java?rev=698125&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java
(added)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java
Tue Sep 23 03:36:14 2008
@@ -0,0 +1,74 @@
+/*
+ * 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;
+
+import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class TrinidadComponentInitializer extends HtmlCoreComponentsComponentInitializer
+{
+    private static final String TRINIDAD_CORE_INPUT_TEXT
+                                         = "org.apache.myfaces.trinidad.component.core.input.CoreInputText";
+    private static final String TRINIDAD_CORE_INPUT_DATE
+                                         = "org.apache.myfaces.trinidad.component.core.input.CoreInputDate";
+    @Override
+    protected Boolean isComponentRequired(UIComponent uiComponent)
+    {
+        if(processComponent(uiComponent))
+        {
+            return !((Boolean) ReflectionUtils
+                .tryToInvokeMethodOfClassAndMethodName(uiComponent.getClass().getName(),
"isReadOnly") ||
+                     (Boolean) ReflectionUtils
+                .tryToInvokeMethodOfClassAndMethodName(uiComponent.getClass().getName(),
"isDisabled"));
+        }
+        //ToDo impl. the rest
+        return null;
+    }
+
+    @Override
+    protected void configureMaxLengthAttribute(FacesContext facesContext,
+                                               UIComponent uiComponent,
+                                               Map<String, Object> metaData)
+    {
+        if(metaData.containsKey(MetaDataKeys.MAX_LENGTH))
+        {
+            int maxLength = (Integer)metaData.get(MetaDataKeys.MAX_LENGTH);
+
+            if(processComponent(uiComponent))
+            {
+                ReflectionUtils
+                    .tryToInvokeMethodOfClassAndMethodName(uiComponent.getClass().getName(),
"setMaximumLength",
+                        new Object[] {maxLength}, new Class[] {int.class});
+            }
+        }
+    }
+
+    private boolean processComponent(UIComponent uiComponent)
+    {
+        return TRINIDAD_CORE_INPUT_TEXT.equals(uiComponent.getClass().getName()) ||
+               TRINIDAD_CORE_INPUT_DATE.equals(uiComponent.getClass().getName());
+    }
+}
\ No newline at end of file



Mime
View raw message