# @ejbgen:env-entry Annotation

This tag specifies environment entries for an EJB.

Note. An environment entry is a read-only EJB-specific variable that can be changed at deployment time. It allows you to modify the business logic of the EJB without having to change and recompile your code. For example, you can use an environment entry to set a maximum credit amount for a credit card, specify a company name, and so forth. An example is given below. For more general information on environment entries, see your favorite J2EE documentation.

## Scope

A class tag on an EJB.

## Syntax

@ejbgen:env-entry

[id="TagID"]

name="EnvEntryName"

type="TypeOption"

value="Value"

## Attributes

id

Optional. Specifies the ID of the tag. For more information, see EJBGen Tag Inheritance.

name

Required. Specifies the name of the environment entry.

type

Required. Specifies the type of the environment entry. The type can be String or any of the primitive wrappers, including Character, Short, Integer, Long, Double, Float, Byte, and Boolean.

value

Required. Specifies the value for this environment entry.

## Example

In this example an Order bean has an addProduct method to add a certain number of items to a shopping cart. This method uses a environment entry to limit the quantity that can be ordered:

    /**
     *
     * @ejbgen:env-entry value="5" type="java.lang.Integer" name="maxQuantity"
     *
     * ...
     */
    public class OrderBean ...
    {
        ...
        public void addProduct(ProductInfo theProduct, int requestedQuantity)
        {
          int maximumQuantity;

          try {
            InitialContext ic = new InitialContext();
            Integer maxQuantity = (Integer) ic.lookup("java:comp/env/maxQuantity");
            maximumQuantity = maxQuantity.intValue();
          }
          catch (NamingException ne) {
             ...
          }

          if(requestedQuantity > maximumQuantity) {
            // don't allow purchase
            ...
          }
          else
          {
            // allow purchase
            ...
          }
        ...
    }

Related Topics

EJBGen Tag Inheritance