Seam SVN: r11885 - in modules/envconfig/trunk: src/main/java/org/jboss/seam/envconfig and 1 other directories.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2009-12-24 12:23:08 -0500 (Thu, 24 Dec 2009)
New Revision: 11885
Modified:
modules/envconfig/trunk/readme.txt
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/EnvironmentBinding.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
Log:
JavaDoc (credit to Matt Corey)
Modified: modules/envconfig/trunk/readme.txt
===================================================================
--- modules/envconfig/trunk/readme.txt 2009-12-23 22:41:14 UTC (rev 11884)
+++ modules/envconfig/trunk/readme.txt 2009-12-24 17:23:08 UTC (rev 11885)
@@ -30,3 +30,12 @@
Then inject the resource:
@Resource(lookup = "java:global/adminUser") User user;
+
+TODO:
+
+- Add tests (learning Arquillian first)
+- Support unbinding, either with @Unbind, or by simply handling a 'null' value for unbind
+- Support binding producer methods
+- Make 'value' optional on @Bind, using the property name for the binding if not provided (may need to qualify it with class name, possibly even module name?)
+- Implement JndiBinder as a Servlet for non-EJB containers?
+- Create web and/or REST interface to display/reprocess bindings?
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java 2009-12-23 22:41:14 UTC (rev 11884)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java 2009-12-24 17:23:08 UTC (rev 11885)
@@ -22,12 +22,27 @@
import java.lang.annotation.Target;
/**
+ * An annotation that can be applied to any field or method to indicate that
+ * its value should be bound to JNDI under the key provided in the 'value'
+ * attribute.
+ *
* @author Matt Corey
*/
@Target( { ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Bind
{
+ /**
+ * The JNDI key to bind the value to. If the value is not a full JNDI name,
+ * then the value will be prefixed with 'java:/global/', putting the value
+ * into the global JNDI namespace.
+ */
String value();
+
+ /**
+ * Specify whether or not to overwrite a value that may already exist at the
+ * provided JNDI name. If overwrite is set to false, the binding will be
+ * ignored if a value already exists.
+ */
boolean overwrite() default true;
}
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/EnvironmentBinding.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/EnvironmentBinding.java 2009-12-23 22:41:14 UTC (rev 11884)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/EnvironmentBinding.java 2009-12-24 17:23:08 UTC (rev 11885)
@@ -25,6 +25,10 @@
import javax.enterprise.inject.Stereotype;
/**
+ * A stereotype that can be applied to any class that should be processed for
+ * @Bind fields or methods. Any bean with this stereotype applied will default
+ * to application-scoped.
+ *
* @author Matt Corey
*/
@Stereotype
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java 2009-12-23 22:41:14 UTC (rev 11884)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java 2009-12-24 17:23:08 UTC (rev 11885)
@@ -31,6 +31,11 @@
import org.slf4j.LoggerFactory;
/**
+ * A CDI portable extension class that is resposible for listening to
+ * ProcessBean events, and 'collecting' beans that have the @EnvironmentBinding
+ * stereotype annotation. A startup bean will then iterate over these
+ * beans and process the JNDI bindings.
+ *
* @author Matt Corey
*/
public class EnvironmentBindingExtension implements Extension
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-23 22:41:14 UTC (rev 11884)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-24 17:23:08 UTC (rev 11885)
@@ -34,6 +34,9 @@
import org.slf4j.LoggerFactory;
/**
+ * An EJB Singleton-based implementation that actually processes the
+ * @EnvironmentBinding annotated classes.
+ *
* @author Matt Corey
*/
public @Singleton @Startup class JndiBinder
15 years
Seam SVN: r11884 - modules/envconfig/trunk.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2009-12-23 17:41:14 -0500 (Wed, 23 Dec 2009)
New Revision: 11884
Modified:
modules/envconfig/trunk/readme.txt
Log:
note that it is portable
Modified: modules/envconfig/trunk/readme.txt
===================================================================
--- modules/envconfig/trunk/readme.txt 2009-12-23 22:40:16 UTC (rev 11883)
+++ modules/envconfig/trunk/readme.txt 2009-12-23 22:41:14 UTC (rev 11884)
@@ -1,6 +1,8 @@
Seam Environment Configuration
==============================
+Extension type: Portable Extension (PE)
+
Example:
The following bean will cause the string "Hello World!" to
15 years
Seam SVN: r11883 - modules/envconfig/trunk.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2009-12-23 17:40:16 -0500 (Wed, 23 Dec 2009)
New Revision: 11883
Modified:
modules/envconfig/trunk/readme.txt
Log:
add notes
Modified: modules/envconfig/trunk/readme.txt
===================================================================
--- modules/envconfig/trunk/readme.txt 2009-12-23 22:33:00 UTC (rev 11882)
+++ modules/envconfig/trunk/readme.txt 2009-12-23 22:40:16 UTC (rev 11883)
@@ -12,10 +12,19 @@
public @EnvironmentBinding class EnvironmentVars
{
- @Bind("msg") private final String msg = "Hello World!";
+ @Bind("msg") String msg = "Hello World!";
+
}
You can then inject the value into a managed bean as follows:
@Resource(lookup = "java:global/msg") String msg;
+You can also bind custom objects:
+
+// somewhere in the same deployment must be a producer for @Admin User
+@Inject @Admin @Bind("adminUser") User user;
+
+Then inject the resource:
+
+@Resource(lookup = "java:global/adminUser") User user;
15 years
Seam SVN: r11881 - modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2009-12-23 17:12:35 -0500 (Wed, 23 Dec 2009)
New Revision: 11881
Removed:
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/Placeholder.java
Modified:
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
Log:
Placeholder bean fix was a fallacy; turns out I was using javax.inject.Singleton
fix some logging
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java 2009-12-23 21:48:36 UTC (rev 11880)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java 2009-12-23 22:12:35 UTC (rev 11881)
@@ -35,7 +35,7 @@
*/
public class EnvironmentBindingExtension implements Extension
{
- private Logger log = LoggerFactory.getLogger(getClass().getName());
+ private static Logger log = LoggerFactory.getLogger(EnvironmentBindingExtension.class);
private Set<Bean> envBeans = new HashSet<Bean>();
private BeanManager beanManager;
@@ -53,7 +53,7 @@
{
if (st.equals(EnvironmentBinding.class))
{
- log.debug("Found class annotated with EnvironmentBinding: " + beanClass.getName());
+ log.debug("Found class annotated with @EnvironmentBinding: " + beanClass.getName());
envBeans.add(bean);
break;
}
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-23 21:48:36 UTC (rev 11880)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-23 22:12:35 UTC (rev 11881)
@@ -20,12 +20,12 @@
import java.util.Set;
import javax.annotation.PostConstruct;
+import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.spi.Context;
import javax.enterprise.inject.spi.Bean;
import javax.inject.Inject;
-import javax.inject.Singleton;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -38,7 +38,7 @@
*/
public @Singleton @Startup class JndiBinder
{
- private Logger log = LoggerFactory.getLogger(JndiBinder.class);
+ private static Logger log = LoggerFactory.getLogger(JndiBinder.class);
@Inject
private EnvironmentBindingExtension bindingExtension;
@@ -48,7 +48,7 @@
{
Set<Bean> envBeans = bindingExtension.getEnvBeans();
- log.debug("Processing EnvironmentBinding Classes: " + envBeans);
+ log.debug("Processing @EnvironmentBinding classes: " + envBeans);
Context appContext = bindingExtension.getBeanManager().getContext(ApplicationScoped.class);
for (Bean bean : envBeans)
@@ -62,7 +62,7 @@
{
if (field.isAnnotationPresent(Bind.class))
{
- log.debug("Processing Binding field " + beanClass.getName() + "." + field.getName());
+ log.debug("Processing @Bind field " + beanClass.getName() + "." + field.getName());
field.setAccessible(true);
@@ -96,13 +96,13 @@
if (!overwrite) {
try {
ic.lookup(name);
- log.debug("JNDI name " + name + " already bound and overwrite is disabled");
+ log.debug("Skipping binding; JNDI name " + name + " is already bound and overwrite is disabled");
return;
}
catch (NamingException e) {
}
}
- log.debug("Binding " + name + " to " + value);
+ log.debug("Binding " + value + " to JNDI name " + name);
ic.rebind(name, value);
}
}
Deleted: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/Placeholder.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/Placeholder.java 2009-12-23 21:48:36 UTC (rev 11880)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/Placeholder.java 2009-12-23 22:12:35 UTC (rev 11881)
@@ -1,28 +0,0 @@
-/*
- * Seam 3 Modules - http://seamframework.org
- * CDI portable extensions for Java EE and non-Java EE technologies
- *
- * JBoss, by Red Hat
- *
- * This library 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;
- * version 2.1 of the License.
- *
- * This library 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.
- */
-package org.jboss.seam.envconfig.extension;
-
-import javax.ejb.Stateless;
-
-/**
- * This is a temporary class that is present because GlassFish V3 doesn't seem
- * to recognize an EJB-JAR archive as valid if it only has a @Singleton bean.
- *
- * @author Dan Alen
- */
-public @Stateless class Placeholder {
-}
15 years
Seam SVN: r11880 - modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2009-12-23 16:48:36 -0500 (Wed, 23 Dec 2009)
New Revision: 11880
Modified:
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
Log:
switch info log message to debug
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java 2009-12-23 21:46:11 UTC (rev 11879)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java 2009-12-23 21:48:36 UTC (rev 11880)
@@ -53,7 +53,7 @@
{
if (st.equals(EnvironmentBinding.class))
{
- log.info("Found class annotated with EnvironmentBinding: " + beanClass.getName());
+ log.debug("Found class annotated with EnvironmentBinding: " + beanClass.getName());
envBeans.add(bean);
break;
}
15 years
Seam SVN: r11879 - in modules/envconfig/trunk: src/main/java/org/jboss/seam/envconfig and 1 other directories.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2009-12-23 16:46:11 -0500 (Wed, 23 Dec 2009)
New Revision: 11879
Modified:
modules/envconfig/trunk/readme.txt
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
Log:
change jndiAddress attribute to value to simplify annotation declaration
Modified: modules/envconfig/trunk/readme.txt
===================================================================
--- modules/envconfig/trunk/readme.txt 2009-12-23 21:42:36 UTC (rev 11878)
+++ modules/envconfig/trunk/readme.txt 2009-12-23 21:46:11 UTC (rev 11879)
@@ -12,7 +12,7 @@
public @EnvironmentBinding class EnvironmentVars
{
- @Bind(jndiAddress="msg") private final String msg = "Hello World!";
+ @Bind("msg") private final String msg = "Hello World!";
}
You can then inject the value into a managed bean as follows:
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java 2009-12-23 21:42:36 UTC (rev 11878)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java 2009-12-23 21:46:11 UTC (rev 11879)
@@ -28,6 +28,6 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface Bind
{
- String jndiAddress();
+ String value();
boolean overwrite() default true;
}
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-23 21:42:36 UTC (rev 11878)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-23 21:46:11 UTC (rev 11879)
@@ -67,7 +67,7 @@
field.setAccessible(true);
Bind ann = field.getAnnotation(Bind.class);
- String jndi = ann.jndiAddress();
+ String jndi = ann.value();
boolean overwrite = ann.overwrite();
Object val = field.get(beanInstance);
15 years
Seam SVN: r11878 - in modules/envconfig/trunk: src/main/java/org/jboss/seam/envconfig/extension and 1 other directory.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2009-12-23 16:42:36 -0500 (Wed, 23 Dec 2009)
New Revision: 11878
Modified:
modules/envconfig/trunk/pom.xml
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
Log:
honor overwrite flag
switch to slf4j
Modified: modules/envconfig/trunk/pom.xml
===================================================================
--- modules/envconfig/trunk/pom.xml 2009-12-23 21:12:45 UTC (rev 11877)
+++ modules/envconfig/trunk/pom.xml 2009-12-23 21:42:36 UTC (rev 11878)
@@ -73,6 +73,11 @@
<scope>provided</scope>
<version>3.1.0</version>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java 2009-12-23 21:12:45 UTC (rev 11877)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java 2009-12-23 21:42:36 UTC (rev 11878)
@@ -19,21 +19,23 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-import java.util.logging.Logger;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessBean;
+
import org.jboss.seam.envconfig.EnvironmentBinding;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Matt Corey
*/
public class EnvironmentBindingExtension implements Extension
{
- private Logger log = Logger.getLogger(getClass().getName());
+ private Logger log = LoggerFactory.getLogger(getClass().getName());
private Set<Bean> envBeans = new HashSet<Bean>();
private BeanManager beanManager;
Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-23 21:12:45 UTC (rev 11877)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-23 21:42:36 UTC (rev 11878)
@@ -18,7 +18,6 @@
import java.lang.reflect.Field;
import java.util.Set;
-import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.Startup;
@@ -29,14 +28,17 @@
import javax.inject.Singleton;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+
import org.jboss.seam.envconfig.Bind;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Matt Corey
*/
public @Singleton @Startup class JndiBinder
{
- private Logger log = Logger.getLogger(getClass().getName());
+ private Logger log = LoggerFactory.getLogger(JndiBinder.class);
@Inject
private EnvironmentBindingExtension bindingExtension;
@@ -46,7 +48,7 @@
{
Set<Bean> envBeans = bindingExtension.getEnvBeans();
- log.info("Processing EnvironmentBinding Classes: " + envBeans);
+ log.debug("Processing EnvironmentBinding Classes: " + envBeans);
Context appContext = bindingExtension.getBeanManager().getContext(ApplicationScoped.class);
for (Bean bean : envBeans)
@@ -60,20 +62,22 @@
{
if (field.isAnnotationPresent(Bind.class))
{
- log.info("Processing Binding field " + beanClass.getName() + "." + field.getName());
+ log.debug("Processing Binding field " + beanClass.getName() + "." + field.getName());
field.setAccessible(true);
- String jndi = field.getAnnotation(Bind.class).jndiAddress();
+ Bind ann = field.getAnnotation(Bind.class);
+ String jndi = ann.jndiAddress();
+ boolean overwrite = ann.overwrite();
Object val = field.get(beanInstance);
- bindValue(jndi, val);
+ bindValue(jndi, val, overwrite);
}
}
}
}
- private void bindValue(String nameSuffix, Object value) throws NamingException
+ private void bindValue(String nameSuffix, Object value, boolean overwrite) throws NamingException
{
InitialContext ic = new InitialContext();
@@ -87,7 +91,18 @@
}
}
nameToBind.append(nameSuffix);
- log.info("Bound " + nameToBind + " to " + value);
- ic.rebind(nameToBind.toString(), value);
+ String name = nameToBind.toString();
+
+ if (!overwrite) {
+ try {
+ ic.lookup(name);
+ log.debug("JNDI name " + name + " already bound and overwrite is disabled");
+ return;
+ }
+ catch (NamingException e) {
+ }
+ }
+ log.debug("Binding " + name + " to " + value);
+ ic.rebind(name, value);
}
}
15 years
Seam SVN: r11877 - in modules: envconfig and 12 other directories.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2009-12-23 16:12:45 -0500 (Wed, 23 Dec 2009)
New Revision: 11877
Added:
modules/envconfig/
modules/envconfig/branches/
modules/envconfig/tags/
modules/envconfig/trunk/
modules/envconfig/trunk/pom.xml
modules/envconfig/trunk/readme.txt
modules/envconfig/trunk/src/
modules/envconfig/trunk/src/main/
modules/envconfig/trunk/src/main/java/
modules/envconfig/trunk/src/main/java/org/
modules/envconfig/trunk/src/main/java/org/jboss/
modules/envconfig/trunk/src/main/java/org/jboss/seam/
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/EnvironmentBinding.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/Placeholder.java
modules/envconfig/trunk/src/main/resources/
modules/envconfig/trunk/src/main/resources/META-INF/
modules/envconfig/trunk/src/main/resources/META-INF/beans.xml
modules/envconfig/trunk/src/main/resources/META-INF/services/
modules/envconfig/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Log:
add new module: envconfig
module driver: Matt Corey
Property changes on: modules/envconfig/trunk
___________________________________________________________________
Name: svn:ignore
+ target
.project
.classpath
.settings
Added: modules/envconfig/trunk/pom.xml
===================================================================
--- modules/envconfig/trunk/pom.xml (rev 0)
+++ modules/envconfig/trunk/pom.xml 2009-12-23 21:12:45 UTC (rev 11877)
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-parent</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-envconfig</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <packaging>ejb</packaging>
+
+ <name>Seam Environment Configuration</name>
+ <description>A set of CDI extensions that deal with configuration of the Java EE environment (e.g., binding to JNDI)</description>
+ <inceptionYear>2009</inceptionYear>
+
+ <developers>
+ <developer>
+ <name>Matt Corey</name>
+ <url>http://smokeandice.blogspot.com</url>
+ <timezone>GMT-05:00</timezone>
+ <roles>
+ <role>Module driver</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>dan.j.allen</id>
+ <name>Dan Allen</name>
+ <email>dan.j.allen(a)gmail.com</email>
+ <url>http://in.relation.to/Bloggers/Dan</url>
+ <organization>JBoss, by Red Hat</organization>
+ <timezone>GMT-05:00</timezone>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ </developers>
+
+ <properties>
+ <seam.version>3.0.0-SNAPSHOT</seam.version>
+ </properties>
+
+ <!-- Snapshots repo to get parent -->
+ <repositories>
+ <repository>
+ <id>oss.sonatype.org/jboss-snapshots</id>
+ <name>JBoss (Nexus) Snapshots Repository</name>
+ <url>http://oss.sonatype.org/content/repositories/jboss-snapshots</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <scope>provided</scope>
+ <version>3.1.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ejb-plugin</artifactId>
+ <configuration>
+ <ejbVersion>3.0</ejbVersion>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/envconfig/trunk</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/envconfig/trunk</developerConnection>
+ <url>http://fisheye.jboss.org/browse/Seam/modules/envconfig/trunk</url>
+ </scm>
+
+</project>
Added: modules/envconfig/trunk/readme.txt
===================================================================
--- modules/envconfig/trunk/readme.txt (rev 0)
+++ modules/envconfig/trunk/readme.txt 2009-12-23 21:12:45 UTC (rev 11877)
@@ -0,0 +1,21 @@
+Seam Environment Configuration
+==============================
+
+Example:
+
+The following bean will cause the string "Hello World!" to
+be bound to the JNDI name java:global/msg when the archive
+that contains this bean is deployed.
+
+import org.jboss.seam.envconfig.Bind;
+import org.jboss.seam.envconfig.EnvironmentBinding;
+
+public @EnvironmentBinding class EnvironmentVars
+{
+ @Bind(jndiAddress="msg") private final String msg = "Hello World!";
+}
+
+You can then inject the value into a managed bean as follows:
+
+@Resource(lookup = "java:global/msg") String msg;
+
Added: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java (rev 0)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java 2009-12-23 21:12:45 UTC (rev 11877)
@@ -0,0 +1,33 @@
+/*
+ * Seam 3 Modules - http://seamframework.org
+ * CDI portable extensions for Java EE and non-Java EE technologies
+ *
+ * JBoss, by Red Hat
+ *
+ * This library 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;
+ * version 2.1 of the License.
+ *
+ * This library 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.
+ */
+package org.jboss.seam.envconfig;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Matt Corey
+ */
+@Target( { ElementType.METHOD, ElementType.FIELD })
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Bind
+{
+ String jndiAddress();
+ boolean overwrite() default true;
+}
Added: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/EnvironmentBinding.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/EnvironmentBinding.java (rev 0)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/EnvironmentBinding.java 2009-12-23 21:12:45 UTC (rev 11877)
@@ -0,0 +1,36 @@
+/*
+ * Seam 3 Modules - http://seamframework.org
+ * CDI portable extensions for Java EE and non-Java EE technologies
+ *
+ * JBoss, by Red Hat
+ *
+ * This library 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;
+ * version 2.1 of the License.
+ *
+ * This library 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.
+ */
+package org.jboss.seam.envconfig;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Stereotype;
+
+/**
+ * @author Matt Corey
+ */
+@Stereotype
+@ApplicationScoped
+(a)Target(ElementType.TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface EnvironmentBinding
+{
+}
Added: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java (rev 0)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java 2009-12-23 21:12:45 UTC (rev 11877)
@@ -0,0 +1,70 @@
+/*
+ * Seam 3 Modules - http://seamframework.org
+ * CDI portable extensions for Java EE and non-Java EE technologies
+ *
+ * JBoss, by Red Hat
+ *
+ * This library 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;
+ * version 2.1 of the License.
+ *
+ * This library 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.
+ */
+package org.jboss.seam.envconfig.extension;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessBean;
+import org.jboss.seam.envconfig.EnvironmentBinding;
+
+/**
+ * @author Matt Corey
+ */
+public class EnvironmentBindingExtension implements Extension
+{
+ private Logger log = Logger.getLogger(getClass().getName());
+
+ private Set<Bean> envBeans = new HashSet<Bean>();
+ private BeanManager beanManager;
+
+ public void discoverEnvironmentBindingClasses(@Observes ProcessBean pb, BeanManager bm) throws Exception
+ {
+ this.beanManager = bm;
+
+ Bean bean = pb.getBean();
+ Class beanClass = bean.getBeanClass();
+
+ Set<Class> sts = bean.getStereotypes();
+
+ for (Class st : sts)
+ {
+ if (st.equals(EnvironmentBinding.class))
+ {
+ log.info("Found class annotated with EnvironmentBinding: " + beanClass.getName());
+ envBeans.add(bean);
+ break;
+ }
+ }
+ }
+
+ public Set<Bean> getEnvBeans()
+ {
+ return Collections.unmodifiableSet(envBeans);
+ }
+
+ public BeanManager getBeanManager()
+ {
+ return beanManager;
+ }
+}
Added: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java (rev 0)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-23 21:12:45 UTC (rev 11877)
@@ -0,0 +1,93 @@
+/*
+ * Seam 3 Modules - http://seamframework.org
+ * CDI portable extensions for Java EE and non-Java EE technologies
+ *
+ * JBoss, by Red Hat
+ *
+ * This library 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;
+ * version 2.1 of the License.
+ *
+ * This library 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.
+ */
+package org.jboss.seam.envconfig.extension;
+
+import java.lang.reflect.Field;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Startup;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.inject.spi.Bean;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.jboss.seam.envconfig.Bind;
+
+/**
+ * @author Matt Corey
+ */
+public @Singleton @Startup class JndiBinder
+{
+ private Logger log = Logger.getLogger(getClass().getName());
+
+ @Inject
+ private EnvironmentBindingExtension bindingExtension;
+
+ @PostConstruct
+ public void processBindings() throws Exception
+ {
+ Set<Bean> envBeans = bindingExtension.getEnvBeans();
+
+ log.info("Processing EnvironmentBinding Classes: " + envBeans);
+
+ Context appContext = bindingExtension.getBeanManager().getContext(ApplicationScoped.class);
+ for (Bean bean : envBeans)
+ {
+ Class beanClass = bean.getBeanClass();
+
+ Object beanInstance = appContext.get(bean, bindingExtension.getBeanManager().createCreationalContext(bean));
+
+ Field[] fields = beanClass.getDeclaredFields();
+ for (Field field : fields)
+ {
+ if (field.isAnnotationPresent(Bind.class))
+ {
+ log.info("Processing Binding field " + beanClass.getName() + "." + field.getName());
+
+ field.setAccessible(true);
+
+ String jndi = field.getAnnotation(Bind.class).jndiAddress();
+ Object val = field.get(beanInstance);
+
+ bindValue(jndi, val);
+ }
+ }
+ }
+ }
+
+ private void bindValue(String nameSuffix, Object value) throws NamingException
+ {
+ InitialContext ic = new InitialContext();
+
+ StringBuilder nameToBind = new StringBuilder();
+ if (!nameSuffix.matches("java:/?global"))
+ {
+ nameToBind.append("java:global");
+ if (!nameSuffix.endsWith("/"))
+ {
+ nameToBind.append('/');
+ }
+ }
+ nameToBind.append(nameSuffix);
+ log.info("Bound " + nameToBind + " to " + value);
+ ic.rebind(nameToBind.toString(), value);
+ }
+}
Added: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/Placeholder.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/Placeholder.java (rev 0)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/Placeholder.java 2009-12-23 21:12:45 UTC (rev 11877)
@@ -0,0 +1,28 @@
+/*
+ * Seam 3 Modules - http://seamframework.org
+ * CDI portable extensions for Java EE and non-Java EE technologies
+ *
+ * JBoss, by Red Hat
+ *
+ * This library 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;
+ * version 2.1 of the License.
+ *
+ * This library 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.
+ */
+package org.jboss.seam.envconfig.extension;
+
+import javax.ejb.Stateless;
+
+/**
+ * This is a temporary class that is present because GlassFish V3 doesn't seem
+ * to recognize an EJB-JAR archive as valid if it only has a @Singleton bean.
+ *
+ * @author Dan Alen
+ */
+public @Stateless class Placeholder {
+}
Added: modules/envconfig/trunk/src/main/resources/META-INF/beans.xml
===================================================================
Added: modules/envconfig/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- modules/envconfig/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension (rev 0)
+++ modules/envconfig/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2009-12-23 21:12:45 UTC (rev 11877)
@@ -0,0 +1 @@
+org.jboss.seam.envconfig.extension.EnvironmentBindingExtension
\ No newline at end of file
15 years
Seam SVN: r11876 - modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2009-12-23 05:36:41 -0500 (Wed, 23 Dec 2009)
New Revision: 11876
Modified:
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
why am i using an array?! that's crazy!!
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2009-12-23 10:22:55 UTC (rev 11875)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2009-12-23 10:36:41 UTC (rev 11876)
@@ -1,5 +1,5 @@
var Seam = {
- beans: new Array(),
+ beans: {},
debug: false,
debugWindow: null,
PATH_EXECUTE: "/execute",
@@ -9,26 +9,20 @@
}
Seam.createBean = function(name) {
- var b = Seam.beans;
- for (var i=0; i<b.length; i++) {
- if (b[i].__name == name) {
- var v = new b[i];
- if (arguments.length > 1) {
- v.__qualifiers = new Array();
- for (var j=1; j<arguments.length; j++) {
- v.__qualifiers.push(arguments[j]);
- }
- }
- return v;
+ if (!Seam.beans[name]) return null;
+ var b = new Seam.beans[name];
+ if (arguments.length > 1) {
+ b.__qualifiers = new Array();
+ for (var i=1; i<arguments.length; i++) {
+ b.__qualifiers.push(arguments[i]);
}
}
- return null;
+ return b;
}
Seam.getBeanType = function(obj) {
- var b = Seam.beans;
- for (var i=0; i<b.length; i++) {
- if (obj instanceof b[i]) return b[i];
+ for (var b in Seam.beans) {
+ if (obj instanceof Seam.beans[b]) return Seam.beans[b];
}
return undefined;
}
@@ -67,23 +61,11 @@
}
}
- var b = Seam.beans;
- for (var i=0; i<b.length; i++) {
- if (b[i].__name == name) {
- b[i] = t;
- return;
- }
- }
- b.push(t);
+ Seam.beans[name] = t;
}
Seam.isBeanRegistered = function(name) {
- var b = Seam.beans;
- for (var i=0; i<b.length; i++) {
- if (b[i].__name == name)
- return true;
- }
- return false;
+ return Seam.beans[name] != null;
}
Seam.getBeanMetadata = function(obj) {
15 years