jakartaee / messaging

Jakarta Messaging
https://eclipse.org/ee4j/messaging
Other
39 stars 33 forks source link

Add repeating annotation support to @JMSConnectionFactoryDefinition and @JMSDestinationDefinition #151

Closed glassfishrobot closed 2 years ago

glassfishrobot commented 10 years ago

Java SE 7 did not allow class-level annotations such as tt>@JMSConnectionFactoryDefinition</tt and tt>@JMSDestinationDefinition</tt to be repeated.

This meant that if a class needed to define more than one connection factory or destination, then they needed to be wrapped in a tt>@JMSConnectionFactoryDefinitions</tt or tt>@JMSDestinationDefinitions</tt annotation, which made the code quite complicated:

@JMSDestinationDefinitions({   
   @JMSDestinationDefinition(name = "java:global/jms/myQueue1", 
             destinationName = "myQueue1",
             interfaceName = "javax.jms.Queue"),
   @JMSDestinationDefinition(name = "java:global/jms/myQueue2", 
             destinationName = "myQueue2",
             interfaceName = "javax.jms.Queue")    
})

Java SE 8 allows annotation types to be marked as "repeatable". If the tt>@JMSConnectionFactoryDefinition</tt and tt>@JMSDestinationDefinition</tt annotations were marked as repeatable then the above example could be simplified to

@JMSDestinationDefinition(name = "java:global/jms/myQueue1", 
             destinationName = "myQueue1",
             interfaceName = "javax.jms.Queue")
@JMSDestinationDefinition(name = "java:global/jms/myQueue2", 
             destinationName = "myQueue2",
             interfaceName = "javax.jms.Queue")

To allow this, the tt>@JMSDestinationDefinition</tt annotation would be extended as follows:

@Target(value=TYPE)
@Retention(value=RUNTIME)
@repeatable(JMSDestinationDefinitions.class)
public @interface JMSDestinationDefinition

and the tt>@JMSConnectionFactoryDefinition</tt annotation would be extended as follows:

@Target(value=TYPE)
@Retention(value=RUNTIME)
@repeatable(JMSConnectionFactoryDefinitions.class)
public @interface JMSConnectionFactoryDefinition

Note that it is necessary to specify a "containing annotation" which is generated by the compiler and used to store repeating annotations. It should be possible to re-use the existing annotations JMSDestinationDefinitions and JMSConnectionFactoryDefinitions for this purpose.

Affected Versions

[2.0]

glassfishrobot commented 6 years ago
glassfishrobot commented 10 years ago

@glassfishrobot Commented Reported by @nigeldeakin

glassfishrobot commented 10 years ago

@glassfishrobot Commented Issue-Links: blocks JAVAEE_SPEC-36

glassfishrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JMS_SPEC-151

hantsy commented 3 years ago

It is weird this change was not included in Java EE 8.0 in which the main work is aligning with Java 8 SE.

OndroMih commented 2 years ago

This has been fixed by #298. To add test coverage, #299 and #300 were raised, so I will close this issue.