Enum Class AvailableDependencies
- All Implemented Interfaces:
Serializable,Comparable<AvailableDependencies>,Constable
Inject annotation on a type's constructor. Unless otherwise
noted these services will always be available.- Author:
- cdivilly
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionProvide an API for working withAnnotationinstances.Provides aConfigurationinstance appropriate for the backing store that the current request is targeted to.Provides aConnectionconnected to the appropriate database pool and schema, inferred from mapping the request URL.Provides an API for discovering at run-time the available implementations of a service.ProvidesIOStreamsservice for manipulating input and output streams.Provides access to theJSONStreamsservice, which can be used to parse character streams into JSON (usingJSONReader) and to generate JSON usingJSONWriter.Provides access to theJSONObjectsservice, which can be used to build in memory representations of JSON object graphs.Provides the most preferredLocalefor a requestProvides aLocalePreferenceinstance, which enumerates the preferredLocales for a request from most to least preferred.Provides access to the the JDKLoggerservice.Provides methods for working withPathTemplateMatchinstances -
Method Summary
Modifier and TypeMethodDescriptionThe Annotations that may constrain the scope of the dependencyClass<?>type()The type of the dependencystatic AvailableDependenciesReturns the enum constant of this class with the specified name.static AvailableDependencies[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
ANNOTATIONS
Provide an API for working with
Annotationinstances. This API may be useful in unit tests to define expectedAnnotationvalues.Usage
@Provides class SomeTestFixture { @Inject SomeTestFixture(Annotations annotations) { this.expectedNamedAnnotation = annotations.literal(Named.class,"foo"); } ... } -
CONFIGURATION
Provides a
Configurationinstance appropriate for the backing store that the current request is targeted to. If this service is called from anApplicationScopedservice, then the global configuration is used.Usage
@Provides @Dispatches(@PathTemplate("/some/service")) class SomeService extends HttpServlet { @Inject SomeService(Configuration conf) { this.conf = conf; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String setting = conf.get(SOME_CONFIG_SETTING); response.getWriter() .println("The value of the setting is: " + setting); } private final Configuration conf; private final static String SOME_CONFIG_SETTING = "my.really.important.setting"; }The above example retrieves the value of the setting and displays it in the response.
N.B. Care must be exercised when working with
Configurationinstances to ensure that a vector to reveal sensitive configuration data is not created. For example if the value ofmy.really.important.settingis sensitive, then printing it's value in the response to a GET request is entirely inappropriate and dangerous. Similarly any code that allows an attacker to control over displaying of configuration data in the delivered response is dangerous. -
CONNECTION
Provides a
Connectionconnected to the appropriate database pool and schema, inferred from mapping the request URL. This dependency will only be available during processing of requests that have been mapped to a JDBC backing store.Usage
@Provides @Dispatches(@PathTemplate("/some/service")) class SomeService extends HttpServlet { @Inject SomeService(Connection conn) { this.conn = conn; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PreparedStatement ps = conn.prepareStatement( "select sys_context('USERENV','CURRENT_USER') from dual"); ResultSet rs = ps.execute(); rs.next(); String user = rs.getString(1); response.getWriter().println("mapped database user is: " + user); rs.close(); ps.close(); } private final Connection conn; }A
Connectioncan only be injected for request URLs where the runtime has been able to the map the URL to a database pool and schema. If the runtime was not able to map the URL to a database/schema, then it will not attempt to dispatch a service that depends onConnection, even if it's URL pattern matches the request URL.For example attempting to access the above service at:
http://localhost:8080/ords/some/service
Will result in a
404 Not Foundstatus because the URL does not contain enough information to identify a database/schema to map to.By contrast, the following URL:
http://localhost:8080/ords/test_schema/some/service
Will execute correctly assuming a schema named
test_schemaexists in the default database pool -
IO
ProvidesIOStreamsservice for manipulating input and output streams. -
JSON
Provides access to theJSONStreamsservice, which can be used to parse character streams into JSON (usingJSONReader) and to generate JSON usingJSONWriter. -
JSON_OBJECTS
Provides access to theJSONObjectsservice, which can be used to build in memory representations of JSON object graphs. -
LOCALE
Provides the most preferredLocalefor a request -
LOCALE_PREFERENCE
Provides aLocalePreferenceinstance, which enumerates the preferredLocales for a request from most to least preferred. -
LOG
Provides access to the the JDK
Loggerservice. All Logging must be done through this service.Usage
@Provides class SomeService { @Inject SomeService(Logger log) { this.log = log; } public void someMethod() { log.info("doing something"); } private final Logger log; } -
PATH_TEMPLATES
Provides methods for working with
PathTemplateMatchinstancesUsage
@Provides class SomeService { @Inject SomeService(PathTemplates pathTemplates) { this.pathTemplates = pathTemplates; } private final PathTemplates pathTemplates; } -
INSTANCE_LOCATOR
Provides an API for discovering at run-time the available implementations of a service. Typically it is preferred to directly inject service implementations via an
@Injectannotated constructor, but there are occasional use cases where it can be useful to locate dependencies dynamically at run-time. For example it may be necessary to discover if a given dependency is available or has multiple providers.Usage of this API should be limited as overuse implies reliance on the Service Locator Pattern rather than the Dependency Injection Pattern.
Usage
@Provides class SomeService { @Inject SomeService(InstanceLocator locator) { boolean widgetAvailable = !locator.select(Widget.class) .isUnsatisfied(); } public void someMethod() { if (widgetAvailable) { // go down the preferred code path } else { // go down a fallback code path } } }
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
constraints
The Annotations that may constrain the scope of the dependency- Returns:
- Annotations that the depedency must be matche against
-
type
The type of the dependency- Returns:
- dependency type
-