File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Injection of Simple Environment Entries Using Annotations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Injection of Simple Environment Entries Using Annotations" Watch "Injection of Simple Environment Entries Using Annotations" New topic
Author

Injection of Simple Environment Entries Using Annotations

Padma Priya
Ranch Hand

Joined: Feb 01, 2007
Posts: 112
Hi all,

I have a small doubt regarding "Injection of Simple Environment Entries Using Annotations".

If i have the code as shown below

@Stateless public class EmployeeServiceBean
implements EmployeeService
{
...
// The maximum number of tax exemptions, configured by Deployer
@Resource int maxExemptions;

// The minimum number of tax exemptions, configured by Deployer
@Resource int minExemptions;

public void setTaxInfo(int numberOfExemptions,...) throws InvalidNumberOfExemptionsException {
...
// Use the environment entries to customize business logic.
if (numberOfExemptions > maxExemptions ||numberOfExemptions < minExemptions)
throw new InvalidNumberOfExemptionsException();
}
}


How can i specify the values of the simple Environment entries maxExemptions and minExemptions?

Can anybody show me the dd snippet of it. Also can't we specify the value directly in the bean code as follows

@Resource int maxExemptions = 4;

The spec says

To support this case, the container must only inject a value for the environment entry if the application
assembler or deployer has specified a value to override the default value.


Can anybody explain the above statement. Does this mean that we should always specify <env-entry-value> in the dd even after we have given a default value in @Resource int maxExemptions = 4;. But that doesn't make sense.


Thank you all in advance.

With Regards
Deepthi

Prasad Kumbhare
Greenhorn

Joined: Oct 18, 2007
Posts: 26
Here is one sample DD entry of env vairable.


Hope this helps.
About your second question I am really not sure. So I will try this and let you know.

Thanks,
Prasad


Thanks,
Prasad Kumbhare
SCJP 5.0, SCWCD 5.0, SCBCD 5.0
Alexey Saenko
Ranch Hand

Joined: Aug 18, 2008
Posts: 30

Deepthi Tirunahari wrote:The spec says
To support this case, the container must only inject a value for the environment entry if the application
assembler or deployer has specified a value to override the default value.

Can anybody explain the above statement. Does this mean that we should always specify <env-entry-value> in the dd even after we have given a default value in @Resource int maxExemptions = 4;. But that doesn't make sense.


I thinks this means the following: if a value for the env-entry has been specified, container must and will inject it. If there is no value in env-entries, container must not and will not inject this value and default value will be used. Also, env-entries always overrides default values (and those which were set in code, like int x = 4), because firstly jvm must create an object (or primitive) and then read the value from DD.

So, we can write down something like this in the bean code:


SCJP 6, SCBCD 5, OCEWSD 6
My blog: http://darkleden.wordpress.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Injection of Simple Environment Entries Using Annotations
 
Similar Threads
env-entry> tag
how to create Environment Entries in jboss
Resource injection for env entry in the field
Security Question
JNDI relativity