[webbeans-commits] Webbeans SVN: r824 - in tck/trunk/api: src/main/java/org/jboss/webbeans/tck/api and 1 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Jan 8 03:38:21 EST 2009
Author: shane.bryzak at jboss.com
Date: 2009-01-08 03:38:21 -0500 (Thu, 08 Jan 2009)
New Revision: 824
Added:
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Configurable.java
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Contexts.java
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/DeploymentProperties.java
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/EnumerationIterable.java
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/EnumerationIterator.java
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/ResourceLoadingException.java
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/SimpleResourceLoader.java
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/Strings.java
Modified:
tck/trunk/api/
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Beans.java
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Managers.java
Log:
More TCK API stuff
Property changes on: tck/trunk/api
___________________________________________________________________
Name: svn:ignore
- target
.classpath
.project
+ target
.classpath
.project
.settings
Modified: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Beans.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Beans.java 2009-01-08 07:41:03 UTC (rev 823)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Beans.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -1,6 +1,11 @@
package org.jboss.webbeans.tck.api;
-public interface Beans
+/**
+ * Provides Bean related operations.
+ *
+ * @author Shane Bryzak
+ */
+public abstract class Beans extends Configurable
{
}
Added: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Configurable.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Configurable.java (rev 0)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Configurable.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.tck.api;
+
+/**
+ *
+ * @author Shane Bryzak
+ *
+ */
+public class Configurable
+{
+ protected static Object getInstance(Class<?> cls)
+ {
+ return null;
+ }
+}
Added: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Contexts.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Contexts.java (rev 0)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Contexts.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.tck.api;
+
+/**
+ *
+ * @author Shane Bryzak
+ */
+public abstract class Contexts extends Configurable
+{
+
+}
Modified: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Managers.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Managers.java 2009-01-08 07:41:03 UTC (rev 823)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Managers.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -5,14 +5,36 @@
import javax.webbeans.manager.Manager;
-public abstract class Managers
+/**
+ * This class provides operations relating to a Web Beans Manager.
+ *
+ * The TCK porting package must provide an implementation of this abstract class which is
+ * suitable for the target Web Beans implementation.
+ *
+ * @author Shane Bryzak
+ */
+public abstract class Managers extends Configurable
{
+ /**
+ * Returns the concrete implementation of Managers
+ *
+ * @return
+ */
public static Managers instance()
{
- return null;
+ return (Managers) getInstance(Managers.class);
}
+ /**
+ *
+ * @param enabledDeploymentTypes
+ */
public abstract void setEnabledDeploymentTypes(List<Class<? extends Annotation>> enabledDeploymentTypes);
+ /**
+ * Creates a new Manager instance
+ *
+ * @return The new Manager
+ */
public abstract Manager createManager();
}
Added: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/DeploymentProperties.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/DeploymentProperties.java (rev 0)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/DeploymentProperties.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -0,0 +1,151 @@
+package org.jboss.webbeans.tck.api.util;
+
+import static org.jboss.webbeans.tck.api.util.Strings.split;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * Utility class to load deployment properties
+ *
+ * @author Pete Muir
+ */
+public class DeploymentProperties
+{
+ // The resource bundle used to control Web Beans RI deployment
+ public static final String RESOURCE_BUNDLE = "META-INF/web-beans-ri.properties";
+
+ // The class to work from
+ private SimpleResourceLoader resourceLoader;
+
+ /**
+ * Constructor
+ *
+ * @param classLoader The classloader to work on
+ */
+ public DeploymentProperties()
+ {
+ this.resourceLoader = new SimpleResourceLoader();
+ }
+
+ /**
+ * Get a list of possible values for a given key.
+ *
+ * First, System properties are tried, followed by the specified resource
+ * bundle (first in classpath only).
+ *
+ * Colon (:) deliminated lists are split out. (gotta love Petes choice of
+ * ASCII art for that one ;-)
+ *
+ * @param key The key to search for
+ * @return A list of possible values. An empty list is returned if there are
+ * no matches.
+ */
+ public List<String> getPropertyValues(String key)
+ {
+ List<String> values = new ArrayList<String>();
+ addPropertiesFromSystem(key, values);
+ addPropertiesFromResourceBundle(key, values);
+ return values;
+ }
+
+ /**
+ * Adds matches from system properties
+ *
+ * @param key The key to match
+ * @param values The currently found values
+ */
+ private void addPropertiesFromSystem(String key, List<String> values)
+ {
+ addProperty(key, System.getProperty(key), values);
+ }
+
+ /**
+ * Adds matches from detected resource bundles
+ *
+ * @param key The key to match
+ * @param values The currently found values
+ */
+ private void addPropertiesFromResourceBundle(String key, List<String> values)
+ {
+ try
+ {
+ for (URL url : resourceLoader.getResources(RESOURCE_BUNDLE))
+ {
+ Properties properties = new Properties();
+ InputStream propertyStream = url.openStream();
+ try
+ {
+ properties.load(propertyStream);
+ addProperty(key, properties.getProperty(key), values);
+ }
+ finally
+ {
+ if (propertyStream != null)
+ {
+ propertyStream.close();
+ }
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ // No - op, file is optional
+ }
+ }
+
+ /**
+ * Add the property to the set of properties only if it hasn't already been
+ * added
+ *
+ * @param key The key searched for
+ * @param value The value of the property
+ * @param values The currently found values
+ */
+ private void addProperty(String key, String value, List<String> values)
+ {
+ if (value != null)
+ {
+ String[] properties = split(value, ":");
+ for (String property : properties)
+ {
+ values.add(property);
+ }
+
+ }
+ }
+
+ /**
+ * Gets the possible implementation class for a given property for which the
+ * values are classanames
+ *
+ * @param deploymentProperties The deployment properties object to use
+ * @param resourceLoader The resource laoder to use to attempt
+ * @param propertyName The name of the property to load
+ * @return A set of classes specified
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> Set<Class<? extends T>> getClasses(DeploymentProperties deploymentProperties, SimpleResourceLoader resourceLoader, String propertyName, Class<T> expectedType)
+ {
+ Set<Class<? extends T>> classes = new HashSet<Class<? extends T>>();
+ for (String className : deploymentProperties.getPropertyValues(propertyName))
+ {
+ try
+ {
+ classes.add((Class<? extends T>) resourceLoader.classForName(className));
+ }
+ catch (ResourceLoadingException e)
+ {
+ //log.debug("Unable to load class " + className + " for property " + propertyName, e);
+ }
+ }
+ return classes;
+ }
+
+}
\ No newline at end of file
Added: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/EnumerationIterable.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/EnumerationIterable.java (rev 0)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/EnumerationIterable.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -0,0 +1,37 @@
+package org.jboss.webbeans.tck.api.util;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * An Enumeration -> Iteratble adaptor
+ *
+ * @author Pete Muir
+ * @see org.jboss.webbeans.util.EnumerationIterator
+ */
+public class EnumerationIterable<T> implements Iterable<T>
+{
+ // The enumeration-iteartor
+ private EnumerationIterator<T> iterator;
+
+ /**
+ * Constructor
+ *
+ * @param enumeration The enumeration
+ */
+ public EnumerationIterable(Enumeration<T> enumeration)
+ {
+ this.iterator = new EnumerationIterator<T>(enumeration);
+ }
+
+ /**
+ * Gets an iterator
+ *
+ * @return The iterator
+ */
+ public Iterator<T> iterator()
+ {
+ return iterator;
+ }
+
+}
\ No newline at end of file
Added: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/EnumerationIterator.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/EnumerationIterator.java (rev 0)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/EnumerationIterator.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -0,0 +1,55 @@
+package org.jboss.webbeans.tck.api.util;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * An enumeration -> iterator adapter
+ *
+ * @author Pete Muir
+ */
+ at SuppressWarnings("unchecked")
+public class EnumerationIterator<T> implements Iterator<T>
+{
+ // The enumeration
+ private Enumeration e;
+
+ /**
+ * Constructor
+ *
+ * @param e The enumeration
+ */
+ public EnumerationIterator(Enumeration e)
+ {
+ this.e = e;
+ }
+
+ /**
+ * Indicates if there are more items to iterate
+ *
+ * @return True if more, false otherwise
+ */
+ public boolean hasNext()
+ {
+ return e.hasMoreElements();
+ }
+
+ /**
+ * Gets the next item
+ *
+ * @return The next items
+ */
+ public T next()
+ {
+ return (T) e.nextElement();
+ }
+
+ /**
+ * Removes an item. Not supported
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+}
\ No newline at end of file
Added: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/ResourceLoadingException.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/ResourceLoadingException.java (rev 0)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/ResourceLoadingException.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -0,0 +1,54 @@
+package org.jboss.webbeans.tck.api.util;
+
+import javax.webbeans.ExecutionException;
+
+/**
+ * Exception thrown when errors occur while loading resource
+ *
+ * @author Pete Muir
+ *
+ */
+public class ResourceLoadingException extends ExecutionException
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor
+ */
+ public ResourceLoadingException()
+ {
+ super();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param message The message
+ * @param throwable The exception
+ */
+ public ResourceLoadingException(String message, Throwable throwable)
+ {
+ super(message, throwable);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param message The message
+ */
+ public ResourceLoadingException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param throwable The exception
+ */
+ public ResourceLoadingException(Throwable throwable)
+ {
+ super(throwable);
+ }
+
+}
\ No newline at end of file
Added: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/SimpleResourceLoader.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/SimpleResourceLoader.java (rev 0)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/SimpleResourceLoader.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -0,0 +1,43 @@
+package org.jboss.webbeans.tck.api.util;
+
+import java.io.IOException;
+import java.net.URL;
+
+public class SimpleResourceLoader
+{
+
+ public Class<?> classForName(String name)
+ {
+
+ try
+ {
+ return Class.forName(name);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ catch (NoClassDefFoundError e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+ public URL getResource(String name)
+ {
+ return getClass().getResource(name);
+ }
+
+ public Iterable<URL> getResources(String name)
+ {
+ try
+ {
+ return new EnumerationIterable<URL>(getClass().getClassLoader().getResources(name));
+ }
+ catch (IOException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+}
\ No newline at end of file
Added: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/Strings.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/Strings.java (rev 0)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/util/Strings.java 2009-01-08 08:38:21 UTC (rev 824)
@@ -0,0 +1,25 @@
+package org.jboss.webbeans.tck.api.util;
+
+import java.util.StringTokenizer;
+
+public class Strings
+{
+ public static String[] split(String strings, String delims)
+ {
+ if (strings == null)
+ {
+ return new String[0];
+ }
+ else
+ {
+ StringTokenizer tokens = new StringTokenizer(strings, delims);
+ String[] result = new String[tokens.countTokens()];
+ int i = 0;
+ while (tokens.hasMoreTokens())
+ {
+ result[i++] = tokens.nextToken();
+ }
+ return result;
+ }
+ }
+}
More information about the weld-commits
mailing list