• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Injection of Simple Environment Entries Using Annotations

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 30
Eclipse IDE Spring Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic