Source Code Cross Referenced for ApplicationMetaData.java in  » EJB-Server-JBoss-4.2.1 » server » org » jboss » metadata » 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 » EJB Server JBoss 4.2.1 » server » org.jboss.metadata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.metadata;
023:
024:        import java.net.URL;
025:        import java.net.URLClassLoader;
026:        import java.util.ArrayList;
027:        import java.util.HashMap;
028:        import java.util.HashSet;
029:        import java.util.Iterator;
030:        import java.util.Set;
031:
032:        import javax.management.MBeanServer;
033:        import javax.management.ObjectName;
034:
035:        import org.jboss.deployment.DeploymentException;
036:        import org.jboss.mx.util.MBeanServerLocator;
037:        import org.jboss.security.SecurityRoleMetaData;
038:        import org.w3c.dom.DocumentType;
039:        import org.w3c.dom.Element;
040:
041:        /**
042:         * The top level meta data from the jboss.xml and ejb-jar.xml descriptor.
043:         *
044:         * @author <a href="mailto:sebastien.alborini@m4x.org">Sebastien Alborini</a>
045:         * @author <a href="mailto:peter.antman@tim.se">Peter Antman</a>
046:         * @author <a href="mailto:Scott.Stark@jboss.org">Scott Stark</a>
047:         * @author <a href="mailto:criege@riege.com">Christian Riege</a>
048:         * @author <a href="mailto:Christoph.Jung@infor.de">Christoph G. Jung</a>.
049:         * @author <a href="mailto:Thomas.Diesler@jboss.org">Thomas Diesler</a>.
050:         *
051:         * @version $Revision: 57209 $
052:         */
053:        public class ApplicationMetaData extends MetaData {
054:            public static final int EJB_1x = 1;
055:            public static final int EJB_2x = 2;
056:            /** The ejb jar URL */
057:            private URL url;
058:            /** version of the dtd used to create ejb-jar.xml */
059:            protected int ejbVersion;
060:            protected int ejbMinorVersion;
061:            /** ArrayList<BeanMetaData> for the ejbs */
062:            private ArrayList beans = new ArrayList();
063:            /** A HashMap<String, String> for webservice description publish locations */
064:            private HashMap wsdlPublishLocationMap = new HashMap();
065:            /** True if this is a web service deployment */
066:            private boolean webServiceDeployment;
067:            /** The optional JBossWS config-name */
068:            private String configName;
069:            /** The optional JBossWS config-file */
070:            private String configFile;
071:            /** List<RelationMetaData> of relations in this application. */
072:            private ArrayList relationships = new ArrayList();
073:            /** The assembly-descriptor */
074:            private AssemblyDescriptorMetaData assemblyDescriptor = new AssemblyDescriptorMetaData();
075:            /** A HashMap<String, ConfigurationMetaData> for container configs */
076:            private HashMap configurations = new HashMap();
077:            /** A HashMap<String, InvokerProxyBindingMetaData> for invoker bindings */
078:            private HashMap invokerBindings = new HashMap();
079:            /** A HashMap<String, String> of res-name to JNDI name/URL */
080:            private HashMap resources = new HashMap();
081:            private HashMap plugins = new HashMap();
082:            /** The user defined JMX name for the EJBModule */
083:            private String jmxName;
084:            /** The security-domain value assigned to the application */
085:            private String securityDomain;
086:            /** The  unauthenticated-principal value assigned to the application */
087:            private String unauthenticatedPrincipal;
088:            /** The web context root to use for web services */
089:            private String webServiceContextRoot;
090:            /** An unused flag if the spec security restrictions should be enforced */
091:            private boolean enforceEjbRestrictions;
092:            /** The missing-method-permissions-excluded-mode value */
093:            private boolean excludeMissingMethods = true;
094:            /** Whether to throw an exception on a rollback if there is no exception */
095:            private boolean exceptionRollback = false;
096:
097:            /** The ClassLoader to load additional resources */
098:            private URLClassLoader resourceCl;
099:
100:            public ApplicationMetaData() {
101:            }
102:
103:            /** Get the ClassLoader to load additional resources */
104:            public URLClassLoader getResourceCl() {
105:                return resourceCl;
106:            }
107:
108:            /** Set the ClassLoader to load additional resources */
109:            public void setResourceClassLoader(URLClassLoader resourceCl) {
110:                this .resourceCl = resourceCl;
111:            }
112:
113:            public URL getUrl() {
114:                return url;
115:            }
116:
117:            public void setUrl(URL u) {
118:                url = u;
119:            }
120:
121:            public boolean isEJB1x() {
122:                return ejbVersion == 1;
123:            }
124:
125:            public boolean isEJB2x() {
126:                return ejbVersion == 2;
127:            }
128:
129:            public boolean isEJB21() {
130:                return ejbVersion == 2 && ejbMinorVersion == 1;
131:            }
132:
133:            public Iterator getEnterpriseBeans() {
134:                return beans.iterator();
135:            }
136:
137:            /**
138:             * Get an EJB by its declared &lt;ejb-name&gt; tag
139:             *
140:             * @param ejbName EJB to return
141:             *
142:             * @return BeanMetaData pertaining to the given ejb-name,
143:             *   <code>null</code> if none found
144:             */
145:            public BeanMetaData getBeanByEjbName(String ejbName) {
146:                Iterator iterator = getEnterpriseBeans();
147:                while (iterator.hasNext()) {
148:                    BeanMetaData current = (BeanMetaData) iterator.next();
149:                    if (current.getEjbName().equals(ejbName)) {
150:                        return current;
151:                    }
152:                }
153:
154:                // not found
155:                return null;
156:            }
157:
158:            public String getConfigFile() {
159:                return configFile;
160:            }
161:
162:            public void setConfigFile(String configFile) {
163:                this .configFile = configFile;
164:            }
165:
166:            public String getConfigName() {
167:                return configName;
168:            }
169:
170:            public void setConfigName(String configName) {
171:                this .configName = configName;
172:            }
173:
174:            public String getWsdlPublishLocationByName(String name) {
175:                // if not found, the we will use default
176:                return (String) wsdlPublishLocationMap.get(name);
177:            }
178:
179:            public String getWebServiceContextRoot() {
180:                return webServiceContextRoot;
181:            }
182:
183:            public void setWebServiceContextRoot(String webServiceContextRoot) {
184:                this .webServiceContextRoot = webServiceContextRoot;
185:            }
186:
187:            public boolean isWebServiceDeployment() {
188:                return webServiceDeployment;
189:            }
190:
191:            public void setWebServiceDeployment(boolean webServiceDeployment) {
192:                this .webServiceDeployment = webServiceDeployment;
193:            }
194:
195:            /**
196:             * Get the container managed relations in this application.
197:             * Items are instance of RelationMetaData.
198:             */
199:            public Iterator getRelationships() {
200:                return relationships.iterator();
201:            }
202:
203:            public AssemblyDescriptorMetaData getAssemblyDescriptor() {
204:                return assemblyDescriptor;
205:            }
206:
207:            public Iterator getConfigurations() {
208:                return configurations.values().iterator();
209:            }
210:
211:            public ConfigurationMetaData getConfigurationMetaDataByName(
212:                    String name) {
213:                return (ConfigurationMetaData) configurations.get(name);
214:            }
215:
216:            public Iterator getInvokerProxyBindings() {
217:                return invokerBindings.values().iterator();
218:            }
219:
220:            public InvokerProxyBindingMetaData getInvokerProxyBindingMetaDataByName(
221:                    String name) {
222:                return (InvokerProxyBindingMetaData) invokerBindings.get(name);
223:            }
224:
225:            public String getResourceByName(String name) {
226:                // if not found, the container will use default
227:                return (String) resources.get(name);
228:            }
229:
230:            public void addPluginData(String pluginName, Object pluginData) {
231:                plugins.put(pluginName, pluginData);
232:            }
233:
234:            public Object getPluginData(String pluginName) {
235:                return plugins.get(pluginName);
236:            }
237:
238:            public String getJmxName() {
239:                return jmxName;
240:            }
241:
242:            public String getSecurityDomain() {
243:                return securityDomain;
244:            }
245:
246:            /**
247:             * Set the security domain for this web application
248:             */
249:            public void setSecurityDomain(String securityDomain) {
250:                this .securityDomain = securityDomain;
251:            }
252:
253:            public String getUnauthenticatedPrincipal() {
254:                return unauthenticatedPrincipal;
255:            }
256:
257:            public void setUnauthenticatedPrincipal(
258:                    String unauthenticatedPrincipal) {
259:                this .unauthenticatedPrincipal = unauthenticatedPrincipal;
260:            }
261:
262:            public boolean getEnforceEjbRestrictions() {
263:                return enforceEjbRestrictions;
264:            }
265:
266:            public boolean isExcludeMissingMethods() {
267:                return excludeMissingMethods;
268:            }
269:
270:            public MessageDestinationMetaData getMessageDestination(String name) {
271:                return assemblyDescriptor.getMessageDestinationMetaData(name);
272:            }
273:
274:            public boolean getExceptionRollback() {
275:                return exceptionRollback;
276:            }
277:
278:            /**
279:             * Import data provided by ejb-jar.xml
280:             *
281:             * @throws DeploymentException When there was an error encountered
282:             *         while parsing ejb-jar.xml
283:             */
284:            public void importEjbJarXml(Element element)
285:                    throws DeploymentException {
286:                // EJB version is determined by the doc type that was used to
287:                // verify the ejb-jar.xml.
288:                DocumentType docType = element.getOwnerDocument().getDoctype();
289:
290:                if (docType == null) {
291:                    // test if this is a 2.1 schema-based descriptor
292:                    if ("http://java.sun.com/xml/ns/j2ee".equals(element
293:                            .getNamespaceURI())) {
294:                        ejbVersion = 2;
295:                        ejbMinorVersion = 1;
296:                    } else {
297:                        // No good, EJB 1.1/2.1 requires a DOCTYPE declaration
298:                        throw new DeploymentException(
299:                                "ejb-jar.xml must either obey "
300:                                        + "the right xml schema or define a valid DOCTYPE!");
301:                    }
302:                } else {
303:                    String publicId = docType.getPublicId();
304:                    if (publicId == null) {
305:                        // We need a public Id
306:                        throw new DeploymentException(
307:                                "The DOCTYPE declaration in "
308:                                        + "ejb-jar.xml must define a PUBLIC id");
309:                    }
310:
311:                    // Check for a known public Id
312:                    if (publicId
313:                            .startsWith("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0")) {
314:                        ejbVersion = 2;
315:                    } else if (publicId
316:                            .startsWith("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1")) {
317:                        ejbVersion = 1;
318:                    } else {
319:                        // Unknown
320:                        throw new DeploymentException("Unknown PUBLIC id in "
321:                                + "ejb-jar.xml: " + publicId);
322:                    }
323:                }
324:
325:                // find the beans
326:                Element enterpriseBeans = getUniqueChild(element,
327:                        "enterprise-beans");
328:
329:                // Entity Beans
330:                HashMap schemaNameMap = new HashMap();
331:                Iterator iterator = getChildrenByTagName(enterpriseBeans,
332:                        "entity");
333:                while (iterator.hasNext()) {
334:                    Element currentEntity = (Element) iterator.next();
335:                    EntityMetaData entityMetaData = new EntityMetaData(this );
336:                    try {
337:                        entityMetaData.importEjbJarXml(currentEntity);
338:                    } catch (DeploymentException e) {
339:                        throw new DeploymentException("Error in ejb-jar.xml "
340:                                + "for Entity Bean "
341:                                + entityMetaData.getEjbName() + ": "
342:                                + e.getMessage());
343:                    }
344:
345:                    // Ensure unique-ness of <abstract-schema-name>
346:                    String abstractSchemaName = entityMetaData
347:                            .getAbstractSchemaName();
348:                    if (abstractSchemaName != null) {
349:                        if (schemaNameMap.containsKey(abstractSchemaName)) {
350:                            //
351:                            throw new DeploymentException(entityMetaData
352:                                    .getEjbName()
353:                                    + ": Duplicate abstract-schema name '"
354:                                    + abstractSchemaName
355:                                    + "'. Already defined for Entity '"
356:                                    + ((EntityMetaData) schemaNameMap
357:                                            .get(abstractSchemaName))
358:                                            .getEjbName() + "'.");
359:                        }
360:                        schemaNameMap.put(abstractSchemaName, entityMetaData);
361:                    }
362:
363:                    beans.add(entityMetaData);
364:                }
365:
366:                // Session Beans
367:                iterator = getChildrenByTagName(enterpriseBeans, "session");
368:                while (iterator.hasNext()) {
369:                    Element currentSession = (Element) iterator.next();
370:                    SessionMetaData sessionMetaData = new SessionMetaData(this );
371:                    try {
372:                        sessionMetaData.importEjbJarXml(currentSession);
373:                    } catch (DeploymentException e) {
374:                        throw new DeploymentException(
375:                                "Error in ejb-jar.xml for " + "Session Bean "
376:                                        + sessionMetaData.getEjbName() + ": "
377:                                        + e.getMessage());
378:                    }
379:                    beans.add(sessionMetaData);
380:                }
381:
382:                // Message Driven Beans
383:                iterator = getChildrenByTagName(enterpriseBeans,
384:                        "message-driven");
385:                while (iterator.hasNext()) {
386:                    Element currentMessageDriven = (Element) iterator.next();
387:                    MessageDrivenMetaData messageDrivenMetaData = new MessageDrivenMetaData(
388:                            this );
389:
390:                    try {
391:                        messageDrivenMetaData
392:                                .importEjbJarXml(currentMessageDriven);
393:                    } catch (DeploymentException e) {
394:                        throw new DeploymentException(
395:                                "Error in ejb-jar.xml for "
396:                                        + "Message Driven Bean "
397:                                        + messageDrivenMetaData.getEjbName()
398:                                        + ": " + e.getMessage());
399:                    }
400:                    beans.add(messageDrivenMetaData);
401:                }
402:
403:                // Enforce unique-ness of declared ejb-name Elements
404:                Set ejbNames = new HashSet();
405:                Iterator beanIt = beans.iterator();
406:                while (beanIt.hasNext()) {
407:                    BeanMetaData bmd = (BeanMetaData) beanIt.next();
408:
409:                    String beanName = bmd.getEjbName();
410:                    if (ejbNames.contains(beanName)) {
411:                        throw new DeploymentException(
412:                                "Duplicate definition of an "
413:                                        + "EJB with name '" + beanName + "'.");
414:                    }
415:
416:                    ejbNames.add(beanName);
417:                }
418:
419:                // Relationships
420:                Element relationshipsElement = getOptionalChild(element,
421:                        "relationships");
422:                if (relationshipsElement != null) {
423:                    // used to assure that a relationship name is not reused
424:                    Set relationNames = new HashSet();
425:
426:                    iterator = getChildrenByTagName(relationshipsElement,
427:                            "ejb-relation");
428:                    while (iterator.hasNext()) {
429:                        Element relationElement = (Element) iterator.next();
430:                        RelationMetaData relationMetaData = new RelationMetaData();
431:                        try {
432:                            relationMetaData.importEjbJarXml(relationElement);
433:                        } catch (DeploymentException e) {
434:                            throw new DeploymentException(
435:                                    "Error in ejb-jar.xml "
436:                                            + "for relation "
437:                                            + relationMetaData
438:                                                    .getRelationName() + ": "
439:                                            + e.getMessage());
440:                        }
441:
442:                        // if the relationship has a name, assure that it has not
443:                        // already been used
444:                        String relationName = relationMetaData
445:                                .getRelationName();
446:                        if (relationName != null) {
447:                            if (relationNames.contains(relationName)) {
448:                                throw new DeploymentException(
449:                                        "ejb-relation-name must "
450:                                                + "be unique in ejb-jar.xml file: ejb-relation-name is "
451:                                                + relationName);
452:                            }
453:                            relationNames.add(relationName);
454:                        }
455:
456:                        relationships.add(relationMetaData);
457:                    }
458:                }
459:
460:                // read the assembly descriptor (optional)
461:                Element descrElement = getOptionalChild(element,
462:                        "assembly-descriptor");
463:                if (descrElement != null) {
464:                    // set the security roles (optional)
465:                    iterator = getChildrenByTagName(descrElement,
466:                            "security-role");
467:                    while (iterator.hasNext()) {
468:                        Element securityRole = (Element) iterator.next();
469:                        try {
470:                            String roleName = getElementContent(getUniqueChild(
471:                                    securityRole, "role-name"));
472:                            SecurityRoleMetaData srMetaData = new SecurityRoleMetaData(
473:                                    roleName);
474:                            assemblyDescriptor
475:                                    .addSecurityRoleMetaData(srMetaData);
476:                        } catch (DeploymentException e) {
477:                            throw new DeploymentException(
478:                                    "Error in ejb-jar.xml "
479:                                            + "for security-role: "
480:                                            + e.getMessage());
481:                        }
482:                    }
483:
484:                    // set the method permissions (optional)
485:                    iterator = getChildrenByTagName(descrElement,
486:                            "method-permission");
487:                    try {
488:                        while (iterator.hasNext()) {
489:                            Element methodPermission = (Element) iterator
490:                                    .next();
491:                            // Look for the unchecked element
492:                            Element unchecked = getOptionalChild(
493:                                    methodPermission, "unchecked");
494:
495:                            boolean isUnchecked = false;
496:                            Set roles = null;
497:                            if (unchecked != null) {
498:                                isUnchecked = true;
499:                            } else {
500:                                // Get the role-name elements
501:                                roles = new HashSet();
502:                                Iterator rolesIterator = getChildrenByTagName(
503:                                        methodPermission, "role-name");
504:                                while (rolesIterator.hasNext()) {
505:                                    roles
506:                                            .add(getElementContent((Element) rolesIterator
507:                                                    .next()));
508:                                }
509:                                if (roles.size() == 0)
510:                                    throw new DeploymentException(
511:                                            "An unchecked "
512:                                                    + "element or one or more role-name elements "
513:                                                    + "must be specified in method-permission");
514:                            }
515:
516:                            // find the methods
517:                            Iterator methods = getChildrenByTagName(
518:                                    methodPermission, "method");
519:                            while (methods.hasNext()) {
520:                                // load the method
521:                                MethodMetaData method = new MethodMetaData();
522:                                method
523:                                        .importEjbJarXml((Element) methods
524:                                                .next());
525:                                if (isUnchecked) {
526:                                    method.setUnchecked();
527:                                } else {
528:                                    method.setRoles(roles);
529:                                }
530:
531:                                // give the method to the right bean
532:                                BeanMetaData bean = getBeanByEjbName(method
533:                                        .getEjbName());
534:                                if (bean == null) {
535:                                    throw new DeploymentException(method
536:                                            .getEjbName()
537:                                            + " doesn't exist");
538:                                }
539:                                bean.addPermissionMethod(method);
540:                            }
541:                        }
542:                    } catch (DeploymentException e) {
543:                        throw new DeploymentException("Error in ejb-jar.xml, "
544:                                + "in method-permission: " + e.getMessage());
545:                    }
546:
547:                    // set the container transactions (optional)
548:                    iterator = getChildrenByTagName(descrElement,
549:                            "container-transaction");
550:                    try {
551:                        while (iterator.hasNext()) {
552:                            Element containerTransaction = (Element) iterator
553:                                    .next();
554:
555:                            // find the type of the transaction
556:                            byte transactionType;
557:                            String type = getElementContent(getUniqueChild(
558:                                    containerTransaction, "trans-attribute"));
559:
560:                            if (type.equalsIgnoreCase("NotSupported")
561:                                    || type.equalsIgnoreCase("Not_Supported")) {
562:                                transactionType = TX_NOT_SUPPORTED;
563:                            } else if (type.equalsIgnoreCase("Supports")) {
564:                                transactionType = TX_SUPPORTS;
565:                            } else if (type.equalsIgnoreCase("Required")) {
566:                                transactionType = TX_REQUIRED;
567:                            } else if (type.equalsIgnoreCase("RequiresNew")
568:                                    || type.equalsIgnoreCase("Requires_New")) {
569:                                transactionType = TX_REQUIRES_NEW;
570:                            } else if (type.equalsIgnoreCase("Mandatory")) {
571:                                transactionType = TX_MANDATORY;
572:                            } else if (type.equalsIgnoreCase("Never")) {
573:                                transactionType = TX_NEVER;
574:                            } else {
575:                                throw new DeploymentException("invalid "
576:                                        + "<transaction-attribute> : " + type);
577:                            }
578:
579:                            // find the methods
580:                            Iterator methods = getChildrenByTagName(
581:                                    containerTransaction, "method");
582:                            while (methods.hasNext()) {
583:                                // load the method
584:                                MethodMetaData method = new MethodMetaData();
585:                                method
586:                                        .importEjbJarXml((Element) methods
587:                                                .next());
588:                                method.setTransactionType(transactionType);
589:
590:                                // give the method to the right bean
591:                                BeanMetaData bean = getBeanByEjbName(method
592:                                        .getEjbName());
593:                                if (bean == null) {
594:                                    throw new DeploymentException("bean "
595:                                            + method.getEjbName()
596:                                            + " doesn't exist");
597:                                }
598:                                bean.addTransactionMethod(method);
599:                            }
600:                        }
601:                    } catch (DeploymentException e) {
602:                        throw new DeploymentException("Error in ejb-jar.xml, "
603:                                + "in <container-transaction>: "
604:                                + e.getMessage());
605:                    }
606:
607:                    // Get the exclude-list methods
608:                    Element excludeList = getOptionalChild(descrElement,
609:                            "exclude-list");
610:                    if (excludeList != null) {
611:                        iterator = getChildrenByTagName(excludeList, "method");
612:                        while (iterator.hasNext()) {
613:                            Element methodInf = (Element) iterator.next();
614:                            // load the method
615:                            MethodMetaData method = new MethodMetaData();
616:                            method.importEjbJarXml(methodInf);
617:                            method.setExcluded();
618:
619:                            // give the method to the right bean
620:                            BeanMetaData bean = getBeanByEjbName(method
621:                                    .getEjbName());
622:                            if (bean == null) {
623:                                throw new DeploymentException("bean "
624:                                        + method.getEjbName()
625:                                        + " doesn't exist");
626:                            }
627:                            bean.addExcludedMethod(method);
628:                        }
629:                    }
630:
631:                    // set the message destinations (optional)
632:                    iterator = getChildrenByTagName(descrElement,
633:                            "message-destination");
634:                    while (iterator.hasNext()) {
635:                        Element messageDestination = (Element) iterator.next();
636:                        try {
637:                            MessageDestinationMetaData messageDestinationMetaData = new MessageDestinationMetaData();
638:                            messageDestinationMetaData
639:                                    .importEjbJarXml(messageDestination);
640:                            assemblyDescriptor
641:                                    .addMessageDestinationMetaData(messageDestinationMetaData);
642:                        } catch (Throwable t) {
643:                            throw new DeploymentException(
644:                                    "Error in ejb-jar.xml "
645:                                            + "for message destination: "
646:                                            + t.getMessage());
647:                        }
648:                    }
649:                }
650:            }
651:
652:            public void importJbossXml(Element element)
653:                    throws DeploymentException {
654:                Iterator iterator;
655:
656:                // all the tags are optional
657:
658:                // Get the enforce-ejb-restrictions
659:                Element enforce = getOptionalChild(element,
660:                        "enforce-ejb-restrictions");
661:                if (enforce != null) {
662:                    String tmp = getElementContent(enforce);
663:                    enforceEjbRestrictions = Boolean.valueOf(tmp)
664:                            .booleanValue();
665:                }
666:
667:                // Get any user defined JMX name
668:                Element jmxNameElement = getOptionalChild(element, "jmx-name");
669:                if (jmxNameElement != null) {
670:                    jmxName = getElementContent(jmxNameElement);
671:                }
672:
673:                // Throw an exception when marked rollback with no exception thrown
674:                exceptionRollback = MetaData.getOptionalChildBooleanContent(
675:                        element, "exception-on-rollback", false);
676:
677:                // Get the security domain name
678:                Element securityDomainElement = getOptionalChild(element,
679:                        "security-domain");
680:                if (securityDomainElement != null) {
681:                    securityDomain = getElementContent(securityDomainElement);
682:                }
683:
684:                // Get the missing-method-permissions-excluded-mode flag
685:                excludeMissingMethods = MetaData
686:                        .getOptionalChildBooleanContent(element,
687:                                "missing-method-permissions-excluded-mode",
688:                                true);
689:
690:                // Get the unauthenticated-principal name
691:                Element unauth = getOptionalChild(element,
692:                        "unauthenticated-principal");
693:                if (unauth != null) {
694:                    unauthenticatedPrincipal = getElementContent(unauth);
695:                } else {
696:                    try {
697:                        MBeanServer server = MBeanServerLocator.locateJBoss();
698:                        ObjectName oname = new ObjectName(
699:                                "jboss.security:service=JaasSecurityManager");
700:                        unauthenticatedPrincipal = (String) server
701:                                .getAttribute(oname,
702:                                        "DefaultUnauthenticatedPrincipal");
703:                    } catch (Exception e) {
704:                        log.error("Cannot obtain unauthenticated principal");
705:                    }
706:                }
707:
708:                // find the invoker configurations
709:                Element invokerConfs = getOptionalChild(element,
710:                        "invoker-proxy-bindings");
711:                if (invokerConfs != null) {
712:                    iterator = getChildrenByTagName(invokerConfs,
713:                            "invoker-proxy-binding");
714:
715:                    while (iterator.hasNext()) {
716:                        Element invoker = (Element) iterator.next();
717:                        String invokerName = getElementContent(getUniqueChild(
718:                                invoker, "name"));
719:
720:                        // find the configuration if it has already been defined
721:                        // (allow jboss.xml to modify a standard conf)
722:                        InvokerProxyBindingMetaData invokerMetaData = getInvokerProxyBindingMetaDataByName(invokerName);
723:
724:                        // create it if necessary
725:                        if (invokerMetaData == null) {
726:                            invokerMetaData = new InvokerProxyBindingMetaData(
727:                                    invokerName);
728:                            invokerBindings.put(invokerName, invokerMetaData);
729:                        }
730:
731:                        try {
732:                            invokerMetaData.importJbossXml(invoker);
733:                        } catch (DeploymentException e) {
734:                            throw new DeploymentException("Error in jboss.xml "
735:                                    + "for invoker-proxy-binding "
736:                                    + invokerMetaData.getName() + ": "
737:                                    + e.getMessage());
738:                        }
739:                    }
740:                }
741:
742:                // find the container configurations (we need them first to use
743:                // them in the beans)
744:                Element confs = getOptionalChild(element,
745:                        "container-configurations");
746:                if (confs != null) {
747:                    iterator = getChildrenByTagName(confs,
748:                            "container-configuration");
749:
750:                    while (iterator.hasNext()) {
751:                        Element conf = (Element) iterator.next();
752:                        String confName = getElementContent(getUniqueChild(
753:                                conf, "container-name"));
754:                        String parentConfName = conf.getAttribute("extends");
755:                        if (parentConfName != null
756:                                && parentConfName.trim().length() == 0) {
757:                            parentConfName = null;
758:                        }
759:
760:                        // Allow the configuration to inherit from a standard
761:                        // configuration. This is determined by looking for a
762:                        // configuration matching the name given by the extends
763:                        // attribute, or if extends was not specified, an
764:                        // existing configuration with the same.
765:                        ConfigurationMetaData configurationMetaData = null;
766:                        if (parentConfName != null) {
767:                            configurationMetaData = getConfigurationMetaDataByName(parentConfName);
768:                            if (configurationMetaData == null) {
769:                                throw new DeploymentException("Failed to find "
770:                                        + "parent config=" + parentConfName);
771:                            }
772:
773:                            // Make a copy of the existing configuration
774:                            configurationMetaData = (ConfigurationMetaData) configurationMetaData
775:                                    .clone();
776:                            configurations.put(confName, configurationMetaData);
777:                        }
778:
779:                        if (configurationMetaData == null) {
780:                            configurationMetaData = getConfigurationMetaDataByName(confName);
781:                        }
782:
783:                        // Create a new configuration if none was found
784:                        if (configurationMetaData == null) {
785:                            configurationMetaData = new ConfigurationMetaData(
786:                                    confName);
787:                            configurations.put(confName, configurationMetaData);
788:                        }
789:
790:                        try {
791:                            configurationMetaData.importJbossXml(conf);
792:                        } catch (DeploymentException e) {
793:                            throw new DeploymentException("Error in jboss.xml "
794:                                    + "for container-configuration "
795:                                    + configurationMetaData.getName() + ": "
796:                                    + e.getMessage());
797:                        }
798:                    }
799:                }
800:
801:                // webservice meta data that are common to all EJB endpoints
802:                Element webservices = getOptionalChild(element, "webservices");
803:                if (webservices != null) {
804:                    // <context-root>
805:                    Element contextRoot = getOptionalChild(webservices,
806:                            "context-root");
807:                    if (contextRoot != null) {
808:                        webServiceContextRoot = getElementContent(contextRoot);
809:                        if (webServiceContextRoot.charAt(0) != '/')
810:                            webServiceContextRoot = "/" + webServiceContextRoot;
811:                    }
812:
813:                    // <webservice-description>
814:                    iterator = getChildrenByTagName(webservices,
815:                            "webservice-description");
816:                    while (iterator.hasNext()) {
817:                        Element wsd = (Element) iterator.next();
818:                        String wsdName = getElementContent(getUniqueChild(wsd,
819:                                "webservice-description-name"));
820:                        configName = MetaData.getOptionalChildContent(wsd,
821:                                "config-name");
822:                        configFile = MetaData.getOptionalChildContent(wsd,
823:                                "config-file");
824:                        String wsdlPublishLocation = getOptionalChildContent(
825:                                wsd, "wsdl-publish-location");
826:                        wsdlPublishLocationMap
827:                                .put(wsdName, wsdlPublishLocation);
828:                    }
829:                }
830:
831:                // update the enterprise beans
832:                Element entBeans = getOptionalChild(element, "enterprise-beans");
833:                if (entBeans != null) {
834:                    String ejbName = null;
835:                    try {
836:                        // Entity Beans
837:                        iterator = getChildrenByTagName(entBeans, "entity");
838:                        while (iterator.hasNext()) {
839:                            Element bean = (Element) iterator.next();
840:                            ejbName = getElementContent(getUniqueChild(bean,
841:                                    "ejb-name"));
842:                            BeanMetaData beanMetaData = getBeanByEjbName(ejbName);
843:                            if (beanMetaData == null) {
844:                                throw new DeploymentException(
845:                                        "found in jboss.xml "
846:                                                + "but not in ejb-jar.xml");
847:                            }
848:                            beanMetaData.importJbossXml(bean);
849:                        }
850:
851:                        // Session Beans
852:                        iterator = getChildrenByTagName(entBeans, "session");
853:                        while (iterator.hasNext()) {
854:                            Element bean = (Element) iterator.next();
855:                            ejbName = getElementContent(getUniqueChild(bean,
856:                                    "ejb-name"));
857:                            BeanMetaData beanMetaData = getBeanByEjbName(ejbName);
858:                            if (beanMetaData == null) {
859:                                throw new DeploymentException(
860:                                        "found in jboss.xml "
861:                                                + "but not in ejb-jar.xml");
862:                            }
863:                            beanMetaData.importJbossXml(bean);
864:                        }
865:
866:                        // Message Driven Beans
867:                        iterator = getChildrenByTagName(entBeans,
868:                                "message-driven");
869:                        while (iterator.hasNext()) {
870:                            Element bean = (Element) iterator.next();
871:                            ejbName = getElementContent(getUniqueChild(bean,
872:                                    "ejb-name"));
873:                            BeanMetaData beanMetaData = getBeanByEjbName(ejbName);
874:                            if (beanMetaData == null) {
875:                                throw new DeploymentException(
876:                                        "found in jboss.xml "
877:                                                + "but not in ejb-jar.xml");
878:                            }
879:                            beanMetaData.importJbossXml(bean);
880:                        }
881:                    } catch (DeploymentException e) {
882:                        throw new DeploymentException("Error in jboss.xml for "
883:                                + "Bean " + ejbName + ": " + e.getMessage());
884:                    }
885:                }
886:
887:                // read the assembly descriptor (optional)
888:                Element descrElement = getOptionalChild(element,
889:                        "assembly-descriptor");
890:                if (descrElement != null) {
891:                    // set the security roles (optional)
892:                    iterator = getChildrenByTagName(descrElement,
893:                            "security-role");
894:                    while (iterator.hasNext()) {
895:                        Element securityRole = (Element) iterator.next();
896:                        String roleName = getElementContent(getUniqueChild(
897:                                securityRole, "role-name"));
898:                        SecurityRoleMetaData securityRoleMetaData = assemblyDescriptor
899:                                .getSecurityRoleByName(roleName);
900:                        if (securityRoleMetaData == null) {
901:                            // Create a new SecurityRoleMetaData
902:                            securityRoleMetaData = new SecurityRoleMetaData(
903:                                    roleName);
904:                            assemblyDescriptor
905:                                    .addSecurityRoleMetaData(securityRoleMetaData);
906:                        }
907:
908:                        Iterator itPrincipalNames = getChildrenByTagName(
909:                                securityRole, "principal-name");
910:                        while (itPrincipalNames.hasNext()) {
911:                            String principalName = getElementContent((Element) itPrincipalNames
912:                                    .next());
913:                            securityRoleMetaData
914:                                    .addPrincipalName(principalName);
915:                        }
916:                    }
917:
918:                    // set the message destinations (optional)
919:                    iterator = getChildrenByTagName(descrElement,
920:                            "message-destination");
921:                    while (iterator.hasNext()) {
922:                        Element messageDestination = (Element) iterator.next();
923:                        try {
924:                            String messageDestinationName = getUniqueChildContent(
925:                                    messageDestination,
926:                                    "message-destination-name");
927:                            MessageDestinationMetaData messageDestinationMetaData = getMessageDestination(messageDestinationName);
928:                            if (messageDestinationMetaData == null)
929:                                throw new DeploymentException(
930:                                        "message-destination "
931:                                                + messageDestinationName
932:                                                + " found in jboss.xml but not in ejb-jar.xml");
933:                            messageDestinationMetaData
934:                                    .importJbossXml(messageDestination);
935:                        } catch (Throwable t) {
936:                            throw new DeploymentException(
937:                                    "Error in ejb-jar.xml "
938:                                            + "for message destination: "
939:                                            + t.getMessage());
940:                        }
941:                    }
942:                }
943:
944:                // set the resource managers
945:                Element resmans = getOptionalChild(element, "resource-managers");
946:                if (resmans != null) {
947:                    iterator = getChildrenByTagName(resmans, "resource-manager");
948:                    try {
949:                        while (iterator.hasNext()) {
950:                            Element resourceManager = (Element) iterator.next();
951:                            String resName = getElementContent(getUniqueChild(
952:                                    resourceManager, "res-name"));
953:
954:                            String jndi = getElementContent(getOptionalChild(
955:                                    resourceManager, "res-jndi-name"));
956:
957:                            String url = getElementContent(getOptionalChild(
958:                                    resourceManager, "res-url"));
959:
960:                            if (jndi != null && url == null) {
961:                                resources.put(resName, jndi);
962:                            } else if (jndi == null && url != null) {
963:                                resources.put(resName, url);
964:                            } else {
965:                                throw new DeploymentException(
966:                                        resName
967:                                                + " : expected res-url or res-jndi-name tag");
968:                            }
969:                        }
970:                    } catch (DeploymentException e) {
971:                        throw new DeploymentException("Error in jboss.xml, in "
972:                                + "resource-manager: " + e.getMessage());
973:                    }
974:                }
975:            }
976:
977:        }
978:
979:        /*
980:         vim:ts=3:sw=3:et
981:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.