You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2010/01/26 10:40:58 UTC
svn commit: r903142 -
/commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java
Author: simonetripodi
Date: Tue Jan 26 09:40:58 2010
New Revision: 903142
URL: http://svn.apache.org/viewvc?rev=903142&view=rev
Log:
first checkin of AnnotationRuleProviderUtils class
Added:
commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java (with props)
Added: commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java?rev=903142&view=auto
==============================================================================
--- commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java (added)
+++ commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java Tue Jan 26 09:40:58 2010
@@ -0,0 +1,72 @@
+/*
+ * 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.commons.digester.annotations.utils;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+
+import org.apache.commons.beanutils.ConstructorUtils;
+import org.apache.commons.digester.Rule;
+import org.apache.commons.digester.annotations.AnnotationRuleProvider;
+
+/**
+ * Utilities class to manipulate the {@link AnnotationRuleProvider} instances.
+ *
+ * @version $Id$
+ * @since 2.1
+ */
+public final class AnnotationRuleProviderUtils {
+
+ /**
+ * Private constructor, this class can't be instantiated.
+ */
+ private AnnotationRuleProviderUtils() {
+ // do nothing
+ }
+
+ /**
+ * Builds a new {@link AnnotationRuleProvider} instance.
+ *
+ * @param <A> the annotation type.
+ * @param <E> the annotated element type.
+ * @param <R> the reflected digester rule type.
+ * @param klass the {@link AnnotationRuleProvider} type has to be instantiated.
+ * @param annotation the current visited annotation.
+ * @param element the current visited element.
+ * @param rule the reflected commons-digester rule.
+ * @return a new {@link AnnotationRuleProvider} instance.
+ */
+ public static <A extends Annotation, E extends AnnotatedElement, R extends Rule> AnnotationRuleProvider<A, E, R> newProvider(Class<? extends AnnotationRuleProvider<A, E, R>> klass,
+ A annotation,
+ E element,
+ R rule) {
+ Object[] args = new Object[] { annotation, element };
+ Class<?>[] parameterTypes = new Class<?>[] { annotation.annotationType(), element.getClass() };
+
+ try {
+ Object o = ConstructorUtils.invokeExactConstructor(klass,
+ args,
+ parameterTypes);
+ return klass.cast(o);
+ } catch (Throwable t) {
+ throw new RuntimeException("Impossible to instantiate provider of type '"
+ + klass.getName()
+ + "', see nested exceptions", t);
+ }
+ }
+
+}
Propchange: commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain