You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/04/15 20:41:59 UTC
[3/3] DELTASPIKE-129 move AnnotationBuilder and stuff to util package
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotationBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotationBuilder.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotationBuilder.java
new file mode 100644
index 0000000..0230149
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotationBuilder.java
@@ -0,0 +1,173 @@
+/*
+ * 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.deltaspike.core.util.metadata.builder;
+
+import org.apache.deltaspike.core.util.ReflectionUtils;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A store of annotations to be used {@link AnnotatedTypeBuilder} and other places
+ * where a collection of annotations needs manipulation.
+ */
+public class AnnotationBuilder
+{
+ private final Map<Class<? extends Annotation>, Annotation> annotationMap;
+ private final Set<Annotation> annotationSet;
+
+ /**
+ * Default constructor.
+ */
+ public AnnotationBuilder()
+ {
+ this.annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+ this.annotationSet = new HashSet<Annotation>();
+ }
+
+ /**
+ * Adds the annotation to the collections.
+ *
+ * @param annotation annotation to be added
+ * @return this
+ */
+ public AnnotationBuilder add(Annotation annotation)
+ {
+ if (annotation == null)
+ {
+ throw new IllegalArgumentException("annotation parameter must not be null");
+ }
+ annotationSet.add(annotation);
+ annotationMap.put(annotation.annotationType(), annotation);
+ return this;
+ }
+
+ /**
+ * Removes the given annotation from the collections.
+ *
+ * @param annotationType to be removed
+ * @return this
+ */
+ public AnnotationBuilder remove(Class<? extends Annotation> annotationType)
+ {
+ if (annotationType == null)
+ {
+ throw new IllegalArgumentException("annotationType parameter must not be null");
+ }
+
+ Iterator<Annotation> it = annotationSet.iterator();
+ while (it.hasNext())
+ {
+ Annotation an = it.next();
+ if (annotationType.isAssignableFrom(an.annotationType()))
+ {
+ it.remove();
+ }
+ }
+ annotationMap.remove(annotationType);
+ return this;
+ }
+
+ /**
+ * Creates an {@link AnnotationStore} using the annotations from this instance.
+ *
+ * @return new AnnotationStore
+ */
+ public AnnotationStore create()
+ {
+ return new AnnotationStore(annotationMap, annotationSet);
+ }
+
+ /**
+ * Adds all annotations from the given collection
+ *
+ * @param annotations collection of annotations to be added
+ * @return this
+ */
+ public AnnotationBuilder addAll(Collection<Annotation> annotations)
+ {
+ for (Annotation annotation : annotations)
+ {
+ add(annotation);
+ }
+ return this;
+ }
+
+ /**
+ * Adds all annotations from an {@link AnnotationStore}.
+ *
+ * @param annotations annotations to be added
+ * @return this
+ */
+ public AnnotationBuilder addAll(AnnotationStore annotations)
+ {
+ for (Annotation annotation : annotations.getAnnotations())
+ {
+ add(annotation);
+ }
+ return this;
+ }
+
+ /**
+ * Adds all annotations from the given {@link AnnotatedElement}.
+ *
+ * @param element element containing annotations to be added
+ * @return this
+ */
+ public AnnotationBuilder addAll(AnnotatedElement element)
+ {
+ for (Annotation a : element.getAnnotations())
+ {
+ add(a);
+ }
+ return this;
+ }
+
+ /**
+ * Getter.
+ */
+ public <T extends Annotation> T getAnnotation(Class<T> anType)
+ {
+ return ReflectionUtils.<T>cast(annotationMap.get(anType));
+ }
+
+ /**
+ * Simple check for an annotation.
+ */
+ public boolean isAnnotationPresent(Class<?> annotationType)
+ {
+ return annotationMap.containsKey(annotationType);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString()
+ {
+ return annotationSet.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotationStore.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotationStore.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotationStore.java
new file mode 100644
index 0000000..8a9c813
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotationStore.java
@@ -0,0 +1,64 @@
+/*
+ * 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.deltaspike.core.util.metadata.builder;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.Set;
+
+import static java.util.Collections.emptyMap;
+import static java.util.Collections.emptySet;
+import static java.util.Collections.unmodifiableSet;
+
+/**
+ * A helper class used to hold annotations on a type or member.
+ */
+class AnnotationStore
+{
+ private final Map<Class<? extends Annotation>, Annotation> annotationMap;
+ private final Set<Annotation> annotationSet;
+
+ AnnotationStore(Map<Class<? extends Annotation>, Annotation> annotationMap, Set<Annotation> annotationSet)
+ {
+ this.annotationMap = annotationMap;
+ this.annotationSet = unmodifiableSet(annotationSet);
+ }
+
+ AnnotationStore()
+ {
+ this.annotationMap = emptyMap();
+ this.annotationSet = emptySet();
+ }
+
+ <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ return annotationType.cast(annotationMap.get(annotationType));
+ }
+
+ Set<Annotation> getAnnotations()
+ {
+ return annotationSet;
+ }
+
+ boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ return annotationMap.containsKey(annotationType);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/ImmutableInjectionPoint.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/ImmutableInjectionPoint.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/ImmutableInjectionPoint.java
new file mode 100644
index 0000000..8780361
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/ImmutableInjectionPoint.java
@@ -0,0 +1,182 @@
+/*
+ * 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.deltaspike.core.util.metadata.builder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.deltaspike.core.util.BeanUtils;
+
+import static java.util.Collections.unmodifiableSet;
+
+/**
+ * <p>
+ * A base class for implementing {@link InjectionPoint}. The attributes are
+ * immutable, and collections are defensively copied on instantiation.
+ * </p>
+ */
+public class ImmutableInjectionPoint implements InjectionPoint
+{
+
+ private final Annotated annotated;
+ private final Member member;
+ private final Bean<?> declaringBean;
+ private final Set<Annotation> qualifiers;
+ private final Type type;
+ private final boolean isTransient;
+ private final boolean delegate;
+
+ /**
+ * Instantiate a new {@link InjectionPoint} based upon an
+ * {@link AnnotatedField}.
+ *
+ * @param field the field for which to create the injection point
+ * @param qualifiers the qualifiers on the injection point
+ * @param declaringBean the declaringBean declaring the injection point
+ * @param isTransient <code>true</code> if the injection point is transient
+ * @param delegate <code>true</code> if the injection point is a delegate
+ * injection point on a decorator
+ */
+ public ImmutableInjectionPoint(AnnotatedField<?> field, Set<Annotation> qualifiers, Bean<?> declaringBean,
+ boolean isTransient, boolean delegate)
+ {
+ this.annotated = field;
+ this.member = field.getJavaMember();
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.type = field.getJavaMember().getGenericType();
+ this.isTransient = isTransient;
+ this.delegate = delegate;
+ this.declaringBean = declaringBean;
+ }
+
+ /**
+ * Instantiate a new {@link InjectionPoint} based upon an
+ * {@link AnnotatedField}, reading the qualifiers from the annotations
+ * declared on the field.
+ *
+ * @param field the field for which to create the injection point
+ * @param declaringBean the declaringBean declaring the injection point
+ * @param isTransient <code>true</code> if the injection point is transient
+ * @param delegate <code>true</code> if the injection point is a delegate
+ * injection point on a decorator
+ */
+ public ImmutableInjectionPoint(AnnotatedField<?> field, BeanManager beanManager, Bean<?> declaringBean,
+ boolean isTransient, boolean delegate)
+ {
+ this.annotated = field;
+ this.member = field.getJavaMember();
+ this.qualifiers = BeanUtils.getQualifiers(beanManager, field.getAnnotations());
+ this.type = field.getJavaMember().getGenericType();
+ this.isTransient = isTransient;
+ this.delegate = delegate;
+ this.declaringBean = declaringBean;
+ }
+
+ /**
+ * Instantiate a new {@link InjectionPoint} based upon an
+ * {@link AnnotatedParameter}.
+ *
+ * @param parameter the parameter for which to create the injection point
+ * @param qualifiers the qualifiers on the injection point
+ * @param declaringBean the declaringBean declaring the injection point
+ * @param isTransient <code>true</code> if the injection point is transient
+ * @param delegate <code>true</code> if the injection point is a delegate
+ * injection point on a decorator
+ */
+ public ImmutableInjectionPoint(AnnotatedParameter<?> parameter, Set<Annotation> qualifiers, Bean<?> declaringBean,
+ boolean isTransient, boolean delegate)
+ {
+ this.annotated = parameter;
+ this.member = parameter.getDeclaringCallable().getJavaMember();
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.isTransient = isTransient;
+ this.delegate = delegate;
+ this.declaringBean = declaringBean;
+ this.type = parameter.getBaseType();
+ }
+
+ /**
+ * Instantiate a new {@link InjectionPoint} based upon an
+ * {@link AnnotatedParameter}, reading the qualifiers from the annotations
+ * declared on the parameter.
+ *
+ * @param parameter the parameter for which to create the injection point
+ * @param declaringBean the declaringBean declaring the injection point
+ * @param isTransient <code>true</code> if the injection point is transient
+ * @param delegate <code>true</code> if the injection point is a delegate
+ * injection point on a decorator
+ */
+ public ImmutableInjectionPoint(AnnotatedParameter<?> parameter, BeanManager beanManager, Bean<?> declaringBean,
+ boolean isTransient, boolean delegate)
+ {
+ this.annotated = parameter;
+ this.member = parameter.getDeclaringCallable().getJavaMember();
+ this.qualifiers = BeanUtils.getQualifiers(beanManager, parameter.getAnnotations());
+ this.isTransient = isTransient;
+ this.delegate = delegate;
+ this.declaringBean = declaringBean;
+ this.type = parameter.getBaseType();
+ }
+
+ public Annotated getAnnotated()
+ {
+ return annotated;
+ }
+
+ public Bean<?> getBean()
+ {
+ return declaringBean;
+ }
+
+ public Member getMember()
+ {
+ return member;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return unmodifiableSet(qualifiers);
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+
+ public boolean isDelegate()
+ {
+ return delegate;
+ }
+
+ public boolean isTransient()
+ {
+ return isTransient;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/InjectableMethod.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/InjectableMethod.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/InjectableMethod.java
new file mode 100644
index 0000000..392bb43
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/InjectableMethod.java
@@ -0,0 +1,205 @@
+/*
+ * 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.deltaspike.core.util.metadata.builder;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.deltaspike.core.util.metadata.builder.ParameterValueRedefiner.ParameterValue;
+
+import static org.apache.deltaspike.core.util.BeanUtils.createInjectionPoints;
+import static org.apache.deltaspike.core.util.ReflectionUtils.invokeMethod;
+
+/**
+ * <p>
+ * Allows an {@link AnnotatedMethod} to be injected using the CDI type safe
+ * resolution rules.
+ * </p>
+ * <p/>
+ * <p>
+ * {@link ParameterValueRedefiner} allows the default value to be overridden by
+ * the caller of
+ * {@link #invoke(Object, CreationalContext, ParameterValueRedefiner)}.
+ * </p>
+ *
+ * @param <X> the declaring type
+ */
+public class InjectableMethod<X>
+{
+ private final AnnotatedMethod<X> method;
+ private final List<InjectionPoint> parameters;
+ private final BeanManager beanManager;
+
+ /**
+ * Instantiate a new {@link InjectableMethod}.
+ *
+ * @param method the method which will be injected upon a call to
+ * {@link #invoke(Object, CreationalContext)}
+ * @param declaringBean the bean which defines the injectable method
+ * @param beanManager the {@link BeanManager} to use to obtain the parameter values
+ */
+ public InjectableMethod(AnnotatedMethod<X> method, Bean<?> declaringBean, BeanManager beanManager)
+ {
+ this(method, createInjectionPoints(method, declaringBean, beanManager), beanManager);
+ }
+
+ /**
+ * Instantiate a new {@link InjectableMethod}.
+ *
+ * @param method the method which will be injected upon a call to
+ * {@link #invoke(Object, CreationalContext)}
+ * @param parameters a collection of injection points representing the
+ * parameters of the method
+ * @param beanManager the {@link BeanManager} to use to obtain the parameter
+ * values
+ */
+ public InjectableMethod(AnnotatedMethod<X> method, Collection<InjectionPoint> parameters, BeanManager beanManager)
+ {
+ this.method = method;
+ this.parameters = new ArrayList<InjectionPoint>(parameters);
+ this.beanManager = beanManager;
+ }
+
+ /**
+ * Get the bean manager used by this injectable method.
+ *
+ * @return the bean manager in use
+ */
+ protected BeanManager getBeanManager()
+ {
+ return beanManager;
+ }
+
+ /**
+ * Get the injectable parameters of this method.
+ *
+ * @return a collection of injection points representing the parameters of
+ * this method
+ */
+ protected List<InjectionPoint> getParameters()
+ {
+ return parameters;
+ }
+
+ /**
+ * Invoke the method, causing all parameters to be injected according to the
+ * CDI type safe resolution rules.public class ParameterValueRedefiner {
+ * <p/>
+ * }
+ *
+ * @param <T> the return type of the method
+ * @param receiver the instance upon which to call the method
+ * @param creationalContext the creational context to use to obtain
+ * injectable references for each parameter
+ * @return the result of invoking the method or null if the method's return
+ * type is void
+ * @throws RuntimeException if this <code>Method</code> object enforces Java
+ * language access control and the underlying method is
+ * inaccessible or if the underlying method throws an exception or
+ * if the initialization provoked by this method fails.
+ * @throws IllegalArgumentException if the method is an instance method and
+ * the specified <code>receiver</code> argument is not an instance
+ * of the class or interface declaring the underlying method (or
+ * of a subclass or implementor thereof); if an unwrapping
+ * conversion for primitive arguments fails; or if, after possible
+ * unwrapping, a parameter value cannot be converted to the
+ * corresponding formal parameter type by a method invocation
+ * conversion.
+ * @throws NullPointerException if the specified <code>receiver</code> is
+ * null and the method is an instance method.
+ * @throws ExceptionInInitializerError if the initialization provoked by this
+ * method fails.
+ */
+ public <T> T invoke(Object receiver, CreationalContext<T> creationalContext)
+ {
+ return invoke(receiver, creationalContext, null);
+ }
+
+ /**
+ * Invoke the method, calling the parameter redefiner for each parameter,
+ * allowing the caller to override the default value obtained via the CDI
+ * type safe resolver.
+ *
+ * @param <T> the return type of the method
+ * @param receiver the instance upon which to call the method
+ * @param creationalContext the creational context to use to obtain
+ * injectable references for each parameter
+ * @return the result of invoking the method or null if the method's return
+ * type is void
+ * @throws RuntimeException if this <code>Method</code> object enforces Java
+ * language access control and the underlying method is
+ * inaccessible or if the underlying method throws an exception or
+ * if the initialization provoked by this method fails.
+ * @throws IllegalArgumentException if the method is an instance method and
+ * the specified <code>receiver</code> argument is not an instance
+ * of the class or interface declaring the underlying method (or
+ * of a subclass or implementor thereof); if an unwrapping
+ * conversion for primitive arguments fails; or if, after possible
+ * unwrapping, a parameter value cannot be converted to the
+ * corresponding formal parameter type by a method invocation
+ * conversion.
+ * @throws NullPointerException if the specified <code>receiver</code> is
+ * null and the method is an instance method.
+ * @throws ExceptionInInitializerError if the initialization provoked by this
+ * method fails.
+ */
+ public <T> T invoke(Object receiver, CreationalContext<T> creationalContext, ParameterValueRedefiner redefinition)
+ {
+ List<Object> parameterValues = new ArrayList<Object>();
+ for (int i = 0; i < getParameters().size(); i++)
+ {
+ if (redefinition != null)
+ {
+ ParameterValue value = new ParameterValue(i, getParameters().get(i), getBeanManager());
+ parameterValues.add(redefinition.redefineParameterValue(value));
+ }
+ else
+ {
+ parameterValues.add(getBeanManager().getInjectableReference(getParameters().get(i), creationalContext));
+ }
+ }
+
+ try
+ {
+ @SuppressWarnings({ "unchecked", "UnnecessaryLocalVariable" })
+ T result =
+ (T) invokeMethod(receiver, method.getJavaMember(), Object.class, true, parameterValues.toArray());
+ return result;
+ }
+ catch (RuntimeException e)
+ {
+ //X TODO check if it is compatible with Weld
+ //workaround for OWB which wraps InvocationTargetException the original exception
+ //see ReflectionUtils#invokeMethod
+ if (RuntimeException.class.getName().equals(e.getClass().getName()) &&
+ e.getCause() instanceof RuntimeException)
+ {
+ throw (RuntimeException)e.getCause();
+ }
+ throw e;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/ParameterValueRedefiner.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/ParameterValueRedefiner.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/ParameterValueRedefiner.java
new file mode 100644
index 0000000..c9e2a47
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/ParameterValueRedefiner.java
@@ -0,0 +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.
+ */
+package org.apache.deltaspike.core.util.metadata.builder;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+/**
+ * Provides the ability to redefine the value of a parameter on an
+ * {@link InjectableMethod} via the
+ * {@link #redefineParameterValue(ParameterValue)} callback.
+ *
+ * @see InjectableMethod
+ */
+public interface ParameterValueRedefiner
+{
+ /**
+ * Callback allowing the default parameter value (that which would be
+ * injected according to the CDI type safe resolution rules) to be
+ * overridden.
+ *
+ * @param value the default value
+ * @return the overridden value
+ */
+ Object redefineParameterValue(ParameterValue value);
+
+ /**
+ * Provides the default parameter's value, along with metadata about the
+ * parameter to a parameter redefinition.
+ *
+ * @see ParameterValueRedefiner
+ * @see InjectableMethod
+ */
+ public static class ParameterValue
+ {
+
+ private final int position;
+ private final InjectionPoint injectionPoint;
+ private final BeanManager beanManager;
+
+ ParameterValue(int position, InjectionPoint injectionPoint, BeanManager beanManager)
+ {
+ this.position = position;
+ this.injectionPoint = injectionPoint;
+ this.beanManager = beanManager;
+ }
+
+ /**
+ * Get the position of the parameter in the member's parameter list.
+ *
+ * @return the position of the parameter
+ */
+ public int getPosition()
+ {
+ return position;
+ }
+
+ /**
+ * Get the {@link InjectionPoint} for the parameter.
+ *
+ * @return the injection point
+ */
+ public InjectionPoint getInjectionPoint()
+ {
+ return injectionPoint;
+ }
+
+ /**
+ * Get the default value of the parameter. The default value is that which
+ * would be injected according to the CDI type safe resolution rules.
+ *
+ * @param creationalContext the creationalContext to use to obtain the
+ * injectable reference.
+ * @return the default value
+ */
+ public Object getDefaultValue(CreationalContext<?> creationalContext)
+ {
+ return beanManager.getInjectableReference(injectionPoint, creationalContext);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java
index 2489941..66deb57 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/metadata/AnnotatedTypeBuilderTest.java
@@ -24,7 +24,7 @@ import org.apache.deltaspike.core.api.literal.AnyLiteral;
import org.apache.deltaspike.core.api.literal.ApplicationScopedLiteral;
import org.apache.deltaspike.core.api.literal.NamedLiteral;
import org.apache.deltaspike.core.api.literal.TypedLiteral;
-import org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder;
+import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
import org.junit.Test;
import javax.enterprise.context.ApplicationScoped;
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
index 55ac2c8..e52d417 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
@@ -24,8 +24,8 @@ import org.apache.deltaspike.core.api.exception.control.annotation.Handles;
import org.apache.deltaspike.core.api.exception.control.event.ExceptionEvent;
import org.apache.deltaspike.core.api.exception.control.HandlerMethod;
import org.apache.deltaspike.core.api.literal.AnyLiteral;
-import org.apache.deltaspike.core.api.metadata.builder.ImmutableInjectionPoint;
-import org.apache.deltaspike.core.api.metadata.builder.InjectableMethod;
+import org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint;
+import org.apache.deltaspike.core.util.metadata.builder.InjectableMethod;
import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
import org.apache.deltaspike.core.api.provider.BeanProvider;
import org.apache.deltaspike.core.util.BeanUtils;
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java
index 1857dfc..fcef05c 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/OutboundParameterValueRedefiner.java
@@ -20,7 +20,7 @@
package org.apache.deltaspike.core.impl.exception.control;
import org.apache.deltaspike.core.api.exception.control.event.ExceptionEvent;
-import org.apache.deltaspike.core.api.metadata.builder.ParameterValueRedefiner;
+import org.apache.deltaspike.core.util.metadata.builder.ParameterValueRedefiner;
import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
import javax.enterprise.context.spi.CreationalContext;
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
index c285b38..cb8a519 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
@@ -20,7 +20,7 @@ package org.apache.deltaspike.core.impl.exclude.extension;
import org.apache.deltaspike.core.api.config.ConfigResolver;
import org.apache.deltaspike.core.api.exclude.annotation.Exclude;
-import org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder;
+import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
import org.apache.deltaspike.core.impl.exclude.CustomProjectStageBeanFilter;
import org.apache.deltaspike.core.impl.exclude.GlobalAlternative;
import org.apache.deltaspike.core.spi.activation.Deactivatable;
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/metadata/NamingConventionAwareMetadataFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/metadata/NamingConventionAwareMetadataFilter.java b/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/metadata/NamingConventionAwareMetadataFilter.java
index 18cd501..6e6c4fc 100644
--- a/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/metadata/NamingConventionAwareMetadataFilter.java
+++ b/deltaspike/examples/jse-examples/src/main/java/org/apache/deltaspike/example/metadata/NamingConventionAwareMetadataFilter.java
@@ -19,7 +19,7 @@
package org.apache.deltaspike.example.metadata;
import org.apache.deltaspike.core.api.literal.NamedLiteral;
-import org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder;
+import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Extension;
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/Authorizer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/Authorizer.java b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/Authorizer.java
index 2621a6c..8a3b14a 100644
--- a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/Authorizer.java
+++ b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/Authorizer.java
@@ -35,7 +35,7 @@ import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.util.Nonbinding;
import javax.interceptor.InvocationContext;
-import org.apache.deltaspike.core.api.metadata.builder.InjectableMethod;
+import org.apache.deltaspike.core.util.metadata.builder.InjectableMethod;
import org.apache.deltaspike.security.api.authorization.AccessDeniedException;
import org.apache.deltaspike.security.api.authorization.SecurityDefinitionException;
import org.apache.deltaspike.security.api.authorization.SecurityViolation;
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityExtension.java b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityExtension.java
index 1a389ed..1ec1760 100644
--- a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityExtension.java
+++ b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityExtension.java
@@ -19,7 +19,7 @@
package org.apache.deltaspike.security.impl.authorization;
-import org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder;
+import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
import org.apache.deltaspike.core.spi.activation.Deactivatable;
import org.apache.deltaspike.core.util.ClassDeactivationUtils;
import org.apache.deltaspike.core.util.ClassUtils;
@@ -284,4 +284,4 @@ public class SecurityExtension implements Extension, Deactivatable
isActivated = ClassDeactivationUtils.isActivated(getClass());
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/78d0434e/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityParameterValueRedefiner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityParameterValueRedefiner.java b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityParameterValueRedefiner.java
index 1f483e2..fa51f8a 100644
--- a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityParameterValueRedefiner.java
+++ b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityParameterValueRedefiner.java
@@ -30,7 +30,7 @@ import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.interceptor.InvocationContext;
-import org.apache.deltaspike.core.api.metadata.builder.ParameterValueRedefiner;
+import org.apache.deltaspike.core.util.metadata.builder.ParameterValueRedefiner;
import org.apache.deltaspike.security.api.authorization.annotation.SecurityParameterBinding;
/**