You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/07/31 19:29:02 UTC
svn commit: r681422 [3/4] - in
/myfaces/extensions/validator/branches/trunk_layout_myfaces/core: ./
src/main/java/org/apache/myfaces/extensions/validator/core/
src/main/java/org/apache/myfaces/extensions/validator/core/adapter/
src/main/java/org/apache...
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/message/resolver/mapper/SimpleValidationStrategyToMsgResolverNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/message/resolver/mapper/SimpleValidationStrategyToMsgResolverNameMapper.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/message/resolver/mapper/SimpleValidationStrategyToMsgResolverNameMapper.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/message/resolver/mapper/SimpleValidationStrategyToMsgResolverNameMapper.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * 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.
+ * 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.validation.message.resolver.mapper;
@@ -24,10 +24,14 @@
/**
* @author Gerhard Petracek
*/
-public class SimpleValidationStrategyToMsgResolverNameMapper implements NameMapper<ValidationStrategy> {
- public String createName(ValidationStrategy validationStrategy) {
+public class SimpleValidationStrategyToMsgResolverNameMapper implements
+ NameMapper<ValidationStrategy>
+{
+ public String createName(ValidationStrategy validationStrategy)
+ {
String resolverName = validationStrategy.getClass().getName();
- return resolverName.substring(0, resolverName.lastIndexOf(".")) + ".DefaultValidationErrorMessageResolver";
+ return resolverName.substring(0, resolverName.lastIndexOf("."))
+ + ".DefaultValidationErrorMessageResolver";
}
}
\ No newline at end of file
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidationStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidationStrategy.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidationStrategy.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidationStrategy.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * 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.
+ * 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.validation.strategy;
@@ -29,31 +29,47 @@
/**
* @author Gerhard Petracek
*/
-public abstract class AbstractValidationStrategy extends AbstractValidatorAdapter {
+public abstract class AbstractValidationStrategy extends
+ AbstractValidatorAdapter
+{
protected static final String DETAIL_MESSAGE_KEY_POSTFIX = "_details";
- protected String resolveMessage(String key) {
- Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
+ protected String resolveMessage(String key)
+ {
+ Locale locale = FacesContext.getCurrentInstance().getViewRoot()
+ .getLocale();
- return FactoryUtils.getMessageResolverFactory().create(this).getMessage(key, locale);
+ return FactoryUtils.getMessageResolverFactory().create(this)
+ .getMessage(key, locale);
}
- protected String getErrorMessageSummary(Annotation annotation) {
+ protected String getErrorMessageSummary(Annotation annotation)
+ {
return resolveMessage(getValidationErrorMsgKey(annotation));
}
- protected String getErrorMessageDetails(Annotation annotation) {
- try {
+ protected String getErrorMessageDetails(Annotation annotation)
+ {
+ try
+ {
String key = getValidationErrorMsgKey(annotation);
- return (key != null) ? resolveMessage(key + DETAIL_MESSAGE_KEY_POSTFIX) : null;
- } catch (MissingResourceException e) {
- logger.warn("couldn't find key " + getValidationErrorMsgKey(annotation) + DETAIL_MESSAGE_KEY_POSTFIX, e);
+ return (key != null) ? resolveMessage(key
+ + DETAIL_MESSAGE_KEY_POSTFIX) : null;
+ }
+ catch (MissingResourceException e)
+ {
+ logger.warn("couldn't find key "
+ + getValidationErrorMsgKey(annotation)
+ + DETAIL_MESSAGE_KEY_POSTFIX, e);
}
return null;
}
- protected FacesMessage getValidationErrorFacesMassage(Annotation annotation) {
- return new FacesMessage(FacesMessage.SEVERITY_ERROR, getErrorMessageSummary(annotation), getErrorMessageDetails(annotation));
+ protected FacesMessage getValidationErrorFacesMassage(Annotation annotation)
+ {
+ return new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ getErrorMessageSummary(annotation),
+ getErrorMessageDetails(annotation));
}
protected abstract String getValidationErrorMsgKey(Annotation annotation);
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidatorAdapter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidatorAdapter.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidatorAdapter.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidatorAdapter.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * 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.
+ * 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.validation.strategy;
@@ -30,30 +30,47 @@
/**
* @author Gerhard Petracek
*/
-public abstract class AbstractValidatorAdapter implements ValidationStrategy {
+public abstract class AbstractValidatorAdapter implements ValidationStrategy
+{
protected final Log logger = LogFactory.getLog(getClass());
- public void validate(FacesContext facesContext, UIComponent uiComponent, AnnotationEntry annotationEntry, Object convertedObject) {
- initValidation(facesContext, uiComponent, annotationEntry, convertedObject);
-
- try {
- processValidation(facesContext, uiComponent, annotationEntry, convertedObject);
+ public void validate(FacesContext facesContext, UIComponent uiComponent,
+ AnnotationEntry annotationEntry, Object convertedObject)
+ {
+ initValidation(facesContext, uiComponent, annotationEntry,
+ convertedObject);
+
+ try
+ {
+ processValidation(facesContext, uiComponent, annotationEntry,
+ convertedObject);
}
- catch (ValidatorException e) {
- if (processAfterValidatorException(facesContext, uiComponent, annotationEntry, convertedObject, e)) {
+ catch (ValidatorException e)
+ {
+ if (processAfterValidatorException(facesContext, uiComponent,
+ annotationEntry, convertedObject, e))
+ {
throw new ConverterException(e.getFacesMessage(), e);
}
}
}
- protected void initValidation(FacesContext facesContext, UIComponent uiComponent, AnnotationEntry annotationEntry, Object convertedObject) {
+ protected void initValidation(FacesContext facesContext,
+ UIComponent uiComponent, AnnotationEntry annotationEntry,
+ Object convertedObject)
+ {
//override if needed
}
//override if needed
- protected boolean processAfterValidatorException(FacesContext facesContext, UIComponent uiComponent, AnnotationEntry annotationEntry, Object convertedObject, ValidatorException e) {
+ protected boolean processAfterValidatorException(FacesContext facesContext,
+ UIComponent uiComponent, AnnotationEntry annotationEntry,
+ Object convertedObject, ValidatorException e)
+ {
return true;
}
- protected abstract void processValidation(FacesContext facesContext, UIComponent uiComponent, AnnotationEntry annotationEntry, Object convertedObject) throws ValidatorException;
+ protected abstract void processValidation(FacesContext facesContext,
+ UIComponent uiComponent, AnnotationEntry annotationEntry,
+ Object convertedObject) throws ValidatorException;
}
\ No newline at end of file
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/DefaultValidationStrategyFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/DefaultValidationStrategyFactory.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/DefaultValidationStrategyFactory.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/DefaultValidationStrategyFactory.java Thu Jul 31 10:28:59 2008
@@ -1,73 +1,99 @@
/*
- * 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.
+ * 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.validation.strategy;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
import org.apache.myfaces.extensions.validator.core.ClassMappingFactory;
import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
import org.apache.myfaces.extensions.validator.core.mapper.NameMapper;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.mapper.CustomConfiguredAnnotationToValidationStrategyNameMapper;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.mapper.CustomConventionAnnotationToValidationStrategyNameMapper;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.mapper.DefaultAnnotationToValidationStrategyNameMapper;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.mapper.SimpleAnnotationToValidationStrategyNameMapper;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.
+ mapper.CustomConfiguredAnnotationToValidationStrategyNameMapper;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.
+ mapper.CustomConventionAnnotationToValidationStrategyNameMapper;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.
+ mapper.DefaultAnnotationToValidationStrategyNameMapper;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.
+ mapper.SimpleAnnotationToValidationStrategyNameMapper;
import org.apache.myfaces.extensions.validator.util.ClassUtils;
import org.apache.myfaces.extensions.validator.util.ExtValUtils;
-import java.lang.annotation.Annotation;
-import java.util.*;
/**
* @author Gerhard Petracek
*/
//TODO add generic java api (de-/register mapping)
-public class DefaultValidationStrategyFactory implements ClassMappingFactory<Annotation, ValidationStrategy> {
+public class DefaultValidationStrategyFactory implements
+ ClassMappingFactory<Annotation, ValidationStrategy>
+{
private static Map<String, String> annotationStrategyMapping = null;
private static List<NameMapper<Annotation>> nameMapperList = new ArrayList<NameMapper<Annotation>>();
- static {
- nameMapperList.add(new CustomConfiguredAnnotationToValidationStrategyNameMapper());
- nameMapperList.add(new CustomConventionAnnotationToValidationStrategyNameMapper());
- nameMapperList.add(new DefaultAnnotationToValidationStrategyNameMapper());
- nameMapperList.add(new SimpleAnnotationToValidationStrategyNameMapper());
+ static
+ {
+ nameMapperList
+ .add(new CustomConfiguredAnnotationToValidationStrategyNameMapper());
+ nameMapperList
+ .add(new CustomConventionAnnotationToValidationStrategyNameMapper());
+ nameMapperList
+ .add(new DefaultAnnotationToValidationStrategyNameMapper());
+ nameMapperList
+ .add(new SimpleAnnotationToValidationStrategyNameMapper());
//TODO if jsr 303 doesn't change:
//nameMapperList.add(new BeanValidationAnnotationStrategyNameMapper());
}
- public ValidationStrategy create(Annotation annotation) {
- if (annotationStrategyMapping == null) {
+ public ValidationStrategy create(Annotation annotation)
+ {
+ if (annotationStrategyMapping == null)
+ {
initStaticStrategyMappings();
}
String annotationName = annotation.annotationType().getName();
- if (annotationStrategyMapping.containsKey(annotationName)) {
- return (ValidationStrategy) ClassUtils.tryToInstantiateClassForName(annotationStrategyMapping.get(annotationName));
+ if (annotationStrategyMapping.containsKey(annotationName))
+ {
+ return (ValidationStrategy) ClassUtils
+ .tryToInstantiateClassForName(annotationStrategyMapping
+ .get(annotationName));
}
ValidationStrategy validationStrategy;
String strategyName;
//null -> use name mappers
- for (NameMapper<Annotation> nameMapper : nameMapperList) {
+ for (NameMapper<Annotation> nameMapper : nameMapperList)
+ {
strategyName = nameMapper.createName(annotation);
//build convention (ValidationStrategy)
- validationStrategy = (ValidationStrategy) ClassUtils.tryToInstantiateClassForName(strategyName);
+ validationStrategy = (ValidationStrategy) ClassUtils
+ .tryToInstantiateClassForName(strategyName);
- if (validationStrategy != null) {
+ if (validationStrategy != null)
+ {
addMapping(annotationName, strategyName);
return validationStrategy;
}
@@ -76,38 +102,51 @@
return null;
}
- private void addMapping(String annotationName, String strategyName) {
- synchronized (DefaultValidationStrategyFactory.class) {
+ private void addMapping(String annotationName, String strategyName)
+ {
+ synchronized (DefaultValidationStrategyFactory.class)
+ {
annotationStrategyMapping.put(annotationName, strategyName);
}
//TODO logging
}
- private void initStaticStrategyMappings() {
- synchronized (DefaultValidationStrategyFactory.class) {
+ private void initStaticStrategyMappings()
+ {
+ synchronized (DefaultValidationStrategyFactory.class)
+ {
annotationStrategyMapping = new HashMap<String, String>();
//setup internal static mappings
- for (String internalMappingSource : ExtValUtils.getInformationProviderBean().getStaticStrategyMappingSources()) {
+ for (String internalMappingSource : ExtValUtils
+ .getInformationProviderBean()
+ .getStaticStrategyMappingSources())
+ {
setupStrategyMappings(internalMappingSource);
}
//try to setup mapping with base name by convention - overrides default mapping
- try {
+ try
+ {
//build convention (strategy mapping)
- setupStrategyMappings(ExtValUtils.getInformationProviderBean().getCustomStaticStrategyMappingSource());
+ setupStrategyMappings(ExtValUtils.getInformationProviderBean()
+ .getCustomStaticStrategyMappingSource());
}
- catch (Throwable t) {
+ catch (Throwable t)
+ {
//do nothing - it was just a try
}
//setup custom mapping - overrides all other mappings
String customMappingBaseName = WebXmlParameter.CUSTOM_VALIDATIONSTRATEGY_MAPPING;
- if (customMappingBaseName != null) {
- try {
+ if (customMappingBaseName != null)
+ {
+ try
+ {
setupStrategyMappings(customMappingBaseName);
}
- catch (MissingResourceException e) {
+ catch (MissingResourceException e)
+ {
//TODO logging
e.printStackTrace();
}
@@ -115,10 +154,12 @@
}
}
- private void setupStrategyMappings(String bundle) {
+ private void setupStrategyMappings(String bundle)
+ {
ResourceBundle strategyMapping = ResourceBundle.getBundle(bundle);
- if (strategyMapping == null) {
+ if (strategyMapping == null)
+ {
return;
}
@@ -127,9 +168,11 @@
String annotationClassName;
String validationStrategyClassName;
- while (keys.hasMoreElements()) {
+ while (keys.hasMoreElements())
+ {
annotationClassName = (String) keys.nextElement();
- validationStrategyClassName = strategyMapping.getString(annotationClassName);
+ validationStrategyClassName = strategyMapping
+ .getString(annotationClassName);
addMapping(annotationClassName, validationStrategyClassName);
}
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/ValidationStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/ValidationStrategy.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/ValidationStrategy.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/ValidationStrategy.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * 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.
+ * 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.validation.strategy;
@@ -26,6 +26,8 @@
/**
* @author Gerhard Petracek
*/
-public interface ValidationStrategy {
- void validate(FacesContext facesContext, UIComponent uiComponent, AnnotationEntry annotationEntry, Object convertedObject);
+public interface ValidationStrategy
+{
+ void validate(FacesContext facesContext, UIComponent uiComponent,
+ AnnotationEntry annotationEntry, Object convertedObject);
}
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/CustomConfiguredAnnotationToValidationStrategyNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/CustomConfiguredAnnotationToValidationStrategyNameMapper.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/CustomConfiguredAnnotationToValidationStrategyNameMapper.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/CustomConfiguredAnnotationToValidationStrategyNameMapper.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * 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.
+ * 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.validation.strategy.mapper;
@@ -27,9 +27,12 @@
* @author Gerhard Petracek
*/
@Deprecated
-public class CustomConfiguredAnnotationToValidationStrategyNameMapper extends AbstractCustomNameMapper<Annotation> {
+public class CustomConfiguredAnnotationToValidationStrategyNameMapper extends
+ AbstractCustomNameMapper<Annotation>
+{
- protected String getCustomNameMapperClassName() {
+ protected String getCustomNameMapperClassName()
+ {
return WebXmlParameter.CUSTOM_ANNOTATION_TO_VALIDATION_STRATEGY_NAME_MAPPER;
}
}
\ No newline at end of file
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/CustomConventionAnnotationToValidationStrategyNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/CustomConventionAnnotationToValidationStrategyNameMapper.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/CustomConventionAnnotationToValidationStrategyNameMapper.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/CustomConventionAnnotationToValidationStrategyNameMapper.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * 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.
+ * 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.validation.strategy.mapper;
@@ -28,9 +28,13 @@
*
* @author Gerhard Petracek
*/
-public class CustomConventionAnnotationToValidationStrategyNameMapper extends AbstractCustomNameMapper<Annotation> {
+public class CustomConventionAnnotationToValidationStrategyNameMapper extends
+ AbstractCustomNameMapper<Annotation>
+{
- protected String getCustomNameMapperClassName() {
- return ExtValUtils.getInformationProviderBean().getCustomAnnotationToValidationStrategyNameMapper();
+ protected String getCustomNameMapperClassName()
+ {
+ return ExtValUtils.getInformationProviderBean()
+ .getCustomAnnotationToValidationStrategyNameMapper();
}
}
\ No newline at end of file
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/DefaultAnnotationToValidationStrategyNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/DefaultAnnotationToValidationStrategyNameMapper.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/DefaultAnnotationToValidationStrategyNameMapper.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/DefaultAnnotationToValidationStrategyNameMapper.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * 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.
+ * 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.validation.strategy.mapper;
@@ -26,8 +26,12 @@
/**
* @author Gerhard Petracek
*/
-public class DefaultAnnotationToValidationStrategyNameMapper implements NameMapper<Annotation> {
- public String createName(Annotation annotation) {
- return ExtValUtils.getInformationProviderBean().getConventionNameForValidationStrategy(annotation);
+public class DefaultAnnotationToValidationStrategyNameMapper implements
+ NameMapper<Annotation>
+{
+ public String createName(Annotation annotation)
+ {
+ return ExtValUtils.getInformationProviderBean()
+ .getConventionNameForValidationStrategy(annotation);
}
}
\ No newline at end of file
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/SimpleAnnotationToValidationStrategyNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/SimpleAnnotationToValidationStrategyNameMapper.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/SimpleAnnotationToValidationStrategyNameMapper.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/mapper/SimpleAnnotationToValidationStrategyNameMapper.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * 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.
+ * 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.validation.strategy.mapper;
@@ -25,8 +25,11 @@
/**
* @author Gerhard Petracek
*/
-public class SimpleAnnotationToValidationStrategyNameMapper implements NameMapper<Annotation> {
- public String createName(Annotation annotation) {
+public class SimpleAnnotationToValidationStrategyNameMapper implements
+ NameMapper<Annotation>
+{
+ public String createName(Annotation annotation)
+ {
return annotation.annotationType().getName() + "Strategy";
}
}
\ No newline at end of file
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ClassUtils.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ClassUtils.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ClassUtils.java Thu Jul 31 10:28:59 2008
@@ -1,61 +1,75 @@
/*
- * 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.
+ * 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.util;
/**
* @author Gerhard Petracek
*/
-public class ClassUtils {
- public static Class loadClassForName(String name) throws ClassNotFoundException {
- try {
+public class ClassUtils
+{
+ public static Class loadClassForName(String name)
+ throws ClassNotFoundException
+ {
+ try
+ {
// Try WebApp ClassLoader first
- return Class.forName(name,
- false, // do not initialize for faster startup
+ return Class.forName(name, false, // do not initialize for faster startup
Thread.currentThread().getContextClassLoader());
}
- catch (ClassNotFoundException ignore) {
+ catch (ClassNotFoundException ignore)
+ {
// fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar lib)
- return Class.forName(name,
- false, // do not initialize for faster startup
+ return Class.forName(name, false, // do not initialize for faster startup
ClassUtils.class.getClassLoader());
}
}
- public static Object tryToInstantiateClass(Class targetClass) {
- try {
+ public static Object tryToInstantiateClass(Class targetClass)
+ {
+ try
+ {
return targetClass.newInstance();
- } catch (Throwable t) {
+ }
+ catch (Throwable t)
+ {
//do nothing - it was just a try
}
return null;
}
- public static Object tryToInstantiateClassForName(String className) {
- try {
+ public static Object tryToInstantiateClassForName(String className)
+ {
+ try
+ {
return instantiateClassForName(className);
- } catch (Throwable t) {
+ }
+ catch (Throwable t)
+ {
//do nothing - it was just a try
}
return null;
}
- public static Object instantiateClassForName(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
+ public static Object instantiateClassForName(String className)
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException
+ {
return loadClassForName(className).newInstance();
}
}
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ELUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ELUtils.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ELUtils.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ELUtils.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * 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.
+ * 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.util;
@@ -28,63 +28,99 @@
* @author Gerhard Petracek
*/
//TODO
-public class ELUtils {
- public static Class getTypeOfValueBindingForExpression(FacesContext facesContext, String valueBindingExpression) {
+public class ELUtils
+{
+ public static Class getTypeOfValueBindingForExpression(
+ FacesContext facesContext, String valueBindingExpression)
+ {
//due to a restriction with the ri
- Object bean = ELUtils.getValueOfExpression(facesContext, valueBindingExpression);
+ Object bean = ELUtils.getValueOfExpression(facesContext,
+ valueBindingExpression);
return (bean != null) ? bean.getClass() : null;
}
- public static Object getBean(String beanName) {
+ public static Object getBean(String beanName)
+ {
FacesContext facesContext = FacesContext.getCurrentInstance();
- return facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, beanName);
+ return facesContext.getApplication().getELResolver().getValue(
+ facesContext.getELContext(), null, beanName);
}
//TODO refactor - problem - static values - jsf 1.2 e.g.: ${value}
- public static Object getBeanObject(String valueBindingExpression, UIComponent uiComponent) {
- if (valueBindingExpression.lastIndexOf(".") == -1) {
- return uiComponent.getValueExpression("value").getValue(FacesContext.getCurrentInstance().getELContext());
+ public static Object getBeanObject(String valueBindingExpression,
+ UIComponent uiComponent)
+ {
+ if (valueBindingExpression.lastIndexOf(".") == -1)
+ {
+ return uiComponent.getValueExpression("value").getValue(
+ FacesContext.getCurrentInstance().getELContext());
}
return getBeanObject(valueBindingExpression);
}
- public static Object getBeanObject(String valueBindingExpression) {
- String newExpression = valueBindingExpression.substring(0, valueBindingExpression.lastIndexOf(".")) + "}";
-
- return getValueOfExpression(FacesContext.getCurrentInstance(), newExpression);
- }
-
- public static Object getValueOfExpression(FacesContext facesContext, String valueBindingExpression) {
- return (valueBindingExpression != null) ? facesContext.getApplication().createValueBinding(valueBindingExpression).getValue(facesContext) : null;
- }
-
- public static boolean isExpressionValid(FacesContext facesContext, String valueBindingExpression) {
- return facesContext.getApplication().createValueBinding(valueBindingExpression) != null;
- }
-
- public static String getReliableValueBindingExpression(UIComponent uiComponent) {
+ public static Object getBeanObject(String valueBindingExpression)
+ {
+ String newExpression = valueBindingExpression.substring(0,
+ valueBindingExpression.lastIndexOf("."))
+ + "}";
+
+ return getValueOfExpression(FacesContext.getCurrentInstance(),
+ newExpression);
+ }
+
+ public static Object getValueOfExpression(FacesContext facesContext,
+ String valueBindingExpression)
+ {
+ return (valueBindingExpression != null) ? facesContext.getApplication()
+ .createValueBinding(valueBindingExpression).getValue(
+ facesContext) : null;
+ }
+
+ public static boolean isExpressionValid(FacesContext facesContext,
+ String valueBindingExpression)
+ {
+ return facesContext.getApplication().createValueBinding(
+ valueBindingExpression) != null;
+ }
+
+ public static String getReliableValueBindingExpression(
+ UIComponent uiComponent)
+ {
String valueBindingExpression = getValueBindingExpression(uiComponent);
String baseExpression = valueBindingExpression;
- if(baseExpression.contains(".")) {
- baseExpression = baseExpression.substring(0, valueBindingExpression.lastIndexOf(".")) + "}";
+ if (baseExpression.contains("."))
+ {
+ baseExpression = baseExpression.substring(0, valueBindingExpression
+ .lastIndexOf("."))
+ + "}";
}
- if(getTypeOfValueBindingForExpression(FacesContext.getCurrentInstance(), baseExpression) == null) {
- valueBindingExpression = FaceletsTaglibExpressionUtils.tryToCreateValueBindingForFaceletsBinding(uiComponent);
+ if (getTypeOfValueBindingForExpression(FacesContext
+ .getCurrentInstance(), baseExpression) == null)
+ {
+ valueBindingExpression = FaceletsTaglibExpressionUtils
+ .tryToCreateValueBindingForFaceletsBinding(uiComponent);
}
return valueBindingExpression;
}
- public static String getValueBindingExpression(UIComponent uiComponent) {
- ValueExpression valueExpression = uiComponent.getValueExpression("value");
-
- return (valueExpression != null) ? valueExpression.getExpressionString() : null;
- }
-
- public static Class getTypeOfValueBindingForComponent(FacesContext facesContext, UIComponent uiComponent) {
- ValueExpression valueExpression = uiComponent.getValueExpression("value");
+ public static String getValueBindingExpression(UIComponent uiComponent)
+ {
+ ValueExpression valueExpression = uiComponent
+ .getValueExpression("value");
+
+ return (valueExpression != null) ? valueExpression
+ .getExpressionString() : null;
+ }
+
+ public static Class getTypeOfValueBindingForComponent(
+ FacesContext facesContext, UIComponent uiComponent)
+ {
+ ValueExpression valueExpression = uiComponent
+ .getValueExpression("value");
- return (valueExpression != null) ? valueExpression.getType(facesContext.getELContext()) : null;
+ return (valueExpression != null) ? valueExpression.getType(facesContext
+ .getELContext()) : null;
}
}
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java Thu Jul 31 10:28:59 2008
@@ -1,26 +1,28 @@
/*
- * 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.
+ * 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.util;
-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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
@@ -32,115 +34,160 @@
import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
import javax.faces.lifecycle.LifecycleFactory;
-import java.util.*;
+
+import org.apache.myfaces.extensions.validator.core.InformationProviderBean;
+import org.apache.myfaces.extensions.validator.core.ProcessedInformationEntry;
+import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
+
/**
* @author Gerhard Petracek
*/
-public class ExtValUtils {
+public class ExtValUtils
+{
- public static String getBasePackage() {
+ public static String getBasePackage()
+ {
return getInformationProviderBean().getBasePackage();
}
- public static InformationProviderBean getInformationProviderBean() {
- Map applicationMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
- InformationProviderBean bean = (InformationProviderBean) applicationMap.get(InformationProviderBean.BEAN_NAME);
+ public static InformationProviderBean getInformationProviderBean()
+ {
+ Map applicationMap = FacesContext.getCurrentInstance()
+ .getExternalContext().getApplicationMap();
+ InformationProviderBean bean = (InformationProviderBean) applicationMap
+ .get(InformationProviderBean.BEAN_NAME);
- if (bean == null) {
+ if (bean == null)
+ {
return initInformationProviderBean(applicationMap);
}
return bean;
}
- private static InformationProviderBean initInformationProviderBean(Map applicationMap) {
+ private static InformationProviderBean initInformationProviderBean(
+ Map applicationMap)
+ {
List<String> informationProviderBeanClassNames = new ArrayList<String>();
- informationProviderBeanClassNames.add(WebXmlParameter.CUSTOM_CONVENTION_INFO_PROVIDER_BEAN);
- informationProviderBeanClassNames.add(ExtValUtils.getCustomInformationProviderBeanClassName());
- informationProviderBeanClassNames.add(InformationProviderBean.class.getName());
+ informationProviderBeanClassNames
+ .add(WebXmlParameter.CUSTOM_CONVENTION_INFO_PROVIDER_BEAN);
+ informationProviderBeanClassNames.add(ExtValUtils
+ .getCustomInformationProviderBeanClassName());
+ informationProviderBeanClassNames.add(InformationProviderBean.class
+ .getName());
InformationProviderBean informationProviderBean;
- for (String className : informationProviderBeanClassNames) {
- informationProviderBean = (InformationProviderBean) ClassUtils.tryToInstantiateClassForName(className);
-
- if (informationProviderBean != null) {
- applicationMap.put(InformationProviderBean.BEAN_NAME, informationProviderBean);
+ for (String className : informationProviderBeanClassNames)
+ {
+ informationProviderBean = (InformationProviderBean) ClassUtils
+ .tryToInstantiateClassForName(className);
+
+ if (informationProviderBean != null)
+ {
+ applicationMap.put(InformationProviderBean.BEAN_NAME,
+ informationProviderBean);
return informationProviderBean;
}
}
- throw new IllegalStateException(InformationProviderBean.class.getName() + " not found");
+ throw new IllegalStateException(InformationProviderBean.class.getName()
+ + " not found");
}
- public static String getCustomInformationProviderBeanClassName() {
- InformationProviderBean bean = (InformationProviderBean) ELUtils.getBean(InformationProviderBean.CUSTOM_BEAN);
+ public static String getCustomInformationProviderBeanClassName()
+ {
+ InformationProviderBean bean = (InformationProviderBean) ELUtils
+ .getBean(InformationProviderBean.CUSTOM_BEAN);
return (bean != null) ? bean.getClass().getName() : null;
}
- public static void deregisterPhaseListener(PhaseListener phaseListener) {
- LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ public static void deregisterPhaseListener(PhaseListener phaseListener)
+ {
+ LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
String currentId;
Lifecycle currentLifecycle;
Iterator lifecycleIds = lifecycleFactory.getLifecycleIds();
- while (lifecycleIds.hasNext()) {
+ while (lifecycleIds.hasNext())
+ {
currentId = (String) lifecycleIds.next();
currentLifecycle = lifecycleFactory.getLifecycle(currentId);
currentLifecycle.removePhaseListener(phaseListener);
}
}
- public static final String VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY = ExtValUtils.class.getName();
+ public static final String VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY = ExtValUtils.class
+ .getName();
- public static Map<String, ProcessedInformationEntry> getOrInitValueBindingConvertedValueMapping() {
- Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+ public static Map<String, ProcessedInformationEntry> getOrInitValueBindingConvertedValueMapping()
+ {
+ Map requestMap = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequestMap();
- if (!requestMap.containsKey(VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY)) {
+ if (!requestMap.containsKey(VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY))
+ {
resetCrossValidationStorage();
}
- return (Map<String, ProcessedInformationEntry>) requestMap.get(VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY);
+ return (Map<String, ProcessedInformationEntry>) requestMap
+ .get(VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY);
}
- public static void resetCrossValidationStorage() {
- FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY, new HashMap<String, ProcessedInformationEntry>());
+ public static void resetCrossValidationStorage()
+ {
+ FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
+ .put(VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY,
+ new HashMap<String, ProcessedInformationEntry>());
}
/*
* workaround: mapping clientId -> proxy -> after restore view: find component + set converter of the mapping
* TODO: find a better solution - multi-window-mode
*/
- public static final String PROXY_MAPPING_KEY = VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY + ":proxyMapping";
+ public static final String PROXY_MAPPING_KEY = VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY
+ + ":proxyMapping";
- public static Map<String, Object> getOrInitProxyMapping() {
+ public static Map<String, Object> getOrInitProxyMapping()
+ {
FacesContext facesContext = FacesContext.getCurrentInstance();
//session scope is just the worst case - cleanup after restore view
Map sessionMap = facesContext.getExternalContext().getSessionMap();
String viewId = facesContext.getViewRoot().getViewId();
- if (!sessionMap.containsKey(PROXY_MAPPING_KEY) || !((Map)sessionMap.get(PROXY_MAPPING_KEY)).containsKey(viewId)) {
+ if (!sessionMap.containsKey(PROXY_MAPPING_KEY)
+ || !((Map) sessionMap.get(PROXY_MAPPING_KEY))
+ .containsKey(viewId))
+ {
resetProxyMapping(viewId);
}
- return (Map<String, Object>) ((Map)sessionMap.get(PROXY_MAPPING_KEY)).get(viewId);
+ return (Map<String, Object>) ((Map) sessionMap.get(PROXY_MAPPING_KEY))
+ .get(viewId);
}
- public static void resetProxyMapping(String viewId) {
- Map sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
+ public static void resetProxyMapping(String viewId)
+ {
+ Map sessionMap = FacesContext.getCurrentInstance().getExternalContext()
+ .getSessionMap();
Map<String, Map<String, Object>> storage;
- if(sessionMap.containsKey(PROXY_MAPPING_KEY)) {
- storage = (Map)sessionMap.get(PROXY_MAPPING_KEY);
- } else {
+ if (sessionMap.containsKey(PROXY_MAPPING_KEY))
+ {
+ storage = (Map) sessionMap.get(PROXY_MAPPING_KEY);
+ }
+ else
+ {
storage = new HashMap<String, Map<String, Object>>();
}
Map<String, Object> map;
- if(!storage.containsKey(viewId)) {
+ if (!storage.containsKey(viewId))
+ {
map = new HashMap<String, Object>();
storage.put(viewId, map);
}
@@ -148,58 +195,74 @@
sessionMap.put(PROXY_MAPPING_KEY, storage);
}
- public static final String PROCESSED_CONVERTER_COUNT_KEY = VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY + ":processedConverterCount";
+ public static final String PROCESSED_CONVERTER_COUNT_KEY = VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY
+ + ":processedConverterCount";
- public static Integer getProcessedConverterCount() {
- Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+ public static Integer getProcessedConverterCount()
+ {
+ Map requestMap = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequestMap();
- if (!requestMap.containsKey(PROCESSED_CONVERTER_COUNT_KEY)) {
+ if (!requestMap.containsKey(PROCESSED_CONVERTER_COUNT_KEY))
+ {
resetProcessedConverterMapping();
}
return (Integer) requestMap.get(PROCESSED_CONVERTER_COUNT_KEY);
}
- public static void setProcessedConverterCount(Integer count) {
- Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+ public static void setProcessedConverterCount(Integer count)
+ {
+ Map requestMap = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequestMap();
- if (!requestMap.containsKey(PROCESSED_CONVERTER_COUNT_KEY)) {
+ if (!requestMap.containsKey(PROCESSED_CONVERTER_COUNT_KEY))
+ {
resetProcessedConverterMapping();
}
requestMap.put(PROCESSED_CONVERTER_COUNT_KEY, count);
}
- public static void resetProcessedConverterMapping() {
- FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(PROCESSED_CONVERTER_COUNT_KEY, 0);
+ public static void resetProcessedConverterMapping()
+ {
+ FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
+ .put(PROCESSED_CONVERTER_COUNT_KEY, 0);
}
- public static void increaseProcessedConverterCount() {
+ public static void increaseProcessedConverterCount()
+ {
setProcessedConverterCount(getProcessedConverterCount() + 1);
}
- public static void decreaseProcessedConverterCount() {
+ public static void decreaseProcessedConverterCount()
+ {
setProcessedConverterCount(getProcessedConverterCount() - 1);
}
- public static boolean useProxyMapping() {
+ public static boolean useProxyMapping()
+ {
String initParam = WebXmlParameter.DEACTIVATE_PROXY_MAPPING;
- boolean disableProxyMapping = (initParam != null && initParam.trim().equalsIgnoreCase("true"));
+ boolean disableProxyMapping = (initParam != null && initParam.trim()
+ .equalsIgnoreCase("true"));
return !(useFallbackAdapters() || disableProxyMapping);
}
@Deprecated
- public static boolean useFallbackAdapters() {
+ public static boolean useFallbackAdapters()
+ {
String initParam = WebXmlParameter.USE_ADAPTERS;
return (initParam != null && initParam.trim().equalsIgnoreCase("true"));
}
- public static void restoreProxies() {
+ public static void restoreProxies()
+ {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
- if (viewRoot != null && ExtValUtils.useProxyMapping()) {
+ if (viewRoot != null && ExtValUtils.useProxyMapping())
+ {
Map componentConverterMapping = ExtValUtils.getOrInitProxyMapping();
Iterator current = componentConverterMapping.keySet().iterator();
@@ -207,83 +270,111 @@
Converter converter;
Converter converterOfComponent;
UIComponent component = null;
- while (current.hasNext()) {
+ while (current.hasNext())
+ {
key = (String) current.next();
converter = (Converter) componentConverterMapping.get(key);
- try {
+ try
+ {
component = viewRoot.findComponent(key);
- } catch (IllegalArgumentException e) {
- //do nothing - it's just a ri bug with complex components - resolveComponentInComplexComponent will return the correct component
+ }
+ catch (IllegalArgumentException e)
+ {
+ //do nothing - it's just a ri bug with complex components -
+ //resolveComponentInComplexComponent will return the correct component
}
- if (component == null) {
- component = resolveComponentInComplexComponent(viewRoot, component, key);
+ if (component == null)
+ {
+ component = resolveComponentInComplexComponent(viewRoot,
+ component, key);
- if (component == null) {
+ if (component == null)
+ {
continue;
}
}
- if (!(component instanceof ValueHolder)) {
+ if (!(component instanceof ValueHolder))
+ {
continue;
}
converterOfComponent = ((ValueHolder) component).getConverter();
//converterOfComponent lost callback during state-saving -> set converter of same type
- if (converterOfComponent != null && converterOfComponent.getClass().getSuperclass().equals(converter.getClass().getSuperclass())) {
+ if (converterOfComponent != null
+ && converterOfComponent.getClass().getSuperclass()
+ .equals(converter.getClass().getSuperclass()))
+ {
((ValueHolder) component).setConverter(converter);
}
}
}
- if (ExtValUtils.useProxyMapping()) {
- ExtValUtils.resetProxyMapping(FacesContext.getCurrentInstance().getViewRoot().getViewId());
+ if (ExtValUtils.useProxyMapping())
+ {
+ ExtValUtils.resetProxyMapping(FacesContext.getCurrentInstance()
+ .getViewRoot().getViewId());
}
}
//TODO
- private static UIComponent resolveComponentInComplexComponent(UIComponent viewRoot, UIComponent component, String key) {
+ private static UIComponent resolveComponentInComplexComponent(
+ UIComponent viewRoot, UIComponent component, String key)
+ {
int index = key.lastIndexOf(":");
- if(index == -1) {
+ if (index == -1)
+ {
return null;
}
-
+
String newKey = key.substring(0, index);
- if (viewRoot.findComponent(newKey) == null) {
+ if (viewRoot.findComponent(newKey) == null)
+ {
int newIndex = newKey.lastIndexOf(":");
- if (newIndex < 1) {
+ if (newIndex < 1)
+ {
return null;
}
newKey = newKey.substring(0, newIndex);
component = viewRoot.findComponent(newKey);
- if (component == null) {
+ if (component == null)
+ {
return null;
- } else {
- return tryToResolveChildComponent(component, key.substring(key.lastIndexOf(":")));
+ }
+ else
+ {
+ return tryToResolveChildComponent(component, key.substring(key
+ .lastIndexOf(":")));
}
}
return null;
}
//TODO
- private static UIComponent tryToResolveChildComponent(UIComponent component, String endOfKey) {
+ private static UIComponent tryToResolveChildComponent(
+ UIComponent component, String endOfKey)
+ {
FacesContext facesContext = FacesContext.getCurrentInstance();
String clientId = component.getClientId(facesContext);
- if (clientId.substring(clientId.lastIndexOf(":")).endsWith(endOfKey)) {
+ if (clientId.substring(clientId.lastIndexOf(":")).endsWith(endOfKey))
+ {
return component;
}
UIComponent foundComponent;
- for (UIComponent child : (List<UIComponent>) component.getChildren()) {
+ for (UIComponent child : (List<UIComponent>) component.getChildren())
+ {
foundComponent = tryToResolveChildComponent(child, endOfKey);
- if (foundComponent != null) {
+ if (foundComponent != null)
+ {
return foundComponent;
}
}
@@ -291,29 +382,41 @@
return null;
}
- public static final String ORIGINAL_APPLICATION_KEY = VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY + ":wrapped_application";
+ public static final String ORIGINAL_APPLICATION_KEY = VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY
+ + ":wrapped_application";
//in order to access the wrapped application and support other Application wrappers
- public static void setOriginalApplication(Application application) {
+ public static void setOriginalApplication(Application application)
+ {
FacesContext facesContext = FacesContext.getCurrentInstance();
- Map applicationMap = facesContext.getExternalContext().getApplicationMap();
+ Map applicationMap = facesContext.getExternalContext()
+ .getApplicationMap();
- if (!applicationMap.containsKey(ORIGINAL_APPLICATION_KEY)) {
- synchronized (ExtValUtils.class) {
+ if (!applicationMap.containsKey(ORIGINAL_APPLICATION_KEY))
+ {
+ synchronized (ExtValUtils.class)
+ {
applicationMap.put(ORIGINAL_APPLICATION_KEY, application);
}
}
}
- public static Application getOriginalApplication() {
- return (Application) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get(ORIGINAL_APPLICATION_KEY);
+ public static Application getOriginalApplication()
+ {
+ return (Application) FacesContext.getCurrentInstance()
+ .getExternalContext().getApplicationMap().get(
+ ORIGINAL_APPLICATION_KEY);
}
- public static Converter tryToCreateOriginalConverter(FacesContext facesContext, UIComponent uiComponent) {
+ public static Converter tryToCreateOriginalConverter(
+ FacesContext facesContext, UIComponent uiComponent)
+ {
//for backward compatibility: cross-validation workaround with hidden field and static value
- Class valueBindingType = ELUtils.getTypeOfValueBindingForComponent(facesContext, uiComponent);
+ Class valueBindingType = ELUtils.getTypeOfValueBindingForComponent(
+ facesContext, uiComponent);
- if (valueBindingType == null) {
+ if (valueBindingType == null)
+ {
return null;
}