[jboss-cvs] JBossAS SVN: r71300 - in projects/jboss-mdr/trunk/src: tests/org/jboss/test/metadata/loader and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 26 11:49:56 EDT 2008


Author: adrian at jboss.org
Date: 2008-03-26 11:49:56 -0400 (Wed, 26 Mar 2008)
New Revision: 71300

Added:
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/support/
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/support/TestAnnotationMetaDataLoader.java
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/test/
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/test/CustomBasicAnnotationsUnitTestCase.java
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/test/CustomMetaDataLoaderTestSuite.java
Modified:
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/loader/AbstractMetaDataLoader.java
Log:
[JBMDR-19] - Implement retreiveMetaData(String) to look at annotation class names

Modified: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/loader/AbstractMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/loader/AbstractMetaDataLoader.java	2008-03-26 15:17:19 UTC (rev 71299)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/loader/AbstractMetaDataLoader.java	2008-03-26 15:49:56 UTC (rev 71300)
@@ -115,6 +115,18 @@
       return new AnnotationsToMetaDatasBridge(annotations);
    }
 
+   @SuppressWarnings("unchecked")
+   public MetaDataItem<?> retrieveMetaData(String name)
+   {
+      AnnotationsItem annotations = retrieveAnnotations();
+      for (AnnotationItem annotation : annotations.getAnnotations())
+      {
+         if (annotation.getName().equals(name))
+            return new AnnotationToMetaDataBridge(annotation);
+      }
+      return null;
+   }
+
    public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
    {
       if (getScope().getScopeLevel(level) != null)

Added: projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/support/TestAnnotationMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/support/TestAnnotationMetaDataLoader.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/support/TestAnnotationMetaDataLoader.java	2008-03-26 15:49:56 UTC (rev 71300)
@@ -0,0 +1,83 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.metadata.loader.custom.support;
+
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.metadata.plugins.loader.AbstractMetaDataLoader;
+import org.jboss.metadata.spi.retrieval.AnnotationItem;
+import org.jboss.metadata.spi.retrieval.AnnotationsItem;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationItem;
+import org.jboss.metadata.spi.retrieval.simple.SimpleAnnotationsItem;
+import org.jboss.metadata.spi.signature.Signature;
+
+/**
+ * TestAnnotationMetaDataLoader.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestAnnotationMetaDataLoader extends AbstractMetaDataLoader
+{
+   private List<Annotation> annotations;
+
+   public TestAnnotationMetaDataLoader(Annotation... annotations)
+   {
+      this.annotations = Arrays.asList(annotations);
+   }
+   
+   public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
+   {
+      return null;
+   }
+
+   public boolean isEmpty()
+   {
+      return annotations.isEmpty();
+   }
+
+   public <T extends Annotation> AnnotationItem<T> retrieveAnnotation(Class<T> annotationType)
+   {
+      for (Annotation annotation : annotations)
+      {
+         if (annotation.annotationType().equals(annotationType))
+            return new SimpleAnnotationItem<T>(annotationType.cast(annotation));
+      }
+      return null;
+   }
+
+   @SuppressWarnings("unchecked")
+   public AnnotationsItem retrieveAnnotations()
+   {
+      if (annotations.isEmpty())
+         return SimpleAnnotationsItem.NO_ANNOTATIONS;
+      
+      Annotation[] annotations = this.annotations.toArray(new Annotation[0]);
+      AnnotationItem[] items = new AnnotationItem[annotations.length];
+      for (int i = 0; i < items.length; ++i)
+         items[i] = new SimpleAnnotationItem(annotations[i]);
+      return new SimpleAnnotationsItem(items);
+   }
+}

Added: projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/test/CustomBasicAnnotationsUnitTestCase.java
===================================================================
--- projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/test/CustomBasicAnnotationsUnitTestCase.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/test/CustomBasicAnnotationsUnitTestCase.java	2008-03-26 15:49:56 UTC (rev 71300)
@@ -0,0 +1,62 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.metadata.loader.custom.test;
+
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrievalToMetaDataBridge;
+import org.jboss.test.metadata.loader.custom.support.TestAnnotationMetaDataLoader;
+import org.jboss.test.metadata.shared.BasicAnnotationsTest;
+import org.jboss.test.metadata.shared.support.TestAnnotation1Impl;
+import org.jboss.test.metadata.shared.support.TestAnnotation2Impl;
+import org.jboss.test.metadata.shared.support.TestAnnotationImpl;
+
+/**
+ * CustomBasicAnnotationsUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CustomBasicAnnotationsUnitTestCase extends BasicAnnotationsTest
+{
+   public CustomBasicAnnotationsUnitTestCase(String name)
+   {
+      super(name, true);
+   }
+
+   protected MetaData setupEmpty()
+   {
+      TestAnnotationMetaDataLoader loader = new TestAnnotationMetaDataLoader();
+      return new MetaDataRetrievalToMetaDataBridge(loader);
+   }
+
+   protected MetaData setupTestAnnotation()
+   {
+      TestAnnotationMetaDataLoader loader = new TestAnnotationMetaDataLoader(new TestAnnotationImpl());
+      return new MetaDataRetrievalToMetaDataBridge(loader);
+   }
+
+   protected MetaData setupTestAnnotation12()
+   {
+      TestAnnotationMetaDataLoader loader = new TestAnnotationMetaDataLoader(new TestAnnotation1Impl(), new TestAnnotation2Impl());
+      return new MetaDataRetrievalToMetaDataBridge(loader);
+   }
+}

Added: projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/test/CustomMetaDataLoaderTestSuite.java
===================================================================
--- projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/test/CustomMetaDataLoaderTestSuite.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/custom/test/CustomMetaDataLoaderTestSuite.java	2008-03-26 15:49:56 UTC (rev 71300)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.metadata.loader.custom.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * MemoryMetaDataLoader Test Suite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 68681 $
+ */
+public class CustomMetaDataLoaderTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Custom MetaDataLoader Tests");
+
+      suite.addTest(new TestSuite(CustomBasicAnnotationsUnitTestCase.class));
+
+      return suite;
+   }
+}




More information about the jboss-cvs-commits mailing list