if (bean instanceof MessageDrivenBean) {
/*
* @ActivationConfigProperty
*/
MessageDrivenBean mdb = (MessageDrivenBean) bean;
MessageDriven messageDriven = clazz.getAnnotation(MessageDriven.class);
if (messageDriven != null) {
ActivationConfig activationConfig = mdb.getActivationConfig();
if (activationConfig == null) {
activationConfig = new ActivationConfig();
}
if (!messageDriven.mappedName().isEmpty()) {
if (mdb.getActivationConfig() == null) {
mdb.setActivationConfig(activationConfig);
}
activationConfig.addProperty("destinationType", Queue.class.getName());
activationConfig.addProperty("destination", messageDriven.mappedName());
}
javax.ejb.ActivationConfigProperty[] configProperties = messageDriven.activationConfig();
if (configProperties != null) {
if (mdb.getActivationConfig() == null) {
mdb.setActivationConfig(activationConfig);
}
Properties properties = activationConfig.toProperties();
for (javax.ejb.ActivationConfigProperty property : configProperties) {
if (!properties.containsKey(property.propertyName())) {
activationConfig.addProperty(property.propertyName(), property.propertyValue());
}
}
}
if (mdb.getMessagingType() == null) {
Class<?> interfce = messageDriven.messageListenerInterface();
if (interfce != null && !interfce.equals(Object.class)) {
if (!interfce.isInterface()) {
// TODO: Move this check to o.a.o.c.rules.CheckClasses and do it for all MDBs, annotated or not
throw new OpenEJBException("MessageListenerInterface property of @MessageDriven is not an interface");
}
mdb.setMessagingType(interfce.getName());
}
}
}
/*
* Determine the MessageListener interface
*/
if (mdb.getMessagingType() == null) {
List<Class<?>> interfaces = new ArrayList<Class<?>>();
for (Class<?> intf : clazz.getInterfaces()) {
String name = intf.getName();
if (!name.equals("java.io.Serializable") &&
!name.equals("java.io.Externalizable") &&
!name.startsWith("javax.ejb.") &&
!intf.isSynthetic()) {
interfaces.add(intf);
}
}
if (interfaces.size() != 1) {
String msg = "When annotating a bean class as @MessageDriven without declaring messageListenerInterface, the bean must implement exactly one interface, no more and no less. beanClass=" + clazz.getName() + " interfaces=";
for (Class<?> intf : interfaces) {
msg += intf.getName() + ", ";
}
// TODO: Make this a validation failure, not an exception
throw new IllegalStateException(msg);
}
mdb.setMessagingType(interfaces.get(0).getName());
}
}
buildAnnotatedRefs(bean, annotationFinder, classLoader);