KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > service > ServiceOne


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.service;
23
24 import javax.ejb.EJB JavaDoc;
25 import javax.ejb.Remote JavaDoc;
26 import javax.ejb.Local JavaDoc;
27
28 import javax.persistence.EntityManager;
29 import javax.persistence.PersistenceContext;
30
31 import org.jboss.annotation.ejb.Management;
32 import org.jboss.annotation.ejb.Service;
33 import org.jboss.annotation.security.SecurityDomain;
34
35 /**
36  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
37  * @version $Revision: 45473 $
38  */

39 @Service
40 @Remote JavaDoc(ServiceOneRemote.class)
41 @Local JavaDoc(ServiceOneLocal.class)
42 @Management(ServiceOneManagement.class)
43 @SecurityDomain("other")
44 public class ServiceOne implements ServiceOneLocal, ServiceOneRemote, ServiceOneManagement
45 {
46    @PersistenceContext(unitName = "test")
47    private EntityManager manager;
48    
49    static int instances = 0;
50    int localMethodCalls;
51    int remoteMethodCalls;
52    int jmxAttribute;
53    int someJmxAttribute;
54    int otherJmxAttribute;
55    int readWriteOnlyAttribute;
56    
57    @EJB JavaDoc StatelessRemote stateless;
58    
59    public void testEjbInjection()
60    {
61       stateless.test();
62    }
63
64    public ServiceOne()
65    {
66       instances++;
67    }
68
69    public int getInstances()
70    {
71       return instances;
72    }
73
74    public int getRemoteMethodCalls()
75    {
76       return remoteMethodCalls;
77    }
78
79    public void setRemoteMethodCalls(int i)
80    {
81       remoteMethodCalls = i;
82    }
83
84    public int getLocalMethodCalls()
85    {
86       return localMethodCalls;
87    }
88
89    public void setLocalMethodCalls(int i)
90    {
91       localMethodCalls = i;
92    }
93
94    public synchronized void localMethod(String JavaDoc s)
95    {
96       localMethodCalls++;
97    }
98
99    public synchronized void remoteMethod(String JavaDoc s)
100    {
101       remoteMethodCalls++;
102    }
103
104    public String JavaDoc jmxOperation(String JavaDoc s)
105    {
106       return "x" + s + "x";
107    }
108
109    public String JavaDoc[] jmxOperation(String JavaDoc[] s)
110    {
111       for (int i = 0 ; i < s.length ; i++)
112       {
113          s[i] = jmxOperation(s[i]);
114       }
115       return s;
116    }
117
118    public int getAttribute()
119    {
120       return jmxAttribute;
121    }
122
123    public void setAttribute(int i)
124    {
125       jmxAttribute = i;
126    }
127
128    public int getSomeAttr()
129    {
130       return someJmxAttribute;
131    }
132
133    public void setSomeAttr(int i)
134    {
135       someJmxAttribute = i;
136    }
137
138    public int getOtherAttr()
139    {
140       return otherJmxAttribute;
141    }
142
143    public void setOtherAttr(int i)
144    {
145       otherJmxAttribute = i;
146    }
147
148    public void setWriteOnly(int i)
149    {
150       readWriteOnlyAttribute = i;
151    }
152
153    public int getReadOnly()
154    {
155       return readWriteOnlyAttribute;
156    }
157
158
159    public void create() throws Exception JavaDoc
160    {
161       System.out.println("ServiceOne - CREATE");
162       Tester.creates.add("1");
163    }
164
165    public void start() throws Exception JavaDoc
166    {
167       System.out.println("ServiceOne - START");
168       Tester.starts.add("1");
169       
170       //test EntityManager injection
171
manager.toString();
172    }
173
174    public void stop()
175    {
176       System.out.println("ServiceOne - STOP");
177    }
178
179    public void destroy()
180    {
181       System.out.println("ServiceOne - DESTROY");
182    }
183
184 }
185
Popular Tags