Source Code Cross Referenced for EJB.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » container » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: EJB.java 9118 2006-07-05 13:23:44Z sauthieg $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.container;
025:
026:        import java.util.ArrayList;
027:        import java.util.HashSet;
028:        import java.util.Hashtable;
029:        import java.util.Iterator;
030:        import java.util.Set;
031:
032:        import org.objectweb.jonas.dbm.DataBaseServiceImpl;
033:        import org.objectweb.jonas.mail.MailServiceImpl;
034:        import org.objectweb.jonas.management.j2eemanagement.J2EEManagedObject;
035:        import org.objectweb.jonas.resource.ResourceServiceImpl;
036:        import org.objectweb.jonas.service.ServiceManager;
037:        import org.objectweb.jonas_ejb.container.JFactory;
038:        import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
039:        import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp1Desc;
040:        import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp2Desc;
041:        import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
042:        import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
043:
044:        /**
045:         * This class implements the EJB type specified in JSR77
046:         * @author Adriana Danes
047:         *
048:         */
049:        public class EJB extends J2EEManagedObject {
050:            /**
051:             * The Bean to manage
052:             */
053:            protected JFactory ejbToManage = null;
054:            protected BeanDesc desc = null;
055:            protected String fileName = null;
056:
057:            public EJB(String objectName, JFactory ejbToManage) {
058:                super (objectName);
059:                this .ejbToManage = ejbToManage;
060:                this .fileName = ejbToManage.getContainer()
061:                        .getExternalFileName();
062:                this .desc = ejbToManage.getDeploymentDescriptor();
063:            }
064:
065:            /**
066:             * @return String The Name of this JFactory
067:             */
068:            public String getName() {
069:                return desc.getEjbName();
070:            }
071:
072:            /**
073:             * @return Ejb File Name
074:             */
075:            public String getFileName() {
076:                return fileName;
077:            }
078:
079:            /**
080:             * Construct Hashtable containing for each ResourceRef jndi name
081:             * its corresponding the ResourceAdapter MBean OBJECT_NAME.
082:             * @return Hashtable table
083:             */
084:            public Hashtable getAllJdbcResourceAdapterName() {
085:                Hashtable result = new Hashtable();
086:                ArrayList jdbcResourceRefJndiNames = getAllJdbcResourceRefJndiNames();
087:                if (jdbcResourceRefJndiNames.isEmpty()) {
088:                    // return empty result
089:                    return result;
090:                }
091:                ServiceManager sm;
092:                try {
093:                    sm = ServiceManager.getInstance();
094:                } catch (Exception e) {
095:                    // Can't get the ServiceManger, return empty result
096:                    return result;
097:                }
098:                ResourceServiceImpl resServ = null;
099:                try {
100:                    resServ = (ResourceServiceImpl) sm.getRarService();
101:                    // Resource Service activated
102:                    // For each jndi name we look for a JDBC ResourceAdapater having this jndi name
103:                    // This code can be improved by calling one the getJDBCResourceAdapaters()
104:                    // outside the for loop. In this case, in order to get the 'jndiName' attribute's
105:                    // the EJB object (this object) needs a reference ti the mbeanServer.
106:                    for (Iterator it = jdbcResourceRefJndiNames.iterator(); it
107:                            .hasNext();) {
108:                        String jndiName = (String) it.next();
109:                        String raON = resServ.getJDBCResourceAdapater(jndiName);
110:                        if (raON != null) {
111:                            // found JDBC ResourceAdapater with the given jndi name
112:                            result.put(jndiName, raON);
113:                        }
114:                    }
115:                } catch (Exception e) {
116:                    // Resource service not available or exception raised when
117:                    // browsing RA MBeans
118:                }
119:                return result;
120:            }
121:
122:            /**
123:             * Construct Hashtable containing for each ResourceRef jndi name
124:             * its corresponding the datasource name or empty String if no
125:             * corresponding datasource was found.
126:             * @return Hashtable table
127:             */
128:            public Hashtable getAllDataSourceName() {
129:                Hashtable result = new Hashtable();
130:                ArrayList jdbcResourceRefJndiNames = getAllJdbcResourceRefJndiNames();
131:                if (jdbcResourceRefJndiNames.isEmpty()) {
132:                    // return empty result
133:                    return result;
134:                }
135:                ServiceManager sm;
136:                try {
137:                    sm = ServiceManager.getInstance();
138:                } catch (Exception e) {
139:                    // Can't get the ServiceManger, return empty result
140:                    return result;
141:                }
142:                DataBaseServiceImpl bdmServ = null;
143:                try {
144:                    bdmServ = (DataBaseServiceImpl) sm.getDataBaseService();
145:                    // Dbm Service activated
146:                    for (Iterator it = jdbcResourceRefJndiNames.iterator(); it
147:                            .hasNext();) {
148:                        String jndiName = (String) it.next();
149:                        String datasourceName = bdmServ
150:                                .getDatasourceName(jndiName);
151:                        if (datasourceName != null) {
152:                            result.put(jndiName, datasourceName);
153:                        }
154:                    }
155:                } catch (Exception e) {
156:                }
157:                return result;
158:            }
159:
160:            private ArrayList getAllJdbcResourceRefJndiNames() {
161:                ArrayList jndiNames = new ArrayList();
162:                String jndiName = null;
163:                // find the resource refs
164:                ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
165:                for (int i = 0; i < rrDesc.length; i++) {
166:                    if (rrDesc[i].isJdbc()) {
167:                        // get the DD provided JNDI name
168:                        jndiName = rrDesc[i].getJndiName();
169:                        jndiNames.add(jndiName);
170:                    }
171:                }
172:
173:                // if the EJB is an entity with CMP, we have to find jndi name in the jdbc_mapping
174:                if (desc instanceof  EntityJdbcCmp1Desc) {
175:                    // in case of CMP1 :
176:                    EntityJdbcCmp1Desc jdbcCmp1Desc = (EntityJdbcCmp1Desc) desc;
177:                    jndiName = jdbcCmp1Desc.getDatasourceJndiName();
178:                    jndiNames.add(jndiName);
179:                } else if (desc instanceof  EntityJdbcCmp2Desc) {
180:                    // in case of CMP2 :
181:                    EntityJdbcCmp2Desc jdbcCmp2Desc = (EntityJdbcCmp2Desc) desc;
182:                    jndiName = jdbcCmp2Desc.getDatasourceJndiName();
183:                    jndiNames.add(jndiName);
184:                }
185:                return jndiNames;
186:            }
187:
188:            /**
189:             * @return Set The Name set of the Connection Factories
190:             */
191:            public Set getAllJMSConnectionFactoryName() {
192:                Set result = new HashSet();
193:                ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
194:                for (int i = 0; i < rrDesc.length; i++) {
195:                    if ("javax.jms.TopicConnectionFactory".equals(rrDesc[i]
196:                            .getTypeName())
197:                            || "javax.jms.QueueConnectionFactory"
198:                                    .equals(rrDesc[i].getTypeName())
199:                            || "javax.jms.ConnectionFactory".equals(rrDesc[i]
200:                                    .getTypeName())) {
201:                        result.add(rrDesc[i].getJndiName());
202:                    }
203:                }
204:                return result;
205:            }
206:
207:            /**
208:             * @return Hashtable which maps the JNDI names provided by the DD to the Session Mail factyory resources
209:             * known by the Mail Service
210:             */
211:            public Hashtable getAllMailFactorySName() {
212:                Hashtable result = new Hashtable();
213:                MailServiceImpl mailServ = null;
214:                try {
215:                    // Modified for use with the gcj compiler
216:                    ServiceManager sm = ServiceManager.getInstance();
217:                    mailServ = (MailServiceImpl) sm.getMailService();
218:                } catch (Exception e) {
219:                    // Mail Service not available, mailServ null
220:                }
221:                String jndiName = null; // name provided by the DD
222:                String factoryName = null; // resource name
223:
224:                ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
225:                for (int i = 0; i < rrDesc.length; i++) {
226:                    if ("javax.mail.Session".equals(rrDesc[i].getTypeName())) {
227:                        // The Bean uses a javax.mail.Session resource
228:
229:                        // get the DD provided JNDI name
230:                        jndiName = rrDesc[i].getJndiName();
231:
232:                        // try to get the mail service
233:                        if (mailServ != null) {
234:                            // get the resource factory name (maybe null if no resource factory registered under the jndiName)
235:                            factoryName = mailServ.getFactoryName(jndiName);
236:                            if (factoryName != null)
237:                                result.put(jndiName, factoryName);
238:                            else
239:                                result.put(jndiName, "");
240:                        } else {
241:                            // Mail Service not available
242:                            result.put(jndiName, "");
243:                        }
244:                    }
245:                }
246:                return result;
247:            }
248:
249:            /**
250:             * @return Hashtable which maps the JNDI names provided by the DD to the MimePartDataSource Mail factyory resources
251:             * known by the Mail Service
252:             */
253:            public Hashtable getAllMailFactoryMName() {
254:                Hashtable result = new Hashtable();
255:                MailServiceImpl mailServ = null;
256:                try {
257:                    // Modified for use with the gcj compiler
258:                    ServiceManager sm = ServiceManager.getInstance();
259:                    mailServ = (MailServiceImpl) sm.getMailService();
260:                } catch (Exception e) {
261:                    // Mail Service not available, mailServ null
262:                }
263:                String jndiName = null;
264:                String factoryName = null;
265:
266:                ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
267:                for (int i = 0; i < rrDesc.length; i++) {
268:                    if ("javax.mail.internet.MimePartDataSource"
269:                            .equals(rrDesc[i].getTypeName())) {
270:                        // the Bean uses a javax.mail.internet.MimePartDataSource resource
271:
272:                        // get the DD provided JNDI name
273:                        jndiName = rrDesc[i].getJndiName();
274:
275:                        if (mailServ != null) {
276:                            // get the resource factory name (maybe bull if no resource factory registered under the jndiName)
277:                            factoryName = mailServ.getFactoryName(jndiName);
278:                            if (factoryName != null)
279:                                result.put(jndiName, factoryName);
280:                            else
281:                                result.put(jndiName, "");
282:                        } else {
283:                            // Mail Service not available
284:                            result.put(jndiName, "");
285:                        }
286:                    }
287:                }
288:                return result;
289:            }
290:
291:            /**
292:             * @return Set The Name set of the JMS Destinations
293:             */
294:            public Set getAllJMSDestinationName() {
295:                Set result = new HashSet();
296:                ResourceEnvRefDesc[] rrDesc = desc.getResourceEnvRefDesc();
297:                for (int i = 0; i < rrDesc.length; i++) {
298:                    if ((rrDesc[i].getType() == javax.jms.Topic.class)
299:                            || (rrDesc[i].getType() == javax.jms.Queue.class)) {
300:                        result.add(rrDesc[i].getJndiName());
301:                    }
302:                }
303:                return result;
304:            }
305:
306:            /**
307:             * @return Set The URL ressources used by the bean
308:             */
309:            public Set getAllURLs() {
310:                Set result = new HashSet();
311:                ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
312:                for (int i = 0; i < rrDesc.length; i++) {
313:                    if ("java.net.URL".equals(rrDesc[i].getTypeName())) {
314:                        result.add(rrDesc[i].getJndiName());
315:                    }
316:                }
317:                return result;
318:            }
319:
320:            /**
321:             * @return The current instance pool size
322:             */
323:            public int getPoolSize() {
324:                return ejbToManage.getPoolSize();
325:            }
326:
327:            /**
328:             * @return min-pool-size value
329:             */
330:            public int getMinPoolSize() {
331:                return ejbToManage.getMinPoolSize();
332:            }
333:
334:            /**
335:             * @return max-cache-size value
336:             */
337:            public int getMaxCacheSize() {
338:                return ejbToManage.getMaxCacheSize();
339:            }
340:
341:            /**
342:             * @return  nb of instances (current cache size)
343:             */
344:            public int getCacheSize() {
345:                return ejbToManage.getCacheSize();
346:            }
347:
348:            /**
349:             * Reduce number of instances
350:             */
351:            public void reduceCacheSize() {
352:                ejbToManage.reduceCache();
353:            }
354:
355:            /**
356:             * @return String the  JFactory Class
357:             */
358:            public String getEjbClass() {
359:                return desc.getEjbClass().getName();
360:            }
361:
362:            /**
363:             * @return String the displayName of the bean, or bean name if not defined.
364:             */
365:            public String getDisplayName() {
366:                return desc.getDisplayName() != null ? desc.getDisplayName()
367:                        : desc.getEjbName();
368:            }
369:
370:            /**
371:             * @return String the JNDI Name of the bean.
372:             */
373:            public String getJndiName() {
374:                return desc.getJndiName();
375:            }
376:
377:            /**
378:             * @return String the HomeClass of the bean.
379:             */
380:            public String getHomeClass() {
381:                if (desc.getHomeClass() != null) {
382:                    return desc.getHomeClass().getName();
383:                } else {
384:                    return null;
385:                }
386:            }
387:
388:            /**
389:             * @return String the RemoteClass of the bean.
390:             */
391:            public String getRemoteClass() {
392:                if (desc.getRemoteClass() != null) {
393:                    return desc.getRemoteClass().getName();
394:                } else {
395:                    return null;
396:                }
397:            }
398:
399:            /**
400:             * @return String the LocalHomeClass of the bean.
401:             */
402:            public String getLocalHomeClass() {
403:                if (desc.getLocalHomeClass() != null) {
404:                    return desc.getLocalHomeClass().getName();
405:                } else {
406:                    return null;
407:                }
408:            }
409:
410:            /**
411:             * @return String the LocalClass of the bean.
412:             */
413:            public String getLocalClass() {
414:                if (desc.getLocalClass() != null) {
415:                    return desc.getLocalClass().getName();
416:                } else {
417:                    return null;
418:                }
419:            }
420:
421:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.