Author: dan.j.allen
Date: 2009-12-24 12:41:26 -0500 (Thu, 24 Dec 2009)
New Revision: 11886
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/JndiBinder.java
Log:
put example in JavaDoc
fix invalid logic in binder
Modified: modules/envconfig/trunk/readme.txt
===================================================================
--- modules/envconfig/trunk/readme.txt 2009-12-24 17:23:08 UTC (rev 11885)
+++ modules/envconfig/trunk/readme.txt 2009-12-24 17:41:26 UTC (rev 11886)
@@ -15,7 +15,6 @@
public @EnvironmentBinding class EnvironmentVars
{
@Bind("msg") 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-24
17:23:08 UTC (rev 11885)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/Bind.java 2009-12-24
17:41:26 UTC (rev 11886)
@@ -34,7 +34,7 @@
{
/**
* 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
+ * then the value will be prefixed with 'java:global/', putting the value
* into the global JNDI namespace.
*/
String value();
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-24
17:23:08 UTC (rev 11885)
+++
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/EnvironmentBinding.java 2009-12-24
17:41:26 UTC (rev 11886)
@@ -26,9 +26,37 @@
/**
* 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.
- *
+ * {@link @Bind} fields or methods. Any bean with this stereotype applied will
+ * default to application-scoped.
+ *
+ * <pre>
+ * @EnvironmentBinding
+ * public class EnvironmentVars {
+ * @Bind("msg")
+ * String msg = "Hello World!";
+ * }
+ * </pre>
+ *
+ * <p>
+ * EnvironemntBinding classes are expected to contain fields and/or methods
+ * annotated with @Bind. The values of those fields and methods are bound
+ * to the JNDI name provided in the value attribute of the annotation. The value
+ * can be any object. If the JNDI name provided is not prefixed with java:, then
+ * the java:global/ prefix is added to the name.
+ * </p>
+ *
+ * <p>
+ * Once the binding occurs, the JNDI resource can be injected into the field of
+ * a managed bean:
+ * </p>
+ *
+ * <pre>
+ * public class Greeter {
+ * @Resource(lookup = "java:global/msg")
+ * String msg;
+ * }
+ * </pre>
+ *
* @author Matt Corey
*/
@Stereotype
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-24
17:23:08 UTC (rev 11885)
+++
modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java 2009-12-24
17:41:26 UTC (rev 11886)
@@ -69,31 +69,29 @@
field.setAccessible(true);
- Bind ann = field.getAnnotation(Bind.class);
- String jndi = ann.value();
- boolean overwrite = ann.overwrite();
- Object val = field.get(beanInstance);
+ Bind binding = field.getAnnotation(Bind.class);
+ String jndiName = binding.value();
+ boolean overwrite = binding.overwrite();
+ Object value = field.get(beanInstance);
- bindValue(jndi, val, overwrite);
+ bindValue(jndiName, value, overwrite);
}
}
}
}
- private void bindValue(String nameSuffix, Object value, boolean overwrite) throws
NamingException
+ private void bindValue(String jndiName, Object value, boolean overwrite) throws
NamingException
{
InitialContext ic = new InitialContext();
StringBuilder nameToBind = new StringBuilder();
- if (!nameSuffix.matches("java:/?global"))
+ // JNDI name may be java:global, java:module, java:app or java:comp/env
+ // if none of those, then we default to java:global
+ if (!jndiName.startsWith("java:"))
{
- nameToBind.append("java:global");
- if (!nameSuffix.endsWith("/"))
- {
- nameToBind.append('/');
- }
+ nameToBind.append("java:global/");
}
- nameToBind.append(nameSuffix);
+ nameToBind.append(jndiName);
String name = nameToBind.toString();
if (!overwrite) {
Show replies by date