Chapter 9. XML based metadata

The web-beans.xml file provides an alternative to the use of Java annotations for Web Bean definition. For example, this XML declaration defines a simple Web Bean with an injected field and an initializer method:

<myapp:MockAsynchronousCreditCardPaymentProcessor>
    <myapp:Asynchronous/>
    <myapp:PayBy>CREDIT_CARD</myapp:PayBy>
    <SessionScoped/>
    <myfwk:Mock/>
    <myfwk:Service transactional="true"/>
    <Named>asyncCreditCardPaymentProcessor</Named>
    
    <myapp:synchronousProcessor>
        <myapp:PaymentProcessor>
            <myapp:Synchronous/>
            <myapp:PayBy>CREDIT_CARD</myapp:PayBy>
        </myapp:PaymentProcessor>
    <myapp:synchronousProcessor>
    
    <myapp:init>
        <Initializer/>
        <myfwk:SystemConfig/>
    </myapp:init>
    
 </myapp:MockAsynchronousCreditCardPaymentProcessor>

It is the equivalent to the following declaration using annotations:

@Asynchronous 
@PayBy(CREDIT_CARD) 
@SessionScoped 
@Mock
@Service(transactional=true)
@Named("asyncCreditCardPaymentProcessor")
class MockAsynchronousCreditCardPaymentProcessor {

    @Synchronous @PayBy(CREDIT_CARD) PaymentProcessor synchronousProcessor;

    @Initializer void init(SystemConfig config) { ... }

    ...
}

XML-based Web Bean declarations define additional Web Beans—they do not redefine or disable any Web Bean that was declared via annotations.

The file format is typesafe and extensible:

9.1. XML namespace for a Java package

Every Java package has a corresponding XML namespace. The namespace URN consists of the package name, with the prefix urn:java:. For example, the package com.mydomain.myapp has the XML namespace urn:java:com.mydomain.myapp.

<WebBeans xmlns="urn:java:javax.webbeans"
          xmlns:myapp="urn:java:com.mydomain.myapp">
    ...
</WebBeans>

Each namespace may, optionally, have a schema.

<WebBeans xmlns="urn:java:javax.webbeans"
          xmlns:myapp="urn:java:com.mydomain.myapp"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="urn:java:javax.webbeans http://java.sun.com/jee/web-beans-1.0.xsd
                               urn:java:com.mydomain.myapp http://mydomain.com/xsd/myapp-1.2.xsd">
    ...
</WebBeans>

An XML element belonging to a namespace represents a Java type in the corresponding Java package, or a method or field of a type in that package. There are exactly ten exceptions to this rule: the root <WebBeans> element together with the <Queue>, <Topic>, <destination>, <connectionFactory>, <value>, <Deploy>, <Interceptors>, <Decorators> and <Array> elements in the namespace urn:java:javax.webbeans do not correspond to Java types or members of Java types.

A class, interface or annotation type is represented by an element with the same name as the type, in the namespace corresponding to the Java package. For example, the element <List> in the namespace urn:java:java.util represents java.util.List.

Type parameters may be specified by child elements of the element that represents the type. For example:

<util:List>
    <myapp:Product/>
</util:List>

Members of a type may be specified by child elements of the element that represents the type, in the same namespace as the element that represents the type. For example:

<myapp:ShoppingCart>
    <myapp:paymentProcessor>
        ...
    </myapp:paymentProcessor>
</myapp:ShoppingCart>

Primitive types may be represented by the XML element that represents the corresponding wrapper type in java.lang, since primitive and wrapper types are considered identical for the purposes of typesafe resolution, and assignable for the purposes of injection. For example, the element <Integer> in the namespace urn:java:java.lang represent both int and java.lang.Integer.

Java array types may be represented by an <Array> element in the namespace urn:java:javax.webbeans, with a child element representing the element type. For example:

<Array>
    <myapp:Product/>
</Array>

The namespace urn:java:javax.webbeans is called the Web Beans namespace.

If a web-beans.xml file contains any XML element without a declared namespace, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.2. Web Bean declarations

An XML element that appears as a direct child of the root <WebBeans> element is interpreted as a Web Bean declaration if it is not a <Deploy>, <Interceptors> or <Decorators> element in the Web Beans namespace.

If the XML element is a <Queue> or <Topic> element in the Web Beans namespace, it declares a JMS endpoint, as defined in Section 3.5.2, “Declaring a JMS endpoint using XML”.

Otherwise, the name of the XML element is interpreted as a Java type name in the package corresponding to the child element namespace. The Web Beans manager inspects the Java type and other metadata to determine what kind of Web Bean is being declared. If no such Java type exists in the classpath, a NonexistentTypeException is thrown by the Web Bean manager at initialization time.

For example, the following XML file declares a simple Web Bean with the implementation class com.mydomain.myapp.PaymentProcessor:

<WebBeans xmlns="urn:java:javax.webbeans"
           xmlns:myapp="urn:java:com.mydomain.myapp"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="urn:java:javax.webbeans http://java.sun.com/jee/web-beans-1.0.xsd
                               urn:java:com.mydomain.myapp http://mydomain.com/xsd/myapp-1.2.xsd">
    
    <myapp:PaymentProcessor>
        ...
    </myapp:PaymentProcessor>
    
</WebBeans>

In addition, inline Web Bean declarations may occur at injection points, as defined in Section 9.6, “Inline Web Bean declarations”. Inline Web Bean declarations always declare simple Web Beans.

In a Java EE 5 environment, the Web Bean manager is not required to support XML-based declaration of enterprise Web Beans.

9.2.1. Child elements of a Web Bean declaration

The Web Beans manager inspects the direct child elements of the Web Bean declaration. For each child element:

  • If the name of the child element is the name of a Java annotation type in the package corresponding to the child element namespace, the Web Bean manager interprets the child element as declaring type-level metadata.

  • If the name of the child element is the name of a Java class or interface in the package corresponding to the child element namespace, the Web Bean manager interprets the child element as declaring a parameter of the Web Bean constructor.

  • Otherwise, if the child element namespace is the same as the namespace of the parent, the Web Bean manager interprets the element as declaring a method or field of the Web Bean.

  • Otherwise, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.2.2. Type-level metadata for a Web Bean

Type-level metadata is specified via direct child elements of the Web Bean declaration that represent Java annotation types.

The name of the child element is interpreted as the name of a Java annotation type in the package corresponding to the child element namespace.

For each child element, the Web Bean manager inspects the annotation type:

9.2.3. Web Bean constructor declarations

The Web Bean constructor for a simple Web Bean is declared by the list of direct child elements of the Web Bean declaration that represent Java class or interface types. The Web Bean manager interprets these elements as declaring parameters of the constructor.

<myapp:Order>
    <ConversationScoped/>
    <myapp:PaymentProcessor>
        <myapp:Asynchronous/>
    </myapp:PaymentProcessor>
    <myapp:User/>
</myapp:Order>

Each constructor parameter declaration is interpreted as an injection point declaration, as specified in Section 9.5, “Injection point declarations”.

If the simple Web Bean implementation class has exactly one constructor such that:

  • the constructor has the same number of parameters as the Web Bean declaration has constructor parameter declarations, and

  • the Java type represented by each constructor parameter declaration is assignable to the Java type of the corresponding constructor parameter

then the element is interpreted to represent that constructor, and that constructor is the Web Bean constructor.

If more than one constructor exists which satisfies these conditions, a DefinitionException is thrown by the Web Bean manager at initialization time.

If no constructor of the simple Web Bean implementation class satisfies these conditions, a NonexistentConstructorException is thrown by the Web Bean manager at initialization time.

For any constructor parameter, the API type declared in XML may be a subtype of the Java parameter type. In this case, the Web Bean manager will use the API type declared in XML when resolving the dependency.

9.2.4. Fields of a Web Bean

A field of a Web Bean is declared by a direct child element of the Web Bean declaration. The name of the field is the same as the name of the element.

If a direct child element of a Web Bean declaration:

  • does not correspond to any Java type,

  • exists in the same namespace as its parent,

  • has no direct child <Initializer>, <Destructor>, <Produces>, <Disposes>, <Observes> or <Decorates> element in the Web Beans namespace, and

  • has no direct child element whose name is the name of a Web Beans interceptor binding type in the package corresponding to the child element namespace

then it is interpreted as a field declaration.

If the Web Bean implementation class has a field with the same name as the child element, then the child element is interpreted to represent that field.

If the Web Bean implementation class does not have have a field with the specified name, a NonexistentFieldException is thrown by the Web Bean manager at initialization time.

If more than one child element represents the same field, a DefinitionException is thrown by the Web Bean manager at initialization time.

A field declaration may have an arbitrary number of direct child <value> elements in the Web Beans namespace.

Alternatively, a field declaration may have a direct child element that is not a <value> element. If so, the child element is interpreted as an injection point declaration, as specified in Section 9.5, “Injection point declarations”. If the declared type is not assignable to the Java type of the field, a DefinitionException is thrown by the Web Bean manager at initialization time.

If a field declaration has more than one direct child element, and at least one of these elements is not <value> element in the Web Beans namespace, a DefinitionException is thrown by the Web Bean manager at initialization time.

The API type declared in XML may be a subtype of the Java field type. In this case, the Web Bean manager will use the API type declared in XML when resolving the dependency.

An element that represents a field may declare an injected field or a field with an initial value.

9.2.5. Field initial value declarations

The initial value of a field of a simple Web Bean or enterprise Web Bean with any one of the following types may be specified in XML:

  • any primitive type

  • any enumerated type

  • java.lang.String

  • java.util.Date

  • java.util.Calendar

  • java.lang.Class

  • java.util.List<java.lang.String>

  • java.util.List<X> where X is an enumerated type.

The initial value of the field is specified in the body of an XML element representing the field.

<myapp:Config>
    <myapp:version>1.2.5</myapp:version>
    <myapp:timeout>1000</myapp:timeout>
    <myapp:administrators>
        <value>juan</value>
        <value>antonio</value>
        <value>sonia</value>
        <value>sara</value>
    </myapp:administrators>
</myapp:Config>
  • The initial value of a field of primitive type is specified using the Java literal syntax for that type.

  • The initial value of a field of type java.lang.String is specified using the string value.

  • The initial value of a field of enumerated type is specified using the unqualified name of the enumeration value.

  • The initial value of a field of type java.util.Date or java.util.Calendar is specified using a format that can be parsed by java.text.DateFormat.getDateTimeInstance().parse().

  • The initial value of a field of type java.lang.Class is specified using the fully qualified Java class name.

If a field with an initial value specified in XML is not of one of the listed types, or if the initial value is not specified in the correct format for the type of the field, a DefinitionException is thrown by the Web Bean manager at initialization time.

The initial value of a field of type java.util.List is specified by a list of <value> elements. The body of the value element is specified using the string value or unqualified name of the enumeration value.

If an element representing a field specifies both an initial value and a type declaration, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.2.6. Methods of a Web Bean

A method of a Web Bean is declared by a direct child element of the Web Bean declaration. The name of the declared method is the same as the name of the child element.

If a direct child element of a Web Bean declaration:

  • does not correspond to any Java type,

  • exists in the same namespace as its parent, and either

  • has a direct child <Initializer>, <Destructor>, <Produces>, <Disposes> or <Observes> element in the Web Beans namespace, or

  • has a direct child element whose name is the name of a Web Beans interceptor binding type in the package corresponding to the child element namespace

then it is interpreted as a method declaration.

A method declaration may have any number of direct child elements.

The Web Beans manager inspects the direct child elements of the method declaration. For each child element, the name of the element is interpreted as a Java type name in the package corresponding to the element's namespace. If no such Java type exists in the classpath, a NonexistentTypeException is thrown by the Web Bean manager at initialization time.

  • If the type is javax.webbeans.Disposes, the Web Bean manager searches for a direct child element of the child element and interprets that element as declaring a disposed parameter of the disposal method.

  • If the type is javax.webbeans.Observes, the Web Bean manager searches for a direct child element of the child element that is not an <IfExists>, <AfterTransactionCompletion>, <AfterTransactionSuccess>, <AfterTransactionFailure> or <BeforeTransactionCompletion> element in the Web Beans namespace, and interprets that element as declaring an event parameter of the observer method.

  • If the type is some other Java annotation type, the Web Bean manager interprets the child element as declaring method-level metadata.

  • If the type is a Java class or interface, the Web Bean manager interprets the child element as declaring a parameter of the method.

  • Otherwise, a DefinitionException is thrown by the Web Bean manager at initialization time.

If a method declaration has more than one direct child element which is an <Initializer>, <Destructor>, <Produces>, <Disposes> or <Observes> element in the Web Beans namespace, a DefinitionException is thrown by the Web Bean manager at initialization time.

If a <Disposes> element does not contain exactly one direct child element, a DefinitionException is thrown by the Web Bean manager at initialization time.

If an <Observes> element does not contain exactly one direct child element that is not an <IfExists>, <AfterTransactionCompletion>, <AfterTransactionSuccess>, <AfterTransactionFailure> or <BeforeTransactionCompletion> element in the Web Beans namespace, a DefinitionException is thrown by the Web Bean manager at initialization time.

Each method parameter declaration is interpreted as an injection point declaration, as specified in Section 9.5, “Injection point declarations”.

If the Web Bean implementation class has exactly one method such that:

  • the method name is the same as the name of the element that declares the method,

  • the method has the same number of parameters as the element that declares the method has child elements, and

  • the Java type represented by each method parameter declaration is assignable to the Java type of the corresponding method parameter

then the element is interpreted to represent that method.

If more than one method exists which satisfies these conditions, a DefinitionException is thrown by the Web Bean manager at initialization time.

If no method of the Web Bean implementation class satisfies these conditions, a NonexistentMethodException is thrown by the Web Bean manager at initialization time.

For any method parameter, the API type declared in XML may be a subtype of the Java parameter type. In this case, the Web Bean manager will use the API type declared in XML when resolving the dependency.

If more than one child element of a Web Bean declaration represents the same method of the Web Bean implementation class, a DefinitionException is thrown by the Web Bean manager at initialization time.

An element that represents a method may declare an initializer method, a Web Bean remove method, an observer method, a producer method or a disposal method. Alternatively, or additionally, it may declare method-level interceptor binding types.

9.3. Producer method declarations

A producer method declaration is formed by adding a direct child <Produces> element to an element that represents the method, as defined in Section 3.4.3, “Declaring a producer method using XML”.

<myapp:getPaymentProcessor>
    <Produces>
        <myapp:PaymentProcessor/>
    </Produces>
    ...
</myapp:getPaymentProcessor>

9.3.1. Child elements of a producer method declaration

The Web Bean manager inspects the direct child elements of the producer method declaration.

  • If a child element is the <Produces> element in the Web Beans namespace, it declares the return type, binding types and method-level metadata of the producer method.

  • If the child element name is the name of a Web Beans interceptor binding type in the package corresponding to the child element namespace, it declares a method-level interceptor binding type.

  • Otherwise, the Web Bean manager interprets the child element as declaring a parameter of the producer method.

If there is more than one child <Produces> element in the Web Beans namespace, a DefinitionException is thrown by the Web Bean manager at initialization time.

The Web Bean manager inspects the direct child elements of the <Produces> element. For each child element, the name of the element is interpreted as a Java type name in the package corresponding to the child element namespace. If no such Java type exists in the classpath, a NonexistentTypeException is thrown by the Web Bean manager at initialization time.

  • If the type is a Java class or interface type, the return type of the producer method was declared.

  • If the type is a Java annotation type, it declares method-level metadata of the producer method.

  • Otherwise, a DefinitionException is thrown by the Web Bean manager at initialization time.

If more than one child element represents a Java class or interface type, or if no child element represents a Java class or interface type, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.3.2. Return type and binding types of a producer method

Every XML producer method declaration has a direct child <Produces> element. This element must, in turn, have a direct child element which declares the return type of the producer method and which is interpreted by the Web Bean manager as a type declaration, as defined in Section 9.7, “Specifying API types and binding types”.

This type declaration specifies the return type and binding types of the producer method Web Bean. The return type is used to calculate the set of API types. The return type declared in XML must be a supertype or subtype of the Java method type. If the declared return type is not a supertype or subtype of the Java method type, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.3.3. Method-level metadata for a producer method

Method-level metadata for a producer method declaration is specified via direct child elements of the <Produces> element that represent Java annotation types.

The name of each child element is interpreted as the name of a Java annotation type in the package corresponding to the child element namespace. If the declared type is not a Java annotation type, a DefinitionException is thrown by the Web Bean manager at initialization time.

The Web Bean manager inspects the annotation type:

9.4. Interceptor and decorator declarations

A simple Web Bean declaration is interpreted as an interceptor or decorator declaration if it contains a direct child <Interceptor> or <Decorator> element in the Web Beans namespace.

For example, the following XML file declares an interceptor of class RequiresTransactionInterceptor, an interceptor of class RequiresNewTransactionInterceptor and a decorator of class DataAccessAuthorizationDecorator, all in the Java package com.mydomain.myfwk:

<WebBeans xmlns="urn:java:javax.webbeans"
           xmlns:myapp="urn:java:com.mydomain.myapp"
           xmlns:myfwk="urn:java:com.mydomain.myfwk"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="urn:java:javax.webbeans http://java.sun.com/jee/web-beans-1.0.xsd
                               urn:java:com.mydomain.myfwk http://mydomain.com/xsd/myfwk-1.0.xsd
                               urn:java:com.mydomain.myapp http://mydomain.com/xsd/myapp-1.2.xsd">
    
    <myfwk:RequiresTransactionInterceptor>
        <Interceptor/>
        <myfwk:Transactional/>
    </myfwk:RequiresTransactionInterceptor>
    
    <myfwk:RequiresNewTransactionInterceptor>
        <Interceptor/>
        <myfwk:Transactional requiresNew="true"/>
    </myfwk:RequiresNewTransactionInterceptor>
    
    <myfwk:DataAccessAuthorizationDecorator>
        <Decorator/>
        <myfwk:dataAccess>
            <Decorates>
                <myfwk:DataAccess/>
            </Decorates>
        </myfwk:dataAccess>
    <myfwk:DataAccessAuthorizationDecorator>
    
</WebBeans>

If a Web Bean declaration that is not a simple Web Bean declaration contains a child <Interceptor> or <Decorator> element, or if an inline Web Bean declaration contains a child <Interceptor> or <Decorator> element, a DefinitionException is thrown by the Web Bean manager at initialization time.

If a simple Web Bean declaration contains more than one direct child <Interceptor> or <Decorator> element in the Web Beans namespace, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.4.1. Decorator delegate attribute

Decorator declarations must declare the delegate attribute. A delegate declaration is a direct child element of the decorator declaration. The name of the delegate attribute is the same as the name of the element.

If a direct child element of a decorator declaration:

  • exists in the same namespace as its parent, and

  • has direct child <Decorates> element in the Web Beans namespace

then it is interpreted as a delegate declaration.

If a decorator declaration does not contain exactly one delegate declaration, a DefinitionException is thrown by the Web Bean manager at initialization time.

If the Web Bean implementation class has a field with the same name as the child element, then the child element is interpreted to represent that field.

If the Web Bean implementation class does not have have a field with the specified name, a NonexistentFieldException is thrown by the Web Bean manager at initialization time.

If a delegate declaration has more than one direct child element, a DefinitionException is thrown by the Web Bean manager at initialization time. This child element is a <Decorates> element in the Web Beans namespace. If the <Decorates> element does not, in turn, have exactly one direct child element, a DefinitionException is thrown by the Web Bean manager at initialization time.

The direct child element of the <Decorates> element is interpreted as a type declaration as specified by Section 9.7, “Specifying API types and binding types”. If the declared API type is not assignable to the type of the Java field, a DefinitionException is thrown by the Web Bean manager at initialization time.

The API type declared in XML may be a subtype of the Java field type. In this case, the Web Bean manager will use the API type declared in XML when resolving the dependency.

If simple Web Bean declaration that is not a decorator declaration contains a direct child element that in turn contains a direct child <Decorates> element, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.5. Injection point declarations

An injection point declaration is either:

When the Web Bean manager encounters an injection point declaration, it interprets the name of the element as the name of a Java class or interface in the package corresponding to the element namespace. If no such Java type exists in the classpath, a NonexistentTypeException is thrown by the Web Bean manager at initialization time.

  • If the Java type is a parameterized type, the injection point declaration is a type declaration, and the declared type of the injection point is the API type of the type declaration, including actual type parameters.

  • Otherwise, the Web Bean manager inspects the direct child elements. If the name of any direct child element is the name of a Web Beans binding type in the package corresponding to the child element namespace, the injection point declaration is a type declaration, and the declared type of the injection point is the API type of the type declaration.

  • Otherwise, if any direct child elements exist, the injection point declaration is an inline Web Bean declaration, and the declared type of the injection point is the implementation class of the Web Bean.

  • Otherwise, the injection point declaration is a type declaration, and the declared type of the injection point is the API type of the type declaration.

9.6. Inline Web Bean declarations

An inline Web Bean declaration is a simple Web Bean declaration, as defined in Section 9.2, “Web Bean declarations” that occurs as an injection point declaration, instead of as a direct child of the <WebBeans> element.

<myapp:Admin>
    <ApplicationScoped/>
      
    <myapp:username>gavin</myapp:username>
    
    <myapp:name>
        <myapp:Name>
            <myapp:firstName>Gavin</myapp:firstName>
            <myapp:lastName>King</myapp:lastName>
        </myapp:Name>
    </myapp:name>
    
</myapp:Admin>

The name of the element is interpreted as the name of a Java class in the package corresponding to the element namespace. This Java class is the implementation class of the simple Web Bean.

Inline Web Bean declarations may not explicitly specify a binding type. If an inline Web Bean declaration explicitly specifies a binding type, a DefinitionException is thrown by the Web Bean manager at initialization time.

For every inline injection point, the Web Bean manager generates a unique value for an implementation-specific binding type. (For example, a particular Web Bean manager implementation might generate the value com.vendor.webbeans.Inline(id=12345) at some injection point.) This generated value is the binding type of the injection point, and the only binding type of the simple Web Bean. The API type of the injection point is the declared implementation class of the simple Web Bean.

Thus, an inline Web Bean declaration results in a simple Web Bean that is bound only to the injection point at which it was declared.

9.7. Specifying API types and binding types

Every injection point and delegate attribute defined in XML must explicitly specify an API type and combination of binding types. XML-based producer method declarations must also explicitly specify the return type (which is used to calculate the set of API types) and binding types. A type declaration is:

  • an element that represents a Java class or interface, or <Array>,

  • if the type is a parameterized type, a set of child elements that represent Java classes and/or interfaces, and are interpreted as the actual type parameters, or, if the type is an array type, a single child element that represents the array element type,

  • optionally, a set of child elements that represent Java annotation types, and are interpreted as binding types.

For example, the following XML fragment declares the type List<Product> with binding type @All.

<util:List>
    <myapp:All/>
    <myapp:Product/>
</util:List>

This XML fragment declares the type Product[] with binding type @Available.

<Array>
    <myapp:Available/>
    <myapp:Product/>
</Array>

When the Web Bean manager encounters a type declaration it interprets the element as a Java type:

  • If the element is an <Array> element in the Web Beans namespace, an array type was declared.

  • Otherwise, the name of the element is interpreted as the name of a Java class or interface in the package corresponding to the element namespace. If no such Java type exists in the classpath, a NonexistentTypeException is thrown by the Web Bean manager at initialization time. If the Java type is not a class or interface type, a DefinitionException is thrown by the Web Bean manager at initialization time.

Next, the Web Bean manager inspects every direct child element of the type declaration. The name of each child element is interpreted as the name of a Java type in the package corresponding to the child element namespace. If no such Java type exists in the classpath, a NonexistentTypeException is thrown by the Web Bean manager at initialization time.

  • If the type is a Java annotation type, a binding type was declared.

  • If the type is a Java class or interface type, an actual type parameter or array element type was declared.

  • Otherwise, a DefinitionException is thrown by the Web Bean manager at initialization time.

If multiple array element types are declared, a DefinitionException is thrown by the Web Bean manager at initialization time.

If the number of declared actual type parameters is not the same as the number of parameters of the Java type, a DefinitionException is thrown by the Web Bean manager at initialization time.

If a type parameter of the Java type is bounded, and the corresponding declared actual type parameter does not satisfy the upper or lower bound, a DefinitionException is thrown by the Web Bean manager at initialization time.

If a binding type declaration declares a Java annotation type that is not a Web Beans binding type, a DefinitionException is thrown by the Web Bean manager at initialization time.

If no binding type is declared, the default binding type @Current is assumed.

If the same binding type occurs more than once, a DuplicateBindingTypeException is thrown by the Web Bean manager at initialization time.

For fields, type declarations are specified as direct child elements of the field declaration:

<myapp:Order>
      
    <myapp:paymentProcessor>
    
        <myapp:PaymentProcessor>
            <myapp:PayBy>CHEQUE</myapp:PayBy>
        </myapp:PaymentProcessor>
        
    </myapp:paymentProcessor>
    
</myapp:Order>
<myapp:ShoppingCart>
      
    <myapp:catalog>
    
        <util:List>
            <myapp:All/>
            <myapp:Product/>
        </util:List>
        
    </myapp:catalog>

</myapp:ShoppingCart>

For methods, the method parameter declarations are type declarations:

<myapp:Order>
    
    <myapp:setPaymentProcessor>
        <Initializer/>
        
        <myapp:PaymentProcessor>
            <myapp:PayBy>CHEQUE</myapp:PayBy>
        </myapp:PaymentProcessor>
        
        <myfwk:Logger/>
        
    </myapp:setPaymentProcessor>

</myapp:Order>

For producer methods, the return type must also be specified:

<app:Shop>

    <app:getAvailableProducts>
    
        <Produces>
            <ApplicationScoped/>
            <Array>
                <app:Available/>
                <app:Product/>
            </Array>
        </Produces>
        
        <util:List>
            <app:All/>
            <app:Product/>
        </util:List>        
        
    </app:getAvailableProducts>
    
</app:Shop>

For constructors, the constructor parameter declarations are type declarations:

<myapp:Order>
    <ConversationScoped/>
    
    <myapp:PaymentProcessor>
        <myapp:PayBy>CHEQUE</myapp:PayBy>
    </myapp:PaymentProcessor>
    
    <myfwk:Logger/>
    
</myapp:Order>

9.8. Annotation members

Any binding type or interceptor binding type declaration must define the value of any annotation member without a default value, and may additionally define the value of any annotation member with a default value. Annotation member values are defined by attributes of the XML element which represents the Java annotation.

All attributes of any XML element which corresponds to a Java annotation are interpreted as members of the annotation. The name of the attribute is interpreted as the name of the corresponding annotation member. The value of the attribute is interpreted as the value of the annotation member. If there is no annotation member with the same name as the attribute, a NonexistentMemberException is thrown by the Web Bean manager at initialization time.

<myfwk:DataAccess transactional="true"/>

Alternatively, the value of an annotation member named value may be specified in the body of the XML element which corresponds to the Java annotation. If the XML element has a non-empty body and also specifies an attribute named value, a DefinitionException is thrown by the Web Bean manager at initialization time. If the XML element has a non-empty body, and there is no annotation member named value, a NonexistentMemberException is thrown by the Web Bean manager at initialization time.

<myapp:PayBy>CHEQUE</myapp:PayBy>
  • The value of a member of primitive type is specified using the Java literal syntax for that type.

  • The value of a member of type java.lang.String is specified using the string value.

  • The value of a member of enumerated type is specified using the unqualified name of the enumeration value.

  • The value of a member of type java.lang.Class is specified using the fully qualified Java class name.

If the member value is not specified in the correct format for the type of the member, a DefinitionException is thrown by the Web Bean manager at initialization time.

If an XML element that refers to a Java annotation with a member with no default value does not declare a value for that member, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.9. Deployment declarations

The <Deploy>, <Interceptors> and <Decorators> elements in the Web Beans namespace determine which Web Beans, interceptors and decorators are enabled in a particular deployment.

9.9.1. The <Deploy> declaration

Each direct child element of a <Deploy> element is interpreted as the declaring an enabled deployment type, as specified in Section 2.5.6, “Enabled deployment types”.

For each child element, the name of the child element is interpreted as the name of a Java annotation type in the package corresponding to the child element namespace. If no such Java type exists in the classpath, a DefinitionException is thrown by the Web Bean manager at initialization time. If the type is not a Web Beans deployment type, a DefinitionException is thrown by the Web Bean manager at initialization time.

If the same deployment type is declared more than once, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.9.2. The <Interceptors> declaration

Each direct child element of an <Interceptors> element is interpreted as the declaring an enabled interceptor, as specified in Section 6.2.7, “Interceptor enablement and ordering”.

For each child element, the name of the child element is interpreted as the name of a Java class in the package corresponding to the child element namespace. If no such Java class exists in the classpath, a DefinitionException is thrown by the Web Bean manager at initialization time. If the class is not the implementation class of at least one interceptor, a DefinitionException is thrown by the Web Bean manager at initialization time.

If the same interceptor is declared more than once, a DefinitionException is thrown by the Web Bean manager at initialization time.

9.9.3. The <Decorators> declaration

Each direct child element of a <Decorators> element is interpreted as the declaring an enabled decorator, as specified in Section 6.3.5, “Decorator enablement and ordering”.

For each child element, the name of the child element is interpreted as the name of a Java class in the package corresponding to the child element namespace. If no such Java class exists in the classpath, a DefinitionException is thrown by the Web Bean manager at initialization time. If the class is not the implementation class of at least one decorator, a DefinitionException is thrown by the Web Bean manager at initialization time.

If the same decorator is declared more than once, a DefinitionException is thrown by the Web Bean manager at initialization time.