Source Code Cross Referenced for EjbJarInfoBuilder.java in  » J2EE » openejb3 » org » apache » openejb » config » 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 » openejb3 » org.apache.openejb.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *
003:         * Licensed to the Apache Software Foundation (ASF) under one or more
004:         * contributor license agreements.  See the NOTICE file distributed with
005:         * this work for additional information regarding copyright ownership.
006:         * The ASF licenses this file to You under the Apache License, Version 2.0
007:         * (the "License"); you may not use this file except in compliance with
008:         * the License.  You may obtain a copy of the License at
009:         *
010:         *     http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         *  Unless required by applicable law or agreed to in writing, software
013:         *  distributed under the License is distributed on an "AS IS" BASIS,
014:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         *  See the License for the specific language governing permissions and
016:         *  limitations under the License.
017:         */package org.apache.openejb.config;
018:
019:        import org.apache.openejb.OpenEJBException;
020:        import org.apache.openejb.assembler.classic.CallbackInfo;
021:        import org.apache.openejb.assembler.classic.CmrFieldInfo;
022:        import org.apache.openejb.assembler.classic.EjbJarInfo;
023:        import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
024:        import org.apache.openejb.assembler.classic.EntityBeanInfo;
025:        import org.apache.openejb.assembler.classic.InitMethodInfo;
026:        import org.apache.openejb.assembler.classic.InterceptorBindingInfo;
027:        import org.apache.openejb.assembler.classic.InterceptorInfo;
028:        import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo;
029:        import org.apache.openejb.assembler.classic.MethodInfo;
030:        import org.apache.openejb.assembler.classic.MethodPermissionInfo;
031:        import org.apache.openejb.assembler.classic.MethodTransactionInfo;
032:        import org.apache.openejb.assembler.classic.NamedMethodInfo;
033:        import org.apache.openejb.assembler.classic.QueryInfo;
034:        import org.apache.openejb.assembler.classic.RemoveMethodInfo;
035:        import org.apache.openejb.assembler.classic.SecurityRoleInfo;
036:        import org.apache.openejb.assembler.classic.SecurityRoleReferenceInfo;
037:        import org.apache.openejb.assembler.classic.StatefulBeanInfo;
038:        import org.apache.openejb.assembler.classic.StatelessBeanInfo;
039:        import org.apache.openejb.assembler.classic.ApplicationExceptionInfo;
040:        import org.apache.openejb.assembler.classic.JndiNameInfo;
041:        import org.apache.openejb.jee.ActivationConfig;
042:        import org.apache.openejb.jee.ActivationConfigProperty;
043:        import org.apache.openejb.jee.CallbackMethod;
044:        import org.apache.openejb.jee.CmpField;
045:        import org.apache.openejb.jee.CmpVersion;
046:        import org.apache.openejb.jee.ContainerTransaction;
047:        import org.apache.openejb.jee.EjbRelation;
048:        import org.apache.openejb.jee.EjbRelationshipRole;
049:        import org.apache.openejb.jee.EnterpriseBean;
050:        import org.apache.openejb.jee.EntityBean;
051:        import org.apache.openejb.jee.Icon;
052:        import org.apache.openejb.jee.InitMethod;
053:        import org.apache.openejb.jee.Interceptor;
054:        import org.apache.openejb.jee.InterceptorBinding;
055:        import org.apache.openejb.jee.JndiConsumer;
056:        import org.apache.openejb.jee.MessageDrivenBean;
057:        import org.apache.openejb.jee.Method;
058:        import org.apache.openejb.jee.MethodParams;
059:        import org.apache.openejb.jee.MethodPermission;
060:        import org.apache.openejb.jee.Multiplicity;
061:        import org.apache.openejb.jee.NamedMethod;
062:        import org.apache.openejb.jee.PersistenceType;
063:        import org.apache.openejb.jee.Query;
064:        import org.apache.openejb.jee.QueryMethod;
065:        import org.apache.openejb.jee.RemoteBean;
066:        import org.apache.openejb.jee.RemoveMethod;
067:        import org.apache.openejb.jee.SecurityRole;
068:        import org.apache.openejb.jee.SecurityRoleRef;
069:        import org.apache.openejb.jee.SessionBean;
070:        import org.apache.openejb.jee.SessionType;
071:        import org.apache.openejb.jee.TransactionType;
072:        import org.apache.openejb.jee.ExcludeList;
073:        import org.apache.openejb.jee.ResultTypeMapping;
074:        import org.apache.openejb.jee.ApplicationException;
075:        import org.apache.openejb.jee.oejb3.EjbDeployment;
076:        import org.apache.openejb.jee.oejb3.ResourceLink;
077:        import org.apache.openejb.jee.oejb3.Jndi;
078:        import org.apache.openejb.util.LogCategory;
079:        import org.apache.openejb.util.Logger;
080:        import org.apache.openejb.util.Messages;
081:
082:        import java.io.File;
083:        import java.util.ArrayList;
084:        import java.util.Collections;
085:        import java.util.HashMap;
086:        import java.util.Iterator;
087:        import java.util.List;
088:        import java.util.Map;
089:        import java.util.Collection;
090:
091:        /**
092:         * @version $Revision: 638255 $ $Date: 2008-03-18 01:02:11 -0700 $
093:         */
094:        public class EjbJarInfoBuilder {
095:
096:            public static Messages messages = new Messages(
097:                    "org.apache.openejb.util.resources");
098:            public static Logger logger = Logger.getInstance(
099:                    LogCategory.OPENEJB, "org.apache.openejb.util.resources");
100:
101:            private final List<String> deploymentIds = new ArrayList<String>();
102:            private final List<String> securityRoles = new ArrayList<String>();
103:
104:            public EjbJarInfo buildInfo(EjbModule jar) throws OpenEJBException {
105:                deploymentIds.clear();
106:                securityRoles.clear();
107:                int beansDeployed = jar.getOpenejbJar().getEjbDeploymentCount();
108:                int beansInEjbJar = jar.getEjbJar().getEnterpriseBeans().length;
109:
110:                if (beansInEjbJar != beansDeployed) {
111:                    Map<String, EjbDeployment> deployed = jar.getOpenejbJar()
112:                            .getDeploymentsByEjbName();
113:                    for (EnterpriseBean bean : jar.getEjbJar()
114:                            .getEnterpriseBeans()) {
115:                        if (!deployed.containsKey(bean.getEjbName())) {
116:                            ConfigUtils.logger.warning("conf.0018", bean
117:                                    .getEjbName(), jar.getJarLocation());
118:                        }
119:                    }
120:                    String message = messages.format("conf.0008", jar
121:                            .getJarLocation(), "" + beansInEjbJar, ""
122:                            + beansDeployed);
123:                    logger.warning(message);
124:                    throw new OpenEJBException(message);
125:                }
126:
127:                Map<String, EjbDeployment> ejbds = jar.getOpenejbJar()
128:                        .getDeploymentsByEjbName();
129:                Map<String, EnterpriseBeanInfo> infos = new HashMap<String, EnterpriseBeanInfo>();
130:                Map<String, EnterpriseBean> items = new HashMap<String, EnterpriseBean>();
131:
132:                EjbJarInfo ejbJar = new EjbJarInfo();
133:                ejbJar.jarPath = jar.getJarLocation();
134:                ejbJar.moduleId = jar.getModuleId();
135:                if (ejbJar.moduleId == null) {
136:                    ejbJar.moduleId = new File(ejbJar.jarPath).getName()
137:                            .replaceFirst(".jar$", "");
138:                }
139:                ejbJar.watchedResources.addAll(jar.getWatchedResources());
140:
141:                ejbJar.properties.putAll(jar.getOpenejbJar().getProperties());
142:
143:                for (EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
144:                    EnterpriseBeanInfo beanInfo;
145:                    if (bean instanceof  org.apache.openejb.jee.SessionBean) {
146:                        beanInfo = initSessionBean((SessionBean) bean, ejbds);
147:                    } else if (bean instanceof  org.apache.openejb.jee.EntityBean) {
148:                        beanInfo = initEntityBean((EntityBean) bean, ejbds);
149:                    } else if (bean instanceof  org.apache.openejb.jee.MessageDrivenBean) {
150:                        beanInfo = initMessageBean((MessageDrivenBean) bean,
151:                                ejbds);
152:                    } else {
153:                        throw new OpenEJBException("Unknown bean type: "
154:                                + bean.getClass().getName());
155:                    }
156:                    ejbJar.enterpriseBeans.add(beanInfo);
157:
158:                    if (deploymentIds.contains(beanInfo.ejbDeploymentId)) {
159:                        String message = messages.format("conf.0100",
160:                                beanInfo.ejbDeploymentId, jar.getJarLocation(),
161:                                beanInfo.ejbName);
162:                        logger.warning(message);
163:                        throw new OpenEJBException(message);
164:                    }
165:
166:                    deploymentIds.add(beanInfo.ejbDeploymentId);
167:
168:                    beanInfo.codebase = jar.getJarLocation();
169:                    infos.put(beanInfo.ejbName, beanInfo);
170:                    items.put(beanInfo.ejbName, bean);
171:
172:                    if (bean.getSecurityIdentity() != null) {
173:                        beanInfo.runAs = bean.getSecurityIdentity().getRunAs();
174:                    }
175:
176:                    initJndiNames(ejbds, bean, beanInfo);
177:                }
178:
179:                if (jar.getEjbJar().getAssemblyDescriptor() != null) {
180:                    initInterceptors(jar, ejbJar, infos);
181:                    initSecurityRoles(jar, ejbJar);
182:                    initMethodPermissions(jar, ejbds, ejbJar);
183:                    initExcludesList(jar, ejbds, ejbJar);
184:                    initMethodTransactions(jar, ejbds, ejbJar);
185:                    initApplicationExceptions(jar, ejbJar);
186:
187:                    for (EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
188:                        resolveRoleLinks(jar, bean, items.get(bean.ejbName));
189:                    }
190:                }
191:
192:                if (jar.getEjbJar().getRelationships() != null) {
193:                    initRelationships(jar, infos);
194:                }
195:
196:                return ejbJar;
197:            }
198:
199:            private void initJndiNames(Map<String, EjbDeployment> ejbds,
200:                    EnterpriseBean bean, EnterpriseBeanInfo info) {
201:                EjbDeployment deployment = ejbds.get(info.ejbDeploymentId);
202:                if (deployment != null)
203:                    for (Jndi jndi : deployment.getJndi()) {
204:                        JndiNameInfo jndiNameInfo = new JndiNameInfo();
205:                        jndiNameInfo.intrface = jndi.getInterface();
206:                        jndiNameInfo.name = jndi.getName();
207:                        info.jndiNamess.add(jndiNameInfo);
208:                    }
209:            }
210:
211:            private void initRelationships(EjbModule jar,
212:                    Map<String, EnterpriseBeanInfo> infos)
213:                    throws OpenEJBException {
214:                for (EjbRelation ejbRelation : jar.getEjbJar()
215:                        .getRelationships().getEjbRelation()) {
216:                    Iterator<EjbRelationshipRole> iterator = ejbRelation
217:                            .getEjbRelationshipRole().iterator();
218:                    EjbRelationshipRole left = iterator.next();
219:                    EjbRelationshipRole right = iterator.next();
220:
221:                    // left role info
222:                    CmrFieldInfo leftCmrFieldInfo = initRelationshipRole(left,
223:                            right, infos);
224:                    CmrFieldInfo rightCmrFieldInfo = initRelationshipRole(
225:                            right, left, infos);
226:                    leftCmrFieldInfo.mappedBy = rightCmrFieldInfo;
227:                    rightCmrFieldInfo.mappedBy = leftCmrFieldInfo;
228:                }
229:            }
230:
231:            private CmrFieldInfo initRelationshipRole(EjbRelationshipRole role,
232:                    EjbRelationshipRole relatedRole,
233:                    Map<String, EnterpriseBeanInfo> infos)
234:                    throws OpenEJBException {
235:                CmrFieldInfo cmrFieldInfo = new CmrFieldInfo();
236:
237:                // find the entityBeanInfo info for this role
238:                String ejbName = role.getRelationshipRoleSource().getEjbName();
239:                EnterpriseBeanInfo enterpriseBeanInfo = infos.get(ejbName);
240:                if (enterpriseBeanInfo == null) {
241:                    throw new OpenEJBException(
242:                            "Relation role source ejb not found " + ejbName);
243:                }
244:                if (!(enterpriseBeanInfo instanceof  EntityBeanInfo)) {
245:                    throw new OpenEJBException(
246:                            "Relation role source ejb is not an entity bean "
247:                                    + ejbName);
248:                }
249:                EntityBeanInfo entityBeanInfo = (EntityBeanInfo) enterpriseBeanInfo;
250:                cmrFieldInfo.roleSource = entityBeanInfo;
251:
252:                // RoleName: this may be null
253:                cmrFieldInfo.roleName = role.getEjbRelationshipRoleName();
254:
255:                cmrFieldInfo.synthetic = role.getCmrField() == null;
256:
257:                // CmrFieldName: is null for uni-directional relationships
258:                if (role.getCmrField() != null) {
259:                    cmrFieldInfo.fieldName = role.getCmrField()
260:                            .getCmrFieldName();
261:                    // CollectionType: java.util.Collection or java.util.Set
262:                    if (role.getCmrField().getCmrFieldType() != null) {
263:                        cmrFieldInfo.fieldType = role.getCmrField()
264:                                .getCmrFieldType().toString();
265:                    }
266:                } else {
267:                    String relatedEjbName = relatedRole
268:                            .getRelationshipRoleSource().getEjbName();
269:                    EnterpriseBeanInfo relatedEjb = infos.get(relatedEjbName);
270:                    if (relatedEjb == null) {
271:                        throw new OpenEJBException(
272:                                "Relation role source ejb not found "
273:                                        + relatedEjbName);
274:                    }
275:                    if (!(relatedEjb instanceof  EntityBeanInfo)) {
276:                        throw new OpenEJBException(
277:                                "Relation role source ejb is not an entity bean "
278:                                        + relatedEjbName);
279:                    }
280:                    EntityBeanInfo relatedEntity = (EntityBeanInfo) relatedEjb;
281:
282:                    relatedRole.getRelationshipRoleSource();
283:                    cmrFieldInfo.fieldName = relatedEntity.abstractSchemaName
284:                            + "_" + relatedRole.getCmrField().getCmrFieldName();
285:                    if (relatedRole.getMultiplicity() == Multiplicity.MANY) {
286:                        cmrFieldInfo.fieldType = Collection.class.getName();
287:                    }
288:                }
289:
290:                // CascadeDelete
291:                cmrFieldInfo.cascadeDelete = role.getCascadeDelete();
292:                // Multiplicity: one or many
293:                cmrFieldInfo.many = role.getMultiplicity() == Multiplicity.MANY;
294:
295:                // add the field to the entityBean
296:                entityBeanInfo.cmrFields.add(cmrFieldInfo);
297:
298:                return cmrFieldInfo;
299:            }
300:
301:            private void initInterceptors(EjbModule jar, EjbJarInfo ejbJar,
302:                    Map<String, EnterpriseBeanInfo> beanInfos)
303:                    throws OpenEJBException {
304:                if (jar.getEjbJar().getInterceptors().length == 0)
305:                    return;
306:                if (jar.getEjbJar().getAssemblyDescriptor() == null)
307:                    return;
308:                if (jar.getEjbJar().getAssemblyDescriptor()
309:                        .getInterceptorBinding() == null)
310:                    return;
311:
312:                for (Interceptor s : jar.getEjbJar().getInterceptors()) {
313:                    InterceptorInfo info = new InterceptorInfo();
314:
315:                    info.clazz = s.getInterceptorClass();
316:
317:                    copyCallbacks(s.getAroundInvoke(), info.aroundInvoke);
318:
319:                    copyCallbacks(s.getPostConstruct(), info.postConstruct);
320:                    copyCallbacks(s.getPreDestroy(), info.preDestroy);
321:
322:                    copyCallbacks(s.getPostActivate(), info.postActivate);
323:                    copyCallbacks(s.getPrePassivate(), info.prePassivate);
324:
325:                    ejbJar.interceptors.add(info);
326:                }
327:
328:                for (InterceptorBinding binding : jar.getEjbJar()
329:                        .getAssemblyDescriptor().getInterceptorBinding()) {
330:                    InterceptorBindingInfo info = new InterceptorBindingInfo();
331:                    info.ejbName = binding.getEjbName();
332:                    info.excludeClassInterceptors = binding
333:                            .getExcludeClassInterceptors();
334:                    info.excludeDefaultInterceptors = binding
335:                            .getExcludeDefaultInterceptors();
336:                    info.interceptors.addAll(binding.getInterceptorClass());
337:                    if (binding.getInterceptorOrder() != null) {
338:                        info.interceptorOrder.addAll(binding
339:                                .getInterceptorOrder().getInterceptorClass());
340:                    }
341:
342:                    info.method = toInfo(binding.getMethod());
343:                    ejbJar.interceptorBindings.add(info);
344:                }
345:            }
346:
347:            private void initMethodTransactions(EjbModule jar, Map ejbds,
348:                    EjbJarInfo ejbJarInfo) {
349:
350:                List<ContainerTransaction> containerTransactions = jar
351:                        .getEjbJar().getAssemblyDescriptor()
352:                        .getContainerTransaction();
353:                for (ContainerTransaction cTx : containerTransactions) {
354:                    MethodTransactionInfo info = new MethodTransactionInfo();
355:
356:                    info.description = cTx.getDescription();
357:                    info.transAttribute = cTx.getTransAttribute().toString();
358:                    info.methods.addAll(getMethodInfos(cTx.getMethod(), ejbds));
359:                    ejbJarInfo.methodTransactions.add(info);
360:                }
361:            }
362:
363:            private void initApplicationExceptions(EjbModule jar,
364:                    EjbJarInfo ejbJarInfo) {
365:                for (ApplicationException applicationException : jar
366:                        .getEjbJar().getAssemblyDescriptor()
367:                        .getApplicationException()) {
368:                    ApplicationExceptionInfo info = new ApplicationExceptionInfo();
369:                    info.exceptionClass = applicationException
370:                            .getExceptionClass();
371:                    info.rollback = applicationException.getRollback();
372:                    ejbJarInfo.applicationException.add(info);
373:                }
374:            }
375:
376:            private void initSecurityRoles(EjbModule jar, EjbJarInfo ejbJarInfo) {
377:
378:                List<SecurityRole> roles = jar.getEjbJar()
379:                        .getAssemblyDescriptor().getSecurityRole();
380:
381:                for (SecurityRole sr : roles) {
382:                    SecurityRoleInfo info = new SecurityRoleInfo();
383:
384:                    info.description = sr.getDescription();
385:                    info.roleName = sr.getRoleName();
386:
387:                    if (securityRoles.contains(sr.getRoleName())) {
388:                        ConfigUtils.logger.warning("conf.0102", jar
389:                                .getJarLocation(), sr.getRoleName());
390:                    } else {
391:                        securityRoles.add(sr.getRoleName());
392:                    }
393:                    ejbJarInfo.securityRoles.add(info);
394:                }
395:            }
396:
397:            private void initMethodPermissions(EjbModule jar, Map ejbds,
398:                    EjbJarInfo ejbJarInfo) {
399:
400:                List<MethodPermission> methodPermissions = jar.getEjbJar()
401:                        .getAssemblyDescriptor().getMethodPermission();
402:
403:                for (MethodPermission mp : methodPermissions) {
404:                    MethodPermissionInfo info = new MethodPermissionInfo();
405:
406:                    info.description = mp.getDescription();
407:                    info.roleNames.addAll(mp.getRoleName());
408:                    info.methods.addAll(getMethodInfos(mp.getMethod(), ejbds));
409:                    info.unchecked = mp.getUnchecked();
410:
411:                    ejbJarInfo.methodPermissions.add(info);
412:                }
413:            }
414:
415:            private void initExcludesList(EjbModule jar, Map ejbds,
416:                    EjbJarInfo ejbJarInfo) {
417:
418:                ExcludeList methodPermissions = jar.getEjbJar()
419:                        .getAssemblyDescriptor().getExcludeList();
420:
421:                for (Method excludedMethod : methodPermissions.getMethod()) {
422:                    ejbJarInfo.excludeList.add(getMethodInfo(excludedMethod,
423:                            ejbds));
424:                }
425:            }
426:
427:            private void resolveRoleLinks(EjbModule jar,
428:                    EnterpriseBeanInfo bean, JndiConsumer item) {
429:                if (!(item instanceof  RemoteBean)) {
430:                    return;
431:                }
432:
433:                RemoteBean rb = (RemoteBean) item;
434:
435:                List<SecurityRoleRef> refs = rb.getSecurityRoleRef();
436:                for (SecurityRoleRef ref : refs) {
437:                    SecurityRoleReferenceInfo info = new SecurityRoleReferenceInfo();
438:
439:                    info.description = ref.getDescription();
440:                    info.roleLink = ref.getRoleLink();
441:                    info.roleName = ref.getRoleName();
442:
443:                    if (info.roleLink == null) {
444:                        info.roleLink = info.roleName;
445:                    }
446:                    bean.securityRoleReferences.add(info);
447:                }
448:            }
449:
450:            private List<MethodInfo> getMethodInfos(List<Method> ms, Map ejbds) {
451:                if (ms == null)
452:                    return Collections.emptyList();
453:
454:                List<MethodInfo> mi = new ArrayList<MethodInfo>(ms.size());
455:                for (Method method : ms) {
456:                    MethodInfo methodInfo = getMethodInfo(method, ejbds);
457:                    mi.add(methodInfo);
458:                }
459:
460:                return mi;
461:            }
462:
463:            private MethodInfo getMethodInfo(Method method, Map ejbds) {
464:                MethodInfo methodInfo = new MethodInfo();
465:
466:                EjbDeployment d = (EjbDeployment) ejbds
467:                        .get(method.getEjbName());
468:
469:                methodInfo.description = method.getDescription();
470:                methodInfo.ejbDeploymentId = (d == null) ? null : d
471:                        .getDeploymentId();
472:                methodInfo.ejbName = method.getEjbName();
473:                methodInfo.methodIntf = (method.getMethodIntf() == null) ? null
474:                        : method.getMethodIntf().toString();
475:                methodInfo.methodName = method.getMethodName();
476:                if (methodInfo.methodName == null
477:                        || methodInfo.methodName.equals("")) {
478:                    methodInfo.methodName = "*";
479:                }
480:                methodInfo.className = method.getClassName();
481:                if (methodInfo.className == null
482:                        || methodInfo.className.equals("")) {
483:                    methodInfo.className = "*";
484:                }
485:
486:                MethodParams mp = method.getMethodParams();
487:                if (mp != null) {
488:                    methodInfo.methodParams = mp.getMethodParam();
489:                }
490:                return methodInfo;
491:            }
492:
493:            private EnterpriseBeanInfo initSessionBean(SessionBean s, Map m)
494:                    throws OpenEJBException {
495:                EnterpriseBeanInfo bean = null;
496:
497:                if (s.getSessionType() == SessionType.STATEFUL) {
498:                    bean = new StatefulBeanInfo();
499:                    StatefulBeanInfo stateful = ((StatefulBeanInfo) bean);
500:
501:                    copyCallbacks(s.getPostActivate(), stateful.postActivate);
502:                    copyCallbacks(s.getPrePassivate(), stateful.prePassivate);
503:
504:                    for (InitMethod initMethod : s.getInitMethod()) {
505:                        InitMethodInfo init = new InitMethodInfo();
506:                        init.beanMethod = toInfo(initMethod.getBeanMethod());
507:                        init.createMethod = toInfo(initMethod.getCreateMethod());
508:                        stateful.initMethods.add(init);
509:                    }
510:
511:                    for (RemoveMethod removeMethod : s.getRemoveMethod()) {
512:                        RemoveMethodInfo remove = new RemoveMethodInfo();
513:                        remove.beanMethod = toInfo(removeMethod.getBeanMethod());
514:                        remove.retainIfException = removeMethod
515:                                .getRetainIfException();
516:                        stateful.removeMethods.add(remove);
517:                    }
518:
519:                } else {
520:                    bean = new StatelessBeanInfo();
521:                }
522:
523:                bean.timeoutMethod = toInfo(s.getTimeoutMethod());
524:
525:                copyCallbacks(s.getAroundInvoke(), bean.aroundInvoke);
526:                copyCallbacks(s.getPostConstruct(), bean.postConstruct);
527:                copyCallbacks(s.getPreDestroy(), bean.preDestroy);
528:
529:                EjbDeployment d = (EjbDeployment) m.get(s.getEjbName());
530:                if (d == null) {
531:                    throw new OpenEJBException(
532:                            "No deployment information in openejb-jar.xml for bean "
533:                                    + s.getEjbName()
534:                                    + ". Please redeploy the jar");
535:                }
536:                bean.ejbDeploymentId = d.getDeploymentId();
537:                bean.containerId = d.getContainerId();
538:
539:                Icon icon = s.getIcon();
540:                bean.largeIcon = (icon == null) ? null : icon.getLargeIcon();
541:                bean.smallIcon = (icon == null) ? null : icon.getSmallIcon();
542:                bean.description = s.getDescription();
543:                bean.displayName = s.getDisplayName();
544:                bean.ejbClass = s.getEjbClass();
545:                bean.ejbName = s.getEjbName();
546:                bean.home = s.getHome();
547:                bean.remote = s.getRemote();
548:                bean.localHome = s.getLocalHome();
549:                bean.local = s.getLocal();
550:                bean.businessLocal.addAll(s.getBusinessLocal());
551:                bean.businessRemote.addAll(s.getBusinessRemote());
552:                TransactionType txType = s.getTransactionType();
553:                bean.transactionType = (txType != null) ? txType.toString()
554:                        : TransactionType.CONTAINER.toString();
555:                bean.serviceEndpoint = s.getServiceEndpoint();
556:
557:                return bean;
558:            }
559:
560:            private EnterpriseBeanInfo initMessageBean(MessageDrivenBean mdb,
561:                    Map m) throws OpenEJBException {
562:                MessageDrivenBeanInfo bean = new MessageDrivenBeanInfo();
563:
564:                bean.timeoutMethod = toInfo(mdb.getTimeoutMethod());
565:
566:                copyCallbacks(mdb.getAroundInvoke(), bean.aroundInvoke);
567:                copyCallbacks(mdb.getPostConstruct(), bean.postConstruct);
568:                copyCallbacks(mdb.getPreDestroy(), bean.preDestroy);
569:
570:                EjbDeployment d = (EjbDeployment) m.get(mdb.getEjbName());
571:                if (d == null) {
572:                    throw new OpenEJBException(
573:                            "No deployment information in openejb-jar.xml for bean "
574:                                    + mdb.getEjbName()
575:                                    + ". Please redeploy the jar");
576:                }
577:                bean.ejbDeploymentId = d.getDeploymentId();
578:                bean.containerId = d.getContainerId();
579:
580:                Icon icon = mdb.getIcon();
581:                bean.largeIcon = (icon == null) ? null : icon.getLargeIcon();
582:                bean.smallIcon = (icon == null) ? null : icon.getSmallIcon();
583:                bean.description = mdb.getDescription();
584:                bean.displayName = mdb.getDisplayName();
585:                bean.ejbClass = mdb.getEjbClass();
586:                bean.ejbName = mdb.getEjbName();
587:                TransactionType txType = mdb.getTransactionType();
588:                bean.transactionType = (txType != null) ? txType.toString()
589:                        : TransactionType.CONTAINER.toString();
590:
591:                if (mdb.getMessagingType() != null) {
592:                    bean.mdbInterface = mdb.getMessagingType();
593:                } else {
594:                    bean.mdbInterface = "javax.jms.MessageListener";
595:                }
596:
597:                ResourceLink resourceLink = d
598:                        .getResourceLink("openejb/destination");
599:                if (resourceLink != null) {
600:                    bean.destinationId = resourceLink.getResId();
601:                }
602:
603:                if (mdb.getMessageDestinationType() != null) {
604:                    bean.activationProperties.put("destinationType", mdb
605:                            .getMessageDestinationType());
606:                }
607:
608:                ActivationConfig activationConfig = mdb.getActivationConfig();
609:                if (activationConfig != null) {
610:                    for (ActivationConfigProperty property : activationConfig
611:                            .getActivationConfigProperty()) {
612:                        String name = property
613:                                .getActivationConfigPropertyName();
614:                        String value = property
615:                                .getActivationConfigPropertyValue();
616:                        bean.activationProperties.put(name, value);
617:                    }
618:                }
619:
620:                return bean;
621:            }
622:
623:            private NamedMethodInfo toInfo(NamedMethod method) {
624:                if (method == null)
625:                    return null;
626:
627:                NamedMethodInfo info = new NamedMethodInfo();
628:
629:                info.methodName = method.getMethodName();
630:
631:                if (method.getMethodParams() != null) {
632:                    info.methodParams = method.getMethodParams()
633:                            .getMethodParam();
634:                }
635:
636:                return info;
637:            }
638:
639:            private void copyCallbacks(List<? extends CallbackMethod> from,
640:                    List<CallbackInfo> to) {
641:                for (CallbackMethod callback : from) {
642:                    CallbackInfo info = new CallbackInfo();
643:                    info.className = callback.getClassName();
644:                    info.method = callback.getMethodName();
645:                    to.add(info);
646:                }
647:            }
648:
649:            private EnterpriseBeanInfo initEntityBean(EntityBean e, Map m)
650:                    throws OpenEJBException {
651:                EntityBeanInfo bean = new EntityBeanInfo();
652:
653:                EjbDeployment d = (EjbDeployment) m.get(e.getEjbName());
654:                if (d == null) {
655:                    throw new OpenEJBException(
656:                            "No deployment information in openejb-jar.xml for bean "
657:                                    + e.getEjbName()
658:                                    + ". Please redeploy the jar");
659:                }
660:                bean.ejbDeploymentId = d.getDeploymentId();
661:                bean.containerId = d.getContainerId();
662:
663:                Icon icon = e.getIcon();
664:                bean.largeIcon = (icon == null) ? null : icon.getLargeIcon();
665:                bean.smallIcon = (icon == null) ? null : icon.getSmallIcon();
666:                bean.description = e.getDescription();
667:                bean.displayName = e.getDisplayName();
668:                bean.ejbClass = e.getEjbClass();
669:                bean.abstractSchemaName = e.getAbstractSchemaName();
670:                bean.ejbName = e.getEjbName();
671:                bean.home = e.getHome();
672:                bean.remote = e.getRemote();
673:                bean.localHome = e.getLocalHome();
674:                bean.local = e.getLocal();
675:                bean.transactionType = "Container";
676:
677:                bean.primKeyClass = e.getPrimKeyClass();
678:                bean.primKeyField = e.getPrimkeyField();
679:                bean.persistenceType = e.getPersistenceType().toString();
680:                bean.reentrant = e.getReentrant() + "";
681:
682:                CmpVersion cmpVersion = e.getCmpVersion();
683:                if (e.getPersistenceType() == PersistenceType.CONTAINER) {
684:                    if (cmpVersion != null && cmpVersion == CmpVersion.CMP1) {
685:                        bean.cmpVersion = 1;
686:                    } else {
687:                        bean.cmpVersion = 2;
688:                    }
689:                }
690:
691:                List<CmpField> cmpFields = e.getCmpField();
692:                for (CmpField cmpField : cmpFields) {
693:                    bean.cmpFieldNames.add(cmpField.getFieldName());
694:                }
695:
696:                if (bean.persistenceType.equalsIgnoreCase("Container")) {
697:                    for (Query q : e.getQuery()) {
698:                        QueryInfo query = new QueryInfo();
699:                        query.queryStatement = q.getEjbQl().trim();
700:
701:                        MethodInfo method = new MethodInfo();
702:                        method.ejbName = bean.ejbName;
703:                        method.className = "*";
704:
705:                        QueryMethod qm = q.getQueryMethod();
706:                        method.methodName = qm.getMethodName();
707:                        if (qm.getMethodParams() != null) {
708:                            method.methodParams = qm.getMethodParams()
709:                                    .getMethodParam();
710:                        }
711:                        query.method = method;
712:                        ResultTypeMapping resultType = q.getResultTypeMapping();
713:                        if (ResultTypeMapping.REMOTE.equals(resultType)) {
714:                            query.remoteResultType = true;
715:                        }
716:                        bean.queries.add(query);
717:                    }
718:
719:                    for (org.apache.openejb.jee.oejb3.Query q : d.getQuery()) {
720:                        QueryInfo query = new QueryInfo();
721:                        query.description = q.getDescription();
722:                        query.queryStatement = q.getObjectQl().trim();
723:
724:                        MethodInfo method = new MethodInfo();
725:                        method.ejbName = bean.ejbName;
726:                        method.className = "*";
727:                        org.apache.openejb.jee.oejb3.QueryMethod qm = q
728:                                .getQueryMethod();
729:                        method.methodName = qm.getMethodName();
730:                        if (qm.getMethodParams() != null) {
731:                            method.methodParams = qm.getMethodParams()
732:                                    .getMethodParam();
733:                        }
734:                        query.method = method;
735:                        bean.queries.add(query);
736:                    }
737:                }
738:                return bean;
739:            }
740:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.