Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
438 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
weld/src/main/java/org/jboss/weld/experimental/ExperimentalAnnotated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.experimental; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.reflect.AnnotatedElement; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Collections; | ||
import java.util.LinkedHashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import javax.enterprise.inject.spi.Annotated; | ||
|
||
/** | ||
* This API is experimental and will change! All the methods declared by this interface are supposed to be moved to {@link Annotated}. | ||
* | ||
* @author Jozef Hartinger | ||
* | ||
* @see WELD-1743 | ||
* | ||
* @param <X> | ||
*/ | ||
public interface ExperimentalAnnotated extends Annotated { | ||
|
||
/** | ||
* Equivalent of {@link AnnotatedElement#getAnnotationsByType(Class)}. | ||
* | ||
* @param annotationClass the Class object corresponding to the annotation type | ||
* @return all this element's annotations for the specified annotation type if associated with this element, else an array of length zero | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
default <T extends Annotation> Set<T> getAnnotationsByType(Class<T> annotationClass) { | ||
Objects.requireNonNull(annotationClass, "annotationClass"); | ||
// first, delegate to getAnnotation() | ||
final T annotation = getAnnotation(annotationClass); | ||
if (annotation != null) { | ||
return Collections.singleton(annotation); | ||
} | ||
// second, check if this annotation is repeatable | ||
final Repeatable repeatable = annotationClass.getAnnotation(Repeatable.class); | ||
if (repeatable != null) { | ||
Class<? extends Annotation> containerClass = repeatable.value(); | ||
Annotation container = getAnnotation(containerClass); | ||
if (container != null) { | ||
// we found a container, extract the values | ||
Method value; | ||
try { | ||
value = containerClass.getMethod("value"); | ||
} catch (NoSuchMethodException | SecurityException e) { | ||
throw new RuntimeException(e); // TODO | ||
} | ||
Set<T> result = new LinkedHashSet<>(); | ||
try { | ||
Collections.addAll(result, (T[]) value.invoke(container)); | ||
return result; | ||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | ||
throw new RuntimeException(e); // TODO | ||
} | ||
} | ||
} | ||
return Collections.emptySet(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
weld/src/main/java/org/jboss/weld/experimental/ExperimentalAnnotatedParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.experimental; | ||
|
||
import java.lang.reflect.Executable; | ||
import java.lang.reflect.Member; | ||
import java.lang.reflect.Parameter; | ||
|
||
import javax.enterprise.inject.spi.AnnotatedParameter; | ||
|
||
/** | ||
* This API is experimental and will change! All the methods declared by this interface are supposed to be moved to {@link AnnotatedParameter}. | ||
* | ||
* All the methods declared by this interface should be moved to AnnotatedParameter. | ||
* | ||
* @author Jozef Hartinger | ||
* @see CDI-481 | ||
* | ||
* @param <X> | ||
*/ | ||
public interface ExperimentalAnnotatedParameter<X> extends AnnotatedParameter<X> { | ||
|
||
/** | ||
* Get the underlying {@link Parameter}. | ||
* | ||
* @return the {@link Parameter} | ||
*/ | ||
default Parameter getJavaParameter() { | ||
Member member = getDeclaringCallable().getJavaMember(); | ||
if (!(member instanceof Executable)) { | ||
throw new IllegalStateException("Parameter does not belong to an executable " + member); | ||
} | ||
Executable executable = (Executable) member; | ||
return executable.getParameters()[getPosition()]; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
weld/src/main/java/org/jboss/weld/experimental/ExperimentalInvocationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.experimental; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Set; | ||
|
||
import javax.interceptor.Interceptors; | ||
import javax.interceptor.InvocationContext; | ||
|
||
/** | ||
* This API is experimental and will change! All the methods declared by this interface are supposed to be moved to {@link InvocationContext}. | ||
* | ||
* @author Martin Kouba | ||
* @see CDI-468 | ||
* | ||
*/ | ||
public interface ExperimentalInvocationContext extends InvocationContext { | ||
|
||
/** | ||
* The returning set may be empty if only interceptors using the {@link Interceptors} annotation are associated. | ||
* | ||
* @return a set of interceptor bindings | ||
*/ | ||
<T extends Annotation> Set<T> getInterceptorBindingsByType(Class<T> annotationType); | ||
|
||
/** | ||
* The returning set may be empty if only interceptors using the {@link Interceptors} annotation are associated. | ||
* | ||
* @return a set of interceptor bindings | ||
*/ | ||
Set<Annotation> getInterceptorBindings(); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
weld/src/main/java/org/jboss/weld/experimental/ExperimentalObserverMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.experimental; | ||
|
||
import javax.enterprise.inject.spi.ObserverMethod; | ||
import javax.interceptor.Interceptor; | ||
|
||
/** | ||
* This API is experimental and will change! All the methods declared by this interface are supposed to be moved to {@link ObserverMethod}. | ||
* | ||
* @author Jozef Hartinger | ||
* @see WELD-1728 | ||
* | ||
* @param <T> the event type | ||
*/ | ||
public interface ExperimentalObserverMethod<T> extends ObserverMethod<T>, Prioritized { | ||
|
||
/** | ||
* Default priority for observer methods that do not define priority. Currently the default priority is set to be in the middle | ||
* of the "APPLICATION" range (see {@link Interceptor.Priority} for details). | ||
* | ||
* WARNING: This concept of default priority of an observer method is preliminary and subject to change. | ||
*/ | ||
int DEFAULT_PRIORITY = 2500; | ||
|
||
/** | ||
* The priority of this observer method | ||
*/ | ||
default int getPriority() { | ||
return DEFAULT_PRIORITY; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
weld/src/main/java/org/jboss/weld/experimental/ExperimentalProcessObserverMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.experimental; | ||
|
||
import javax.enterprise.inject.spi.ObserverMethod; | ||
import javax.enterprise.inject.spi.ProcessObserverMethod; | ||
|
||
/** | ||
* This API is experimental and will change! All the methods declared by this interface are supposed to be moved to {@link ProcessObserverMethod}. | ||
* | ||
* @author Jozef Hartinger | ||
* @see WELD-1749 | ||
* | ||
* @param <T> The type of the event being observed | ||
* @param <X> The bean type containing the observer method | ||
*/ | ||
public interface ExperimentalProcessObserverMethod<T, X> extends ProcessObserverMethod<T, X> { | ||
|
||
/** | ||
* Replaces the observer method. | ||
* | ||
* @param observer | ||
*/ | ||
void setObserverMethod(ObserverMethod<T> observerMethod); | ||
|
||
/** | ||
* Forces the container to ignore the observer method. | ||
*/ | ||
void veto(); | ||
|
||
/** | ||
* Temporarilly overriden return type | ||
*/ | ||
@Override | ||
ExperimentalObserverMethod<T> getObserverMethod(); | ||
} |
32 changes: 32 additions & 0 deletions
32
weld/src/main/java/org/jboss/weld/experimental/Prioritized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.experimental; | ||
|
||
/** | ||
* This API is experimental and will change! | ||
* | ||
* An optional interface - we don't want to force users to specify priority if not needed. | ||
*/ | ||
public interface Prioritized { | ||
|
||
/** | ||
* | ||
* @return the priority | ||
*/ | ||
int getPriority(); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
weld/src/main/java/org/jboss/weld/experimental/Priority.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.jboss.weld.experimental; | ||
|
||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* This API is experimental and will change! | ||
* | ||
* This annotation duplicates {@link javax.annotation.Priority}. Unlike {@link javax.annotation.Priority}, this annotation can also be applied on parameters | ||
* which makes it usable for specifying the priority of observer methods. | ||
* | ||
* In the future, {@link javax.annotation.Priority} will be updated and this annotation will be removed. | ||
* | ||
* @author Jozef Hartinger | ||
* | ||
*/ | ||
@Target({ TYPE, PARAMETER }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
public @interface Priority { | ||
int value(); | ||
} |
Oops, something went wrong.