SeamFramework.orgCommunity Documentation
Solder provides a number enhancements to the CDI programming model which are under trial and may be included in later releases of Contexts and Dependency Injection.
Annotating a class @Veto
will cause the type to be ignored, such that any definitions on the
type will not be processed, including:
the managed bean, decorator, interceptor or session bean defined by the type
any producer methods or producer fields defined on the type
any observer methods defined on the type
For example:
@Veto
class Utilities {
...
}
Besides, a package can be annotated with @Veto
, causing all beans in the package to be prevented
from registration.
The ProcessAnnotatedType
container lifecycle event will be called for vetoed types.
Annotating a class with @Requires
will cause the type to be ignored if the class dependencies
cannot be satisfied. Any definitions on the type will not be processed:
the managed bean, decorator, interceptor or session bean defined by the type
any producer methods or producer fields defined on the type
any observer methods defined on the type
Solder will use the Thread Context ClassLoader, as well as the classloader of the type annotated
@Requires
to attempt to satisfy the class dependency.
For example:
@Requires("javax.persistence.EntityManager")
class EntityManagerProducer {
@Produces
EntityManager getEntityManager() {
...
}
}
Annotating a package with @Requires
causes all beans in the package to be ignored if the class dependencies
cannot be satisfied. If both a class and it's package are annotated with @Requires
, both package-level and
class-level dependencies have to be satisfied for the bean to be installed.
The ProcessAnnotatedType
container lifecycle event will be called for required types.
Annotating an injection point with @Exact
allows you to select an exact implementation of the
injection point type to inject. For example:
interface PaymentService {
...
}
class ChequePaymentService implements PaymentService {
...
}
class CardPaymentService implements PaymentService {
...
}
class PaymentProcessor {
@Inject @Exact(CardPaymentService.class)
PaymentService paymentService;
...
}
It is common to want to qualify a bean as belonging to the current client (for example we want to differentiate
the default system locale from the current client's locale). Solder provides a built in qualifier,
@Client
for this purpose.
Solder allows you to annotate the package @Named
, which causes every bean defined in the
package to be given its default name. Package annotations are defined in the file
package-info.java
. For example, to cause any beans defined in com.acme
to be given
their default name:
@Named
package com.acme
According to the CDI standard, the @Named
annotation assigns a name to a bean equal to the value
specified in the @Named
annotation or, if a value is not provided, the simple name of the bean class.
This behavior aligns with the needs of most application developers. However, framework writers should avoid
trampling on the "root" bean namespace. Instead, frameworks should specify qualified names for built-in components.
The motivation is the same as qualifying Java types. The @FullyQualified
provides this facility without
sacrificing type-safety.
Solder allows you to customize the bean name using the complementary @FullyQualified
annotation. When the @FullyQualified
annotation is added to a @Named
bean type, producer
method or producer field, the standard bean name is prefixed with the name of the Java package in which the bean
resides, the segments separated by a period. The resulting fully-qualified bean name (FQBN) replaces the standard
bean name.
package com.acme;
@FullyQualified @Named
public class NamedBean {
public int getAge()
{
return 5;
}
}
The bean in the previous code listing is assigned the name com.acme.namedBean
. The value of its
property age
would be referenced in an EL expression (perhaps in a JSF view template) as follows:
#{com.acme.namedBean.age}
The @FullyQualified
annotation is permitted on a bean type, producer method or producer field. It can
also be used on a Java package, in which case all @Named
beans in that package get a bean name which is
fully-qualified.
@FullyQualified
package com.acme;
If you want to use a different Java package as the namespace of the bean, rather than the Java package of the bean, you specify any class in that alternative package in the annotation value.
package com.acme;
@FullyQualified(ClassInOtherPackage.class) @Named
public class CustomNamespacedNamedBean {
...
}