You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/07/15 21:52:41 UTC
git commit: DELTASPIKE-115 improved javadoc
Updated Branches:
refs/heads/master fed8806a6 -> ed4c3759a
DELTASPIKE-115 improved javadoc
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/ed4c3759
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/ed4c3759
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/ed4c3759
Branch: refs/heads/master
Commit: ed4c3759aa802024318d0dd4bad8c708ec77ceab
Parents: fed8806
Author: gpetracek <gp...@apache.org>
Authored: Sun Jul 15 15:59:56 2012 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Sun Jul 15 21:51:13 2012 +0200
----------------------------------------------------------------------
.../core/api/config/annotation/ConfigProperty.java | 79 ++++++++++++++-
1 files changed, 74 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/ed4c3759/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/annotation/ConfigProperty.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/annotation/ConfigProperty.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/annotation/ConfigProperty.java
index 7145506..a4279cd 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/annotation/ConfigProperty.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/annotation/ConfigProperty.java
@@ -35,15 +35,84 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* <p>This Qualifier allows to use the DeltaSpike configuration mechanism
* via simple injection.</p>
*
- * <p>A small usage Example:
+ * <p>Example 1:
* <pre>
- * @Inject @ConfigProperty(name="database")
- * private String configuredDatabase;
+ * @Inject @ConfigProperty(name="locationId")
+ * private String locationId;
* </pre>
* </p>
*
- * <p>See the sample in {@link org.apache.deltaspike.core.spi.config.BaseConfigPropertyProducer}
- * for how to implement own configuration injection.</p>
+ * <p>Example 2 (the type-safe alternative):
+ *
+ * <pre>
+ * @Target({ FIELD, METHOD })
+ * @Retention(RUNTIME)
+ * @ConfigProperty(name = "locationId")
+ * @Qualifier
+ * public @interface Location
+ * {
+ * }
+ * </pre>
+ * </p>
+ *
+ * Depending on the producer it's possible to use a String or a custom type like an enum at the injection point.
+ * <p/>
+ * With a String:
+ * <pre>
+ * @Location
+ * private String locationId;
+ * </pre>
+ *
+ * With a custom type:
+ * <pre>
+ * @Inject
+ * @Location
+ * private LocationId locationId;
+ * </pre>
+ * <p>In any case a custom producer is needed.
+ * {@link org.apache.deltaspike.core.spi.config.BaseConfigPropertyProducer} can be used as an base for custom
+ * producers.
+ * Producer for the configured String:
+ * <pre>
+ * @ApplicationScoped
+ * public class CustomConfigPropertyProducer extends BaseConfigPropertyProducer
+ * {
+ * @Produces
+ * @Dependent
+ * @Location
+ * public String produceLocationId(InjectionPoint injectionPoint)
+ * {
+ * String configuredValue = getStringPropertyValue(injectionPoint);
+ *
+ * if (configuredValue == null)
+ * {
+ * return "LOCATION_X";
+ * }
+ * return configuredValue;
+ * }
+ * }
+ * </pre>
+ *
+ * Producer for a custom type:
+ * <pre>
+ * @ApplicationScoped
+ * public class CustomConfigPropertyProducer extends BaseConfigPropertyProducer
+ * {
+ * @Produces
+ * @Dependent
+ * @Location
+ * public LocationId produceLocationId(InjectionPoint injectionPoint)
+ * {
+ * String configuredValue = getStringPropertyValue(injectionPoint);
+ *
+ * if (configuredValue == null)
+ * {
+ * return LocationId.LOCATION_X;
+ * }
+ * return LocationId.valueOf(configuredValue.trim().toUpperCase());
+ * }
+ * }
+ * </pre>
*
* @see org.apache.deltaspike.core.api.config.ConfigResolver
* @see org.apache.deltaspike.core.spi.config.BaseConfigPropertyProducer