CUBA supports the same basic mechanism for component configuration
as
it is known from the EJB standard. Configuration parameters can be
declared
as environment entries in a component's deployment descriptor and
accessed
at runtime with function ComponentContextI.getEnvironment().
Environment entries can be of any primitive Java object type and can be
addressed by a symbolic identifier. An environment entry can be
declared
as follows:
<?xml version="1.0"
encoding="UTF-8"?> <component-jar> <component> <component-name>env</component-name> <external-interface>env.Env</external-interface> <component-class>env.EnvImpl</component-class>
<env-entries> |
Accessing the environment entry at runtime by a lookup operation
looks like this
public class EnvImpl
extends AbstractComponent implements Env { public String getEmail() throws ReferenceException { return getContext().getEnvironment("email").toString(); } } |
Alternatively, environment entries can be initialized by the container, using dependency injection. The component's implementation class has to define a public member or setter function which can be refered to in the descriptor, e.g
... |
public class EnvImpl
extends AbstractComponent implements Env { public String emailAddress; // will be set by container public String getEmail() throws ReferenceException { return emailAddress; } } |
public class EnvImpl
extends AbstractComponent implements Env { @Resource(name="emailAddress") public String emailAddress; } |
Home | Introduction | Javadoc |