01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.superbiz.injection;
17:
18: import java.util.ArrayList;
19: import java.util.List;
20:
21: import javax.annotation.Resource;
22: import javax.ejb.Remote;
23: import javax.ejb.Stateful;
24:
25: /**
26: * This example demostrates the use of the injection of environment entries
27: * using <b>Resource</b> annotation.
28: *
29: * "EJB Core Contracts and Requirements" specification section 16.4.1.1.
30: *
31: * Resource annotation is used to annotate the maxLineItems and default value of
32: * 10 is assigned. Deployer can modify the values of the environment entries at
33: * deploy time in deployment descriptor.
34: *
35: * @version $Rev: 601953 $ $Date: 2007-12-06 17:09:47 -0800 $
36: */
37:
38: @Stateful
39: @Remote
40: public class PurchaseOrderBean implements PurchaseOrder {
41:
42: @Resource
43: int maxLineItems = 10;
44:
45: private List<LineItem> items = new ArrayList<LineItem>();
46:
47: private int itemCount;
48:
49: public void addLineItem(LineItem item) throws TooManyItemsException {
50: if (item == null) {
51: throw new IllegalArgumentException(
52: "Line item must not be null");
53: }
54:
55: if (itemCount <= maxLineItems) {
56: items.add(item);
57: itemCount++;
58: } else {
59: throw new TooManyItemsException(
60: "Number of items exceeded the maximum limit");
61: }
62: }
63:
64: public int getMaxLineItems() {
65: return this.maxLineItems;
66: }
67:
68: }
|