You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/12/29 12:48:24 UTC
svn commit: r1053619 - in /myfaces/extensions/cdi/trunk:
core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/util/
jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/
jee-modules/jsf-module/impl/src/main/...
Author: gpetracek
Date: Wed Dec 29 11:48:23 2010
New Revision: 1053619
URL: http://svn.apache.org/viewvc?rev=1053619&view=rev
Log:
EXTCDI-109 first draft
Added:
myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/util/AdvancedLiteral.java
myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableConstraintValidatorFactory.java
myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableMessageInterpolator.java
myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidator.java
myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java
Modified:
myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resolver/SerializableValidatorFactory.java
Added: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/util/AdvancedLiteral.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/util/AdvancedLiteral.java?rev=1053619&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/util/AdvancedLiteral.java (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/util/AdvancedLiteral.java Wed Dec 29 11:48:23 2010
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.core.impl.util;
+
+import org.apache.myfaces.extensions.cdi.core.api.Advanced;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class AdvancedLiteral extends AnnotationLiteral<Advanced> implements Advanced
+{
+ private static final long serialVersionUID = -2681697957798404888L;
+}
Modified: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java?rev=1053619&r1=1053618&r2=1053619&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java Wed Dec 29 11:48:23 2010
@@ -53,7 +53,7 @@ public class CdiAwareBeanValidationProdu
validatorFactory = ValidatorFactoryStorage.getOrCreateValidatorFactory();
}
- return new CdiAwareValidatorFactory(validatorFactory);
+ return new InjectableValidatorFactory(new CdiAwareValidatorFactory(validatorFactory));
}
@Produces
@@ -62,8 +62,9 @@ public class CdiAwareBeanValidationProdu
public Validator createValidatorForDependencyInjectionAwareConstraintValidators(
@BeanValidation GenericResolver<ValidatorFactory> validatorFactoryResolver)
{
- return createValidatorFactoryForDependencyInjectionAwareConstraintValidators(
- validatorFactoryResolver).getValidator();
+ return new InjectableValidator(
+ createValidatorFactoryForDependencyInjectionAwareConstraintValidators(
+ validatorFactoryResolver).getValidator());
}
@Produces
@@ -72,8 +73,9 @@ public class CdiAwareBeanValidationProdu
public ConstraintValidatorFactory createConstraintValidatorFactoryForDependencyInjectionAwareConstraintValidators(
@BeanValidation GenericResolver<ValidatorFactory> validatorFactoryResolver)
{
- return createValidatorFactoryForDependencyInjectionAwareConstraintValidators(
- validatorFactoryResolver).getConstraintValidatorFactory();
+ return new InjectableConstraintValidatorFactory(
+ createValidatorFactoryForDependencyInjectionAwareConstraintValidators(validatorFactoryResolver)
+ .getConstraintValidatorFactory());
}
@Produces
@@ -82,7 +84,8 @@ public class CdiAwareBeanValidationProdu
public MessageInterpolator createMessageInterpolator(
@BeanValidation GenericResolver<ValidatorFactory> validatorFactoryResolver)
{
- return createValidatorFactoryForDependencyInjectionAwareConstraintValidators(
- validatorFactoryResolver).getMessageInterpolator();
+ return new InjectableMessageInterpolator(
+ createValidatorFactoryForDependencyInjectionAwareConstraintValidators(validatorFactoryResolver)
+ .getMessageInterpolator());
}
}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableConstraintValidatorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableConstraintValidatorFactory.java?rev=1053619&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableConstraintValidatorFactory.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableConstraintValidatorFactory.java Wed Dec 29 11:48:23 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.cdi.bv.impl;
+
+import org.apache.myfaces.extensions.cdi.core.impl.util.AdvancedLiteral;
+import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorFactory;
+import java.io.Serializable;
+
+/**
+ * @author Gerhard Petracek
+ */
+class InjectableConstraintValidatorFactory implements ConstraintValidatorFactory, Serializable
+{
+ private static final long serialVersionUID = -4851853797257005554L;
+
+ private transient ConstraintValidatorFactory wrapped;
+
+ public InjectableConstraintValidatorFactory()
+ {
+ }
+
+ InjectableConstraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
+ {
+ this.wrapped = constraintValidatorFactory;
+ }
+
+ protected ConstraintValidatorFactory getWrapped()
+ {
+ if(this.wrapped == null)
+ {
+ this.wrapped = CodiUtils
+ .getContextualReferenceByClass(ConstraintValidatorFactory.class, new AdvancedLiteral());
+
+ if(this.wrapped instanceof InjectableConstraintValidatorFactory)
+ {
+ this.wrapped = ((InjectableConstraintValidatorFactory)this.wrapped).getWrapped();
+ }
+ }
+ return this.wrapped;
+ }
+
+ /*
+ * generated
+ */
+ public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> tClass)
+ {
+ return getWrapped().getInstance(tClass);
+ }
+}
Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableMessageInterpolator.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableMessageInterpolator.java?rev=1053619&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableMessageInterpolator.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableMessageInterpolator.java Wed Dec 29 11:48:23 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.cdi.bv.impl;
+
+import org.apache.myfaces.extensions.cdi.core.impl.util.AdvancedLiteral;
+import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
+
+import javax.validation.MessageInterpolator;
+import java.io.Serializable;
+import java.util.Locale;
+
+/**
+ * @author Gerhard Petracek
+ */
+class InjectableMessageInterpolator implements MessageInterpolator, Serializable
+{
+ private static final long serialVersionUID = -68329117991255147L;
+
+ private transient MessageInterpolator wrapped;
+
+ public InjectableMessageInterpolator()
+ {
+ }
+
+ InjectableMessageInterpolator(MessageInterpolator wrapped)
+ {
+ this.wrapped = wrapped;
+ }
+
+ protected MessageInterpolator getWrapped()
+ {
+ if(this.wrapped == null)
+ {
+ this.wrapped = CodiUtils
+ .getContextualReferenceByClass(MessageInterpolator.class, new AdvancedLiteral());
+
+ if(this.wrapped instanceof InjectableMessageInterpolator)
+ {
+ this.wrapped = ((InjectableMessageInterpolator)this.wrapped).getWrapped();
+ }
+ }
+ return this.wrapped;
+ }
+
+ /*
+ * generated
+ */
+ public String interpolate(String s, Context context)
+ {
+ return getWrapped().interpolate(s, context);
+ }
+
+ public String interpolate(String s, Context context, Locale locale)
+ {
+ return getWrapped().interpolate(s, context, locale);
+ }
+}
Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidator.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidator.java?rev=1053619&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidator.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidator.java Wed Dec 29 11:48:23 2010
@@ -0,0 +1,89 @@
+/*
+ * 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.cdi.bv.impl;
+
+import org.apache.myfaces.extensions.cdi.core.impl.util.AdvancedLiteral;
+import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.metadata.BeanDescriptor;
+import java.io.Serializable;
+import java.util.Set;
+
+/**
+ * @author Gerhard Petracek
+ */
+class InjectableValidator implements Validator, Serializable
+{
+ private static final long serialVersionUID = 7925077169313672595L;
+
+ private transient Validator wrapped;
+
+ public InjectableValidator()
+ {
+ }
+
+ InjectableValidator(Validator validator)
+ {
+ this.wrapped = validator;
+ }
+
+ protected Validator getWrapped()
+ {
+ if(this.wrapped == null)
+ {
+ this.wrapped = CodiUtils.getContextualReferenceByClass(Validator.class, new AdvancedLiteral());
+
+ if(this.wrapped instanceof InjectableValidator)
+ {
+ this.wrapped = ((InjectableValidator)this.wrapped).getWrapped();
+ }
+ }
+ return this.wrapped;
+ }
+
+ /*
+ * generated
+ */
+ public <T> Set<ConstraintViolation<T>> validate(T t, Class<?>... classes)
+ {
+ return getWrapped().validate(t, classes);
+ }
+
+ public <T> Set<ConstraintViolation<T>> validateProperty(T t, String s, Class<?>... classes)
+ {
+ return getWrapped().validateProperty(t, s, classes);
+ }
+
+ public <T> Set<ConstraintViolation<T>> validateValue(Class<T> tClass, String s, Object o, Class<?>... classes)
+ {
+ return getWrapped().validateValue(tClass, s, o, classes);
+ }
+
+ public BeanDescriptor getConstraintsForClass(Class<?> aClass)
+ {
+ return getWrapped().getConstraintsForClass(aClass);
+ }
+
+ public <T> T unwrap(Class<T> tClass)
+ {
+ return getWrapped().unwrap(tClass);
+ }
+}
Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java?rev=1053619&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java Wed Dec 29 11:48:23 2010
@@ -0,0 +1,96 @@
+/*
+ * 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.cdi.bv.impl;
+
+import org.apache.myfaces.extensions.cdi.core.impl.util.AdvancedLiteral;
+import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
+
+import javax.validation.ValidatorFactory;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+import javax.validation.ConstraintValidatorFactory;
+import java.io.Serializable;
+
+/**
+ * @author Gerhard Petracek
+ */
+class InjectableValidatorFactory implements ValidatorFactory, Serializable
+{
+ private static final long serialVersionUID = 2200415478496396632L;
+
+ private transient ValidatorFactory wrapped;
+
+ public InjectableValidatorFactory()
+ {
+ }
+
+ InjectableValidatorFactory(ValidatorFactory validatorFactory)
+ {
+ this.wrapped = validatorFactory;
+ }
+
+ protected ValidatorFactory getWrapped()
+ {
+ if(this.wrapped == null)
+ {
+ this.wrapped = CodiUtils.getContextualReferenceByClass(ValidatorFactory.class, new AdvancedLiteral());
+
+ if(this.wrapped instanceof InjectableValidatorFactory)
+ {
+ this.wrapped = ((InjectableValidatorFactory)this.wrapped).getWrapped();
+ }
+ }
+ return this.wrapped;
+ }
+
+ /*
+ * generated
+ */
+ public Validator getValidator()
+ {
+ return getWrapped().getValidator();
+ }
+
+ public ValidatorContext usingContext()
+ {
+ return getWrapped().usingContext();
+ }
+
+ public MessageInterpolator getMessageInterpolator()
+ {
+ return getWrapped().getMessageInterpolator();
+ }
+
+ public TraversableResolver getTraversableResolver()
+ {
+ return getWrapped().getTraversableResolver();
+ }
+
+ public ConstraintValidatorFactory getConstraintValidatorFactory()
+ {
+ return getWrapped().getConstraintValidatorFactory();
+ }
+
+ public <T> T unwrap(Class<T> tClass)
+ {
+ return getWrapped().unwrap(tClass);
+ }
+}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resolver/SerializableValidatorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resolver/SerializableValidatorFactory.java?rev=1053619&r1=1053618&r2=1053619&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resolver/SerializableValidatorFactory.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resolver/SerializableValidatorFactory.java Wed Dec 29 11:48:23 2010
@@ -49,7 +49,7 @@ class SerializableValidatorFactory imple
private transient boolean jsfInitialized = false;
- protected SerializableValidatorFactory()
+ public SerializableValidatorFactory()
{
}