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:
24: /**
25: * This example demostrates the use of the injection of environment entries
26: * using <b>Resource</b> annotation.
27: *
28: * "EJB Core Contracts and Requirements" specification section 16.4.1.1.
29: *
30: * @version $Rev: 601953 $ $Date: 2007-12-06 17:09:47 -0800 $
31: */
32:
33: @Remote
34: public class InvoiceBean implements Invoice {
35:
36: int maxLineItems;
37:
38: private List<LineItem> items = new ArrayList<LineItem>();
39:
40: private int itemCount;
41:
42: /**
43: * Injects the <b>maxLineItems</b> simple environment entry through bean
44: * method.
45: *
46: * The JavaBeans property name (not the method name) is used as the default
47: * JNDI name. By default, the JavaBeans propery name is combined with the
48: * name of the class in which the annotation is used and is used directly as
49: * the name in the bean's naming context. JNDI name for this entry would
50: * be
51: * java:comp/env/org.apache.openejb.examples.resource.InvoiceBean/maxLineItems
52: *
53: * Refer "EJB Core Contracts and Requirements" specification section 16.2.2.
54: *
55: * @param maxLineItems
56: */
57: @Resource
58: public void setMaxLineItems(int maxLineItems) {
59: this .maxLineItems = maxLineItems;
60: }
61:
62: public void addLineItem(LineItem item) throws TooManyItemsException {
63: if (item == null) {
64: throw new IllegalArgumentException(
65: "Line item must not be null");
66: }
67:
68: if (itemCount <= maxLineItems) {
69: items.add(item);
70: itemCount++;
71: } else {
72: throw new TooManyItemsException(
73: "Number of items exceeded the maximum limit");
74: }
75: }
76:
77: public int getMaxLineItems() {
78: return this.maxLineItems;
79: }
80:
81: }
|