Source Code Cross Referenced for BeanMetaData.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) 


0001:        /*
0002:         * JBoss, Home of Professional Open Source.
0003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
0004:         * as indicated by the @author tags. See the copyright.txt file in the
0005:         * distribution for a full listing of individual contributors.
0006:         *
0007:         * This is free software; you can redistribute it and/or modify it
0008:         * under the terms of the GNU Lesser General Public License as
0009:         * published by the Free Software Foundation; either version 2.1 of
0010:         * the License, or (at your option) any later version.
0011:         *
0012:         * This software is distributed in the hope that it will be useful,
0013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015:         * Lesser General Public License for more details.
0016:         *
0017:         * You should have received a copy of the GNU Lesser General Public
0018:         * License along with this software; if not, write to the Free
0019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
0021:         */
0022:        package org.jboss.metadata;
0023:
0024:        import java.lang.reflect.Method;
0025:        import java.util.ArrayList;
0026:        import java.util.Collection;
0027:        import java.util.HashMap;
0028:        import java.util.HashSet;
0029:        import java.util.Iterator;
0030:        import java.util.LinkedList;
0031:        import java.util.Set;
0032:
0033:        import org.jboss.deployment.DeploymentException;
0034:        import org.jboss.invocation.InvocationType;
0035:        import org.jboss.metadata.serviceref.ServiceRefDelegate;
0036:        import org.jboss.mx.util.ObjectNameFactory;
0037:        import org.jboss.security.AnybodyPrincipal;
0038:        import org.jboss.security.NobodyPrincipal;
0039:        import org.jboss.security.SimplePrincipal;
0040:        import org.jboss.ws.integration.ServiceRefMetaData;
0041:        import org.w3c.dom.Element;
0042:
0043:        import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
0044:
0045:        /**
0046:         * A common meta data class for the entity, message-driven and session beans.
0047:         *
0048:         * @author <a href="mailto:sebastien.alborini@m4x.org">Sebastien Alborini</a>
0049:         * @author <a href="mailto:peter.antman@tim.se">Peter Antman</a>
0050:         * @author <a href="mailto:docodan@mvcsoft.com">Daniel OConnor</a>
0051:         * @author <a href="mailto:Scott.Stark@jboss.org">Scott Stark</a>
0052:         * @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
0053:         * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
0054:         * @author <a href="mailto:criege@riege.com">Christian Riege</a>
0055:         * @author <a href="mailto:Thomas.Diesler@jboss.org">Thomas Diesler</a>
0056:         * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
0057:         *
0058:         * @version $Revision: 61248 $
0059:         */
0060:        public abstract class BeanMetaData extends MetaData {
0061:            // Constants -----------------------------------------------------
0062:
0063:            public static final char SESSION_TYPE = 'S';
0064:            public static final char ENTITY_TYPE = 'E';
0065:            public static final char MDB_TYPE = 'M';
0066:            public static final String LOCAL_INVOKER_PROXY_BINDING = "LOCAL";
0067:
0068:            // Attributes ----------------------------------------------------
0069:            /** The metadata from the toplevel ejb-jar.xml/jboss.xml elements */
0070:            private ApplicationMetaData application;
0071:
0072:            // from ejb-jar.xml
0073:            /** The ejb-name element specifies an enterprise bean's name. This name is
0074:             assigned by the ejb-jar file producer to name the enterprise bean in
0075:             the ejb-jar file's deployment descriptor. The name must be unique
0076:             among the names of the enterprise beans in the same ejb-jar file.
0077:             */
0078:            private String ejbName;
0079:            /** The home element contains the fully-qualified name of the enterprise
0080:             bean's home interface. */
0081:            private String homeClass;
0082:            /** The remote element contains the fully-qualified name of the enterprise
0083:             bean's remote interface. */
0084:            private String remoteClass;
0085:            /** The local-home element contains the fully-qualified name of the
0086:             enterprise bean's local home interface. */
0087:            private String localHomeClass;
0088:            /** The local element contains the fully-qualified name of the enterprise
0089:             bean's local interface */
0090:            private String localClass;
0091:            /** The service-endpoint element contains the fully-qualified
0092:             *  name of the bean�s service endpoint interface (SEI) */
0093:            protected String serviceEndpointClass;
0094:            /** The ejb-class element contains the fully-qualified name of the
0095:             enterprise bean's class. */
0096:            private String ejbClass;
0097:            /** The type of bean: ENTITY_TYPE, SESSION_TYPE, MDB_TYPE */
0098:            protected char beanType;
0099:            /** Is this bean's transactions managed by the container? */
0100:            protected boolean containerManagedTx = true;
0101:
0102:            /** The The env-entry element(s) contains the declaration of an enterprise
0103:             bean's environment entry */
0104:            private ArrayList environmentEntries = new ArrayList();
0105:            /** The The ejb-ref element(s) for the declaration of a reference to an
0106:             enterprise bean's home */
0107:            private HashMap ejbReferences = new HashMap();
0108:            /** The ejb-local-ref element(s) info */
0109:            private HashMap ejbLocalReferences = new HashMap();
0110:            /** The HashMap<ServiceRefMetaData> service-ref element(s) info */
0111:            private HashMap<String, ServiceRefMetaData> serviceReferences = new HashMap<String, ServiceRefMetaData>();
0112:            /** The security-role-ref element(s) info */
0113:            private ArrayList securityRoleReferences = new ArrayList();
0114:            /** The security-idemtity element info */
0115:            private SecurityIdentityMetaData securityIdentity = null;
0116:            /** */
0117:            private SecurityIdentityMetaData ejbTimeoutIdentity = null;
0118:            /** The resource-ref element(s) info */
0119:            private HashMap resourceReferences = new HashMap();
0120:            /** The resource-env-ref element(s) info */
0121:            private HashMap resourceEnvReferences = new HashMap();
0122:            /** The message destination references */
0123:            private HashMap messageDestinationReferences = new HashMap();
0124:            /** The method attributes */
0125:            private ArrayList methodAttributes = new ArrayList();
0126:            private ConcurrentReaderHashMap cachedMethodAttributes = new ConcurrentReaderHashMap();
0127:            /** The assembly-descriptor/method-permission element(s) info */
0128:            private ArrayList permissionMethods = new ArrayList();
0129:            /** The assembly-descriptor/container-transaction element(s) info */
0130:            private ArrayList transactionMethods = new ArrayList();
0131:            /** A cache mapping methods to transaction attributes. */
0132:            private ConcurrentReaderHashMap methodTx = new ConcurrentReaderHashMap();
0133:            /** The assembly-descriptor/exclude-list method(s) */
0134:            private ArrayList excludedMethods = new ArrayList();
0135:            /** The invoker names to JNDI name mapping */
0136:            protected HashMap invokerBindings = null;
0137:            /** The cluster-config element info */
0138:            private ClusterConfigMetaData clusterConfig = null;
0139:
0140:            /** The JNDI name under with the home interface should be bound */
0141:            private String jndiName;
0142:
0143:            /** The JNDI name under with the local home interface should be bound */
0144:            private String localJndiName;
0145:            /** The container configuration name */
0146:            protected String configurationName;
0147:            /** The container configuration metadata */
0148:            private ConfigurationMetaData configuration;
0149:            /** The custom security proxy class */
0150:            private String securityProxy;
0151:
0152:            /** Is the bean marked as clustered */
0153:            protected boolean clustered = false;
0154:            /** Should the bean use by value call semeantics */
0155:            protected boolean callByValue = false;
0156:            /** Any object names for services the bean depends on */
0157:            private Collection depends = new LinkedList();
0158:
0159:            /** Describes the security configuration information for the IOR. Optional element. Since 4.0. */
0160:            private IorSecurityConfigMetaData iorSecurityConfig;
0161:            /** The jboss port-component binding for a ejb webservice */
0162:            protected EjbPortComponentMetaData portComponent;
0163:            /** Whether to throw an exception on a rollback if there is no exception */
0164:            private boolean exceptionRollback = false;
0165:            /** Whether timer persistence is enabled */
0166:            private boolean timerPersistence = true;
0167:
0168:            // Static --------------------------------------------------------
0169:
0170:            // Constructors --------------------------------------------------
0171:            public BeanMetaData(ApplicationMetaData app, char beanType) {
0172:                this .application = app;
0173:                this .beanType = beanType;
0174:            }
0175:
0176:            public boolean isSession() {
0177:                return beanType == SESSION_TYPE;
0178:            }
0179:
0180:            public boolean isMessageDriven() {
0181:                return beanType == MDB_TYPE;
0182:            }
0183:
0184:            public boolean isEntity() {
0185:                return beanType == ENTITY_TYPE;
0186:            }
0187:
0188:            public String getHome() {
0189:                return homeClass;
0190:            }
0191:
0192:            public String getRemote() {
0193:                return remoteClass;
0194:            }
0195:
0196:            public String getLocalHome() {
0197:                return localHomeClass;
0198:            }
0199:
0200:            public String getLocal() {
0201:                return localClass;
0202:            }
0203:
0204:            public String getServiceEndpoint() {
0205:                return serviceEndpointClass;
0206:            }
0207:
0208:            public EjbPortComponentMetaData getPortComponent() {
0209:                return portComponent;
0210:            }
0211:
0212:            public String getEjbClass() {
0213:                return ejbClass;
0214:            }
0215:
0216:            public String getEjbName() {
0217:                return ejbName;
0218:            }
0219:
0220:            public boolean isContainerManagedTx() {
0221:                return containerManagedTx;
0222:            }
0223:
0224:            public boolean isBeanManagedTx() {
0225:                return !containerManagedTx;
0226:            }
0227:
0228:            public Iterator getEjbReferences() {
0229:                return ejbReferences.values().iterator();
0230:            }
0231:
0232:            public Iterator getEjbLocalReferences() {
0233:                return ejbLocalReferences.values().iterator();
0234:            }
0235:
0236:            protected abstract void defaultInvokerBindings();
0237:
0238:            public Iterator getInvokerBindings() {
0239:                if (invokerBindings == null) {
0240:                    // See if there is a container default invoker name
0241:                    String[] defaultNames = configuration.getInvokers();
0242:                    if (defaultNames.length > 0) {
0243:                        invokerBindings = new HashMap();
0244:                        for (int count = 0; count < defaultNames.length; count++) {
0245:                            invokerBindings.put(defaultNames[count],
0246:                                    getJndiName());
0247:                        }
0248:                    } else {
0249:                        // Use the hard-coded defaults
0250:                        defaultInvokerBindings();
0251:                    }
0252:                }
0253:
0254:                return invokerBindings.keySet().iterator();
0255:            }
0256:
0257:            public String getInvokerBinding(String invokerName) {
0258:                if (invokerBindings == null) {
0259:                    defaultInvokerBindings();
0260:                }
0261:
0262:                return (String) invokerBindings.get(invokerName);
0263:            }
0264:
0265:            public EjbRefMetaData getEjbRefByName(String name) {
0266:                return (EjbRefMetaData) ejbReferences.get(name);
0267:            }
0268:
0269:            public EjbLocalRefMetaData getEjbLocalRefByName(String name) {
0270:                return (EjbLocalRefMetaData) ejbLocalReferences.get(name);
0271:            }
0272:
0273:            public Iterator getEnvironmentEntries() {
0274:                return environmentEntries.iterator();
0275:            }
0276:
0277:            public Iterator getSecurityRoleReferences() {
0278:                return securityRoleReferences.iterator();
0279:            }
0280:
0281:            public Iterator getResourceReferences() {
0282:                return resourceReferences.values().iterator();
0283:            }
0284:
0285:            public Iterator getResourceEnvReferences() {
0286:                return resourceEnvReferences.values().iterator();
0287:            }
0288:
0289:            public Iterator getMessageDestinationReferences() {
0290:                return messageDestinationReferences.values().iterator();
0291:            }
0292:
0293:            /**
0294:             * @return HashMap<ServiceRefMetaData>
0295:             */
0296:            public HashMap<String, ServiceRefMetaData> getServiceReferences() {
0297:                return serviceReferences;
0298:            }
0299:
0300:            public String getJndiName() {
0301:                // jndiName may be set in jboss.xml
0302:                if (jndiName == null) {
0303:                    jndiName = ejbName;
0304:                }
0305:                return jndiName;
0306:            }
0307:
0308:            /**
0309:             * Gets the JNDI name under with the local home interface should be bound.
0310:             * The default is local/&lt;ejbName&gt;
0311:             */
0312:            public String getLocalJndiName() {
0313:                if (localJndiName == null) {
0314:                    // Generate a unique name based on ejbName + identityHashCode
0315:                    localJndiName = "local/" + ejbName + '@'
0316:                            + System.identityHashCode(ejbName);
0317:                }
0318:                return localJndiName;
0319:            }
0320:
0321:            /**
0322:             * Gets the container jndi name used in the object name
0323:             */
0324:            public String getContainerObjectNameJndiName() {
0325:                return getHome() != null ? getJndiName() : getLocalJndiName();
0326:            }
0327:
0328:            public String getConfigurationName() {
0329:                if (configurationName == null) {
0330:                    configurationName = getDefaultConfigurationName();
0331:                }
0332:                return configurationName;
0333:            }
0334:
0335:            public ConfigurationMetaData getContainerConfiguration() {
0336:                if (configuration == null) {
0337:                    String configName = getConfigurationName();
0338:                    configuration = application
0339:                            .getConfigurationMetaDataByName(configName);
0340:                    if (configuration == null)
0341:                        throw new IllegalStateException(
0342:                                "Container config not found " + configName);
0343:                }
0344:                return configuration;
0345:            }
0346:
0347:            public String getSecurityProxy() {
0348:                return securityProxy;
0349:            }
0350:
0351:            public SecurityIdentityMetaData getSecurityIdentityMetaData() {
0352:                return securityIdentity;
0353:            }
0354:
0355:            public SecurityIdentityMetaData getEjbTimeoutIdentity() {
0356:                return ejbTimeoutIdentity;
0357:            }
0358:
0359:            public ApplicationMetaData getApplicationMetaData() {
0360:                return application;
0361:            }
0362:
0363:            public abstract String getDefaultConfigurationName();
0364:
0365:            public Iterator getTransactionMethods() {
0366:                return transactionMethods.iterator();
0367:            }
0368:
0369:            public Iterator getPermissionMethods() {
0370:                return permissionMethods.iterator();
0371:            }
0372:
0373:            public Iterator getExcludedMethods() {
0374:                return excludedMethods.iterator();
0375:            }
0376:
0377:            public void addTransactionMethod(MethodMetaData method) {
0378:                transactionMethods.add(method);
0379:            }
0380:
0381:            public void addPermissionMethod(MethodMetaData method) {
0382:                // Insert unchecked methods into the front of the list to speed
0383:                // up their validation
0384:                if (method.isUnchecked()) {
0385:                    permissionMethods.add(0, method);
0386:                } else {
0387:                    permissionMethods.add(method);
0388:                }
0389:            }
0390:
0391:            public void addExcludedMethod(MethodMetaData method) {
0392:                excludedMethods.add(method);
0393:            }
0394:
0395:            public byte getMethodTransactionType(String methodName,
0396:                    Class[] params, InvocationType iface) {
0397:                // default value
0398:                byte result = TX_UNKNOWN;
0399:
0400:                MethodMetaData bestMatch = null;
0401:                Iterator iterator = getTransactionMethods();
0402:                while (iterator.hasNext()) {
0403:                    MethodMetaData m = (MethodMetaData) iterator.next();
0404:                    if (m.patternMatches(methodName, params, iface)) {
0405:
0406:                        // this is the first match
0407:                        if (bestMatch == null) {
0408:                            bestMatch = m;
0409:                        } else {
0410:                            // this is a better match because the name is more precise
0411:                            if (bestMatch.getMethodName().equals("*")) {
0412:                                bestMatch = m;
0413:                            }
0414:                            // this is a better match because now we have parameters, we cant get any better
0415:                            if (m.getMethodParams().length > 0) {
0416:                                bestMatch = m;
0417:                                break;
0418:                            }
0419:                        }
0420:                    }
0421:                }
0422:
0423:                if (bestMatch != null) {
0424:                    result = bestMatch.getTransactionType();
0425:                }
0426:
0427:                return result;
0428:            }
0429:
0430:            // This should be cached, since this method is called very often
0431:            public byte getTransactionMethod(Method m, InvocationType iface) {
0432:                if (m == null)
0433:                    return MetaData.TX_SUPPORTS;
0434:
0435:                Byte b = (Byte) methodTx.get(m);
0436:                if (b != null)
0437:                    return b.byteValue();
0438:
0439:                byte result = getMethodTransactionType(m.getName(), m
0440:                        .getParameterTypes(), iface);
0441:
0442:                // provide default if method is not found in descriptor
0443:                if (result == MetaData.TX_UNKNOWN)
0444:                    result = MetaData.TX_REQUIRED;
0445:
0446:                methodTx.put(m, new Byte(result));
0447:                return result;
0448:            }
0449:
0450:            public Collection getDepends() {
0451:                Collection allDepends = new LinkedList(depends);
0452:                allDepends.addAll(getContainerConfiguration().getDepends());
0453:                return allDepends;
0454:            }
0455:
0456:            /**
0457:             * Checks meta data to obtain the Method Attributes of a bean's method:
0458:             * method attributes are read-only, idempotent and potentially other
0459:             * ones as well.
0460:             * These jboss-specific method attributes are described in jboss.xml
0461:             */
0462:            private MethodAttributes methodAttributesForMethod(String methodName) {
0463:                if (methodName == null)
0464:                    methodName = "*null*";
0465:
0466:                MethodAttributes ma = (MethodAttributes) cachedMethodAttributes
0467:                        .get(methodName);
0468:
0469:                if (ma == null) {
0470:                    Iterator iterator = methodAttributes.iterator();
0471:                    while (iterator.hasNext() && ma == null) {
0472:                        ma = (MethodAttributes) iterator.next();
0473:                        if (!ma.patternMatches(methodName)) {
0474:                            ma = null;
0475:                        }
0476:                    }
0477:                    if (ma == null) {
0478:                        ma = MethodAttributes.kDefaultMethodAttributes;
0479:                    }
0480:
0481:                    cachedMethodAttributes.put(methodName, ma);
0482:                }
0483:                return ma;
0484:            }
0485:
0486:            /**
0487:             * Is this method a read-only method described in jboss.xml?
0488:             */
0489:            public boolean isMethodReadOnly(String methodName) {
0490:                return methodAttributesForMethod(methodName).readOnly;
0491:            }
0492:
0493:            public boolean isMethodReadOnly(Method method) {
0494:                if (method == null) {
0495:                    return false;
0496:                }
0497:                return methodAttributesForMethod(method.getName()).readOnly;
0498:            }
0499:
0500:            /**
0501:             * Get the transaction timeout for the method
0502:             */
0503:            public int getTransactionTimeout(String methodName) {
0504:                return methodAttributesForMethod(methodName).txTimeout;
0505:            }
0506:
0507:            public int getTransactionTimeout(Method method) {
0508:                if (method == null)
0509:                    return 0;
0510:                return getTransactionTimeout(method.getName());
0511:            }
0512:
0513:            /**
0514:             *  A somewhat tedious method that builds a Set<Principal> of the roles
0515:             *  that have been assigned permission to execute the indicated method. The
0516:             *  work performed is tedious because of the wildcard style of declaring
0517:             *  method permission allowed in the ejb-jar.xml descriptor. This method is
0518:             *  called by the Container.getMethodPermissions() when it fails to find the
0519:             *  prebuilt set of method roles in its cache.
0520:             *
0521:             *  @return The Set<Principal> for the application domain roles that
0522:             *     caller principal's are to be validated against.
0523:             */
0524:            public Set getMethodPermissions(String methodName, Class[] params,
0525:                    InvocationType iface) {
0526:                Set result = new HashSet();
0527:                // First check the excluded method list as this takes priority over
0528:                // all other assignments
0529:                Iterator iterator = getExcludedMethods();
0530:                while (iterator.hasNext()) {
0531:                    MethodMetaData m = (MethodMetaData) iterator.next();
0532:                    if (m.patternMatches(methodName, params, iface)) {
0533:                        /* No one is allowed to execute this method so add a role that
0534:                           fails to equate to any Principal or Principal name and return.
0535:                           We don't return null to differentiate between an explicit
0536:                           assignment of no access and no assignment information.
0537:                         */
0538:                        result.add(NobodyPrincipal.NOBODY_PRINCIPAL);
0539:                        return result;
0540:                    }
0541:                }
0542:
0543:                // Check the permissioned methods list
0544:                iterator = getPermissionMethods();
0545:                while (iterator.hasNext()) {
0546:                    MethodMetaData m = (MethodMetaData) iterator.next();
0547:                    if (m.patternMatches(methodName, params, iface)) {
0548:                        /* If this is an unchecked method anyone can access it so
0549:                           set the result set to a role that equates to any Principal or
0550:                           Principal name and return.
0551:                         */
0552:                        if (m.isUnchecked()) {
0553:                            result.clear();
0554:                            result.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
0555:                            break;
0556:                        }
0557:                        // Else, add all roles
0558:                        else {
0559:                            Iterator rolesIterator = m.getRoles().iterator();
0560:                            while (rolesIterator.hasNext()) {
0561:                                String roleName = (String) rolesIterator.next();
0562:                                result.add(new SimplePrincipal(roleName));
0563:                            }
0564:                        }
0565:                    }
0566:                }
0567:
0568:                if (this .isExcludeMissingMethods() == false) {
0569:                    // If no permissions were assigned to the method, anybody can access it
0570:                    if (result.isEmpty()) {
0571:                        result.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
0572:                    }
0573:                }
0574:
0575:                return result;
0576:            }
0577:
0578:            /** Check to see if there was a method-permission or exclude-list statement
0579:             * for the given method.
0580:             * 
0581:             * @param methodName - the method name
0582:             * @param params - the method parameter signature
0583:             * @param iface - the method interface type
0584:             * @return true if a matching method permission exists, false if no match
0585:             */
0586:            public boolean hasMethodPermission(String methodName,
0587:                    Class[] params, InvocationType iface) {
0588:                // First check the excluded method list as this takes priority
0589:                Iterator iterator = getExcludedMethods();
0590:                while (iterator.hasNext()) {
0591:                    MethodMetaData m = (MethodMetaData) iterator.next();
0592:                    if (m.patternMatches(methodName, params, iface)) {
0593:                        return true;
0594:                    }
0595:                }
0596:
0597:                // Check the permissioned methods list
0598:                iterator = getPermissionMethods();
0599:                while (iterator.hasNext()) {
0600:                    MethodMetaData m = (MethodMetaData) iterator.next();
0601:                    if (m.patternMatches(methodName, params, iface)) {
0602:                        return true;
0603:                    }
0604:                }
0605:
0606:                return false;
0607:            }
0608:
0609:            // Cluster configuration methods
0610:            public boolean isClustered() {
0611:                return this .clustered;
0612:            }
0613:
0614:            public boolean isCallByValue() {
0615:                return callByValue;
0616:            }
0617:
0618:            public boolean isExcludeMissingMethods() {
0619:                return application.isExcludeMissingMethods();
0620:            }
0621:
0622:            public ClusterConfigMetaData getClusterConfigMetaData() {
0623:                if (clusterConfig == null) {
0624:                    clusterConfig = getContainerConfiguration()
0625:                            .getClusterConfigMetaData();
0626:                    if (clusterConfig == null) {
0627:                        clusterConfig = new ClusterConfigMetaData();
0628:                    }
0629:                    /* All beans associated with a container are the same type
0630:                       so this can be done more than once without harm */
0631:                    clusterConfig.init(this );
0632:                }
0633:                return this .clusterConfig;
0634:            }
0635:
0636:            public IorSecurityConfigMetaData getIorSecurityConfigMetaData() {
0637:                return iorSecurityConfig;
0638:            }
0639:
0640:            public boolean getExceptionRollback() {
0641:                return exceptionRollback;
0642:            }
0643:
0644:            public boolean getTimerPersistence() {
0645:                return timerPersistence;
0646:            }
0647:
0648:            /** Called to parse the ejb-jar.xml enterprise-beans child ejb elements
0649:             * @param element one of session/entity/message-driven
0650:             * @throws DeploymentException
0651:             */
0652:            public void importEjbJarXml(Element element)
0653:                    throws DeploymentException {
0654:                // set the ejb-name
0655:                ejbName = getElementContent(getUniqueChild(element, "ejb-name"));
0656:
0657:                // Set the interfaces classes for all types but MessageDriven
0658:                if (isMessageDriven() == false) {
0659:                    homeClass = getElementContent(getOptionalChild(element,
0660:                            "home"));
0661:                    remoteClass = getElementContent(getOptionalChild(element,
0662:                            "remote"));
0663:                    localHomeClass = getElementContent(getOptionalChild(
0664:                            element, "local-home"));
0665:                    localClass = getElementContent(getOptionalChild(element,
0666:                            "local"));
0667:                }
0668:                ejbClass = getElementContent(getUniqueChild(element,
0669:                        "ejb-class"));
0670:
0671:                // set the environment entries
0672:                Iterator iterator = getChildrenByTagName(element, "env-entry");
0673:
0674:                while (iterator.hasNext()) {
0675:                    Element envEntry = (Element) iterator.next();
0676:
0677:                    EnvEntryMetaData envEntryMetaData = new EnvEntryMetaData();
0678:                    envEntryMetaData.importEjbJarXml(envEntry);
0679:
0680:                    environmentEntries.add(envEntryMetaData);
0681:                }
0682:
0683:                // set the ejb references
0684:                iterator = getChildrenByTagName(element, "ejb-ref");
0685:
0686:                while (iterator.hasNext()) {
0687:                    Element ejbRef = (Element) iterator.next();
0688:
0689:                    EjbRefMetaData ejbRefMetaData = new EjbRefMetaData();
0690:                    ejbRefMetaData.importEjbJarXml(ejbRef);
0691:
0692:                    ejbReferences.put(ejbRefMetaData.getName(), ejbRefMetaData);
0693:                }
0694:
0695:                // set the ejb local references
0696:                iterator = getChildrenByTagName(element, "ejb-local-ref");
0697:
0698:                while (iterator.hasNext()) {
0699:                    Element ejbLocalRef = (Element) iterator.next();
0700:
0701:                    EjbLocalRefMetaData ejbLocalRefMetaData = new EjbLocalRefMetaData();
0702:                    ejbLocalRefMetaData.importEjbJarXml(ejbLocalRef);
0703:
0704:                    ejbLocalReferences.put(ejbLocalRefMetaData.getName(),
0705:                            ejbLocalRefMetaData);
0706:                }
0707:
0708:                // Parse the service-ref elements
0709:                iterator = MetaData
0710:                        .getChildrenByTagName(element, "service-ref");
0711:                while (iterator.hasNext()) {
0712:                    Element serviceRef = (Element) iterator.next();
0713:                    new ServiceRefDelegate().newServiceRefMetaData();
0714:                    ServiceRefMetaData refMetaData = new ServiceRefDelegate()
0715:                            .newServiceRefMetaData();
0716:                    refMetaData.importStandardXml(serviceRef);
0717:                    serviceReferences.put(refMetaData.getServiceRefName(),
0718:                            refMetaData);
0719:                }
0720:
0721:                // set the security roles references
0722:                iterator = getChildrenByTagName(element, "security-role-ref");
0723:
0724:                while (iterator.hasNext()) {
0725:                    Element secRoleRef = (Element) iterator.next();
0726:                    SecurityRoleRefMetaData securityRoleRefMetaData = new SecurityRoleRefMetaData();
0727:                    securityRoleRefMetaData.importEjbJarXml(secRoleRef);
0728:                    securityRoleReferences.add(securityRoleRefMetaData);
0729:                }
0730:
0731:                // The security-identity element
0732:                Element securityIdentityElement = getOptionalChild(element,
0733:                        "security-identity");
0734:                if (securityIdentityElement != null) {
0735:                    securityIdentity = new SecurityIdentityMetaData();
0736:                    securityIdentity.importEjbJarXml(securityIdentityElement);
0737:                }
0738:
0739:                // set the resource references
0740:                iterator = getChildrenByTagName(element, "resource-ref");
0741:
0742:                while (iterator.hasNext()) {
0743:                    Element resourceRef = (Element) iterator.next();
0744:
0745:                    ResourceRefMetaData resourceRefMetaData = new ResourceRefMetaData();
0746:                    resourceRefMetaData.importEjbJarXml(resourceRef);
0747:
0748:                    resourceReferences.put(resourceRefMetaData.getRefName(),
0749:                            resourceRefMetaData);
0750:                }
0751:
0752:                // Parse the resource-env-ref elements
0753:                iterator = getChildrenByTagName(element, "resource-env-ref");
0754:                while (iterator.hasNext()) {
0755:                    Element resourceRef = (Element) iterator.next();
0756:                    ResourceEnvRefMetaData refMetaData = new ResourceEnvRefMetaData();
0757:                    refMetaData.importEjbJarXml(resourceRef);
0758:                    resourceEnvReferences.put(refMetaData.getRefName(),
0759:                            refMetaData);
0760:                }
0761:
0762:                // set the message destination references
0763:                iterator = getChildrenByTagName(element,
0764:                        "message-destination-ref");
0765:                while (iterator.hasNext()) {
0766:                    Element messageDestinationRef = (Element) iterator.next();
0767:
0768:                    MessageDestinationRefMetaData messageDestinationRefMetaData = new MessageDestinationRefMetaData();
0769:                    messageDestinationRefMetaData
0770:                            .importEjbJarXml(messageDestinationRef);
0771:
0772:                    messageDestinationReferences.put(
0773:                            messageDestinationRefMetaData.getRefName(),
0774:                            messageDestinationRefMetaData);
0775:                }
0776:            }
0777:
0778:            /** Called to parse the jboss.xml enterprise-beans child ejb elements
0779:             * @param element one of session/entity/message-driven
0780:             * @throws DeploymentException
0781:             */
0782:            public void importJbossXml(Element element)
0783:                    throws DeploymentException {
0784:                // we must not set defaults here, this might never be called
0785:
0786:                // set the jndi name, (optional)
0787:                jndiName = getElementContent(getOptionalChild(element,
0788:                        "jndi-name"));
0789:
0790:                // set the JNDI name under with the local home interface should be
0791:                // bound (optional)
0792:                localJndiName = getElementContent(getOptionalChild(element,
0793:                        "local-jndi-name"));
0794:
0795:                // Determine if the bean should use by value call semantics
0796:                String callByValueElt = getElementContent(getOptionalChild(
0797:                        element, "call-by-value"), (callByValue ? "True"
0798:                        : "False"));
0799:                callByValue = callByValueElt.equalsIgnoreCase("True");
0800:
0801:                // set the configuration (optional)
0802:                configurationName = getElementContent(getOptionalChild(element,
0803:                        "configuration-name"));
0804:                if (configurationName != null
0805:                        && getApplicationMetaData()
0806:                                .getConfigurationMetaDataByName(
0807:                                        configurationName) == null) {
0808:                    throw new DeploymentException("configuration '"
0809:                            + configurationName
0810:                            + "' not found in standardjboss.xml or jboss.xml");
0811:                }
0812:
0813:                // Get the security proxy
0814:                securityProxy = getElementContent(getOptionalChild(element,
0815:                        "security-proxy"), securityProxy);
0816:
0817:                // Throw an exception when marked rollback with no exception thrown
0818:                exceptionRollback = MetaData.getOptionalChildBooleanContent(
0819:                        element, "exception-on-rollback", false);
0820:
0821:                // Whether to persist ejb timers across redeployments
0822:                timerPersistence = MetaData.getOptionalChildBooleanContent(
0823:                        element, "timer-persistence", true);
0824:
0825:                // update the resource references (optional)
0826:                Iterator iterator = getChildrenByTagName(element,
0827:                        "resource-ref");
0828:                while (iterator.hasNext()) {
0829:                    Element resourceRef = (Element) iterator.next();
0830:                    String resRefName = getElementContent(getUniqueChild(
0831:                            resourceRef, "res-ref-name"));
0832:                    ResourceRefMetaData resourceRefMetaData = (ResourceRefMetaData) resourceReferences
0833:                            .get(resRefName);
0834:
0835:                    if (resourceRefMetaData == null) {
0836:                        throw new DeploymentException("resource-ref "
0837:                                + resRefName
0838:                                + " found in jboss.xml but not in ejb-jar.xml");
0839:                    }
0840:                    resourceRefMetaData.importJbossXml(resourceRef);
0841:                }
0842:
0843:                // Set the resource-env-ref deployed jndi names
0844:                iterator = getChildrenByTagName(element, "resource-env-ref");
0845:                while (iterator.hasNext()) {
0846:                    Element resourceRef = (Element) iterator.next();
0847:                    String resRefName = getElementContent(getUniqueChild(
0848:                            resourceRef, "resource-env-ref-name"));
0849:                    ResourceEnvRefMetaData refMetaData = (ResourceEnvRefMetaData) resourceEnvReferences
0850:                            .get(resRefName);
0851:                    if (refMetaData == null) {
0852:                        throw new DeploymentException("resource-env-ref "
0853:                                + resRefName
0854:                                + " found in jboss.xml but not in ejb-jar.xml");
0855:                    }
0856:                    refMetaData.importJbossXml(resourceRef);
0857:                }
0858:
0859:                // update the message destination references (optional)
0860:                iterator = getChildrenByTagName(element,
0861:                        "message-destination-ref");
0862:                while (iterator.hasNext()) {
0863:                    Element messageDestinationRef = (Element) iterator.next();
0864:                    String messageDestinationRefName = getElementContent(getUniqueChild(
0865:                            messageDestinationRef,
0866:                            "message-destination-ref-name"));
0867:                    MessageDestinationRefMetaData messageDestinationRefMetaData = (MessageDestinationRefMetaData) messageDestinationReferences
0868:                            .get(messageDestinationRefName);
0869:                    if (messageDestinationRefMetaData == null)
0870:                        throw new DeploymentException(
0871:                                "message-destination-ref "
0872:                                        + messageDestinationRefName
0873:                                        + " found in jboss.xml but not in ejb-jar.xml");
0874:                    messageDestinationRefMetaData
0875:                            .importJbossXml(messageDestinationRef);
0876:                }
0877:
0878:                // set the external ejb-references (optional)
0879:                iterator = getChildrenByTagName(element, "ejb-ref");
0880:                while (iterator.hasNext()) {
0881:                    Element ejbRef = (Element) iterator.next();
0882:                    String ejbRefName = getElementContent(getUniqueChild(
0883:                            ejbRef, "ejb-ref-name"));
0884:                    EjbRefMetaData ejbRefMetaData = getEjbRefByName(ejbRefName);
0885:                    if (ejbRefMetaData == null) {
0886:                        throw new DeploymentException("ejb-ref " + ejbRefName
0887:                                + " found in jboss.xml but not in ejb-jar.xml");
0888:                    }
0889:                    ejbRefMetaData.importJbossXml(ejbRef);
0890:                }
0891:
0892:                //handle the ejb-local-ref elements
0893:                iterator = getChildrenByTagName(element, "ejb-local-ref");
0894:                while (iterator.hasNext()) {
0895:                    Element ejbLocalRef = (Element) iterator.next();
0896:                    String ejbLocalRefName = getElementContent(getUniqueChild(
0897:                            ejbLocalRef, "ejb-ref-name"));
0898:
0899:                    EjbLocalRefMetaData ejbLocalRefMetaData = getEjbLocalRefByName(ejbLocalRefName);
0900:                    if (ejbLocalRefMetaData == null) {
0901:                        throw new DeploymentException("ejb-local-ref "
0902:                                + ejbLocalRefName
0903:                                + " found in jboss.xml but not in ejb-jar.xml");
0904:                    }
0905:                    ejbLocalRefMetaData.importJbossXml(ejbLocalRef);
0906:                }
0907:
0908:                // Parse the service-ref elements
0909:                iterator = MetaData
0910:                        .getChildrenByTagName(element, "service-ref");
0911:                while (iterator.hasNext()) {
0912:                    Element serviceRef = (Element) iterator.next();
0913:                    String serviceRefName = MetaData.getUniqueChildContent(
0914:                            serviceRef, "service-ref-name");
0915:                    ServiceRefMetaData refMetaData = (ServiceRefMetaData) serviceReferences
0916:                            .get(serviceRefName);
0917:                    if (refMetaData == null) {
0918:                        throw new DeploymentException("service-ref "
0919:                                + serviceRefName
0920:                                + " found in jboss.xml but not in ejb-jar.xml");
0921:                    }
0922:                    refMetaData.importJBossXml(serviceRef);
0923:                }
0924:
0925:                // Get the security identity
0926:                Element securityIdentityElement = getOptionalChild(element,
0927:                        "security-identity");
0928:                if (securityIdentityElement != null) {
0929:                    if (securityIdentity == null)
0930:                        throw new DeploymentException(
0931:                                ejbName
0932:                                        + ", security-identity in jboss.xml has no match in ejb-jar.xml");
0933:                    String runAsPrincipal = getElementContent(getUniqueChild(
0934:                            securityIdentityElement, "run-as-principal"),
0935:                            securityIdentity.getRunAsPrincipalName());
0936:                    securityIdentity.setRunAsPrincipalName(runAsPrincipal);
0937:                }
0938:
0939:                // Get the ejbTimeout caller identity
0940:                Element ejbTimeoutIdentityElement = getOptionalChild(element,
0941:                        "ejb-timeout-identity");
0942:                if (ejbTimeoutIdentityElement != null) {
0943:                    ejbTimeoutIdentity = new SecurityIdentityMetaData();
0944:                    String runAsPrincipal = getElementContent(getUniqueChild(
0945:                            ejbTimeoutIdentityElement, "run-as-principal"),
0946:                            null);
0947:                    ejbTimeoutIdentity.setRunAsRoleName("ejbTimeout");
0948:                    if (runAsPrincipal != null && runAsPrincipal.length() > 0)
0949:                        ejbTimeoutIdentity
0950:                                .setRunAsPrincipalName(runAsPrincipal);
0951:                    else
0952:                        ejbTimeoutIdentity.setUseCallerIdentity(true);
0953:                }
0954:
0955:                // Method attributes of the bean
0956:                Element mas = getOptionalChild(element, "method-attributes");
0957:                if (mas != null) {
0958:                    // read in the read-only methods
0959:                    iterator = getChildrenByTagName(mas, "method");
0960:                    while (iterator.hasNext()) {
0961:                        MethodAttributes ma = new MethodAttributes();
0962:                        Element maNode = (Element) iterator.next();
0963:                        ma.pattern = getElementContent(getUniqueChild(maNode,
0964:                                "method-name"));
0965:                        ma.readOnly = getOptionalChildBooleanContent(maNode,
0966:                                "read-only");
0967:                        ma.idempotent = getOptionalChildBooleanContent(maNode,
0968:                                "idempotent");
0969:                        String txTimeout = getOptionalChildContent(maNode,
0970:                                "transaction-timeout");
0971:                        try {
0972:                            if (txTimeout != null && txTimeout.length() > 0)
0973:                                ma.txTimeout = Integer.parseInt(txTimeout);
0974:                        } catch (Exception ignore) {
0975:                            log.debug("Ignoring transaction-timeout '"
0976:                                    + txTimeout + "'", ignore);
0977:                        }
0978:                        methodAttributes.add(ma);
0979:                    }
0980:                }
0981:
0982:                // Invokers
0983:                // If no invoker bindings have been defined they will be defined
0984:                // in EntityMetaData, or SessionMetaData
0985:                Element inv = getOptionalChild(element, "invoker-bindings");
0986:                if (inv != null) {
0987:                    // read in the read-only methods
0988:                    iterator = getChildrenByTagName(inv, "invoker");
0989:                    invokerBindings = new HashMap();
0990:                    while (iterator.hasNext()) {
0991:                        Element node = (Element) iterator.next();
0992:                        String invokerBindingName = getUniqueChildContent(node,
0993:                                "invoker-proxy-binding-name");
0994:                        String jndiBinding = getOptionalChildContent(node,
0995:                                "jndi-name");
0996:
0997:                        if (jndiBinding == null) {
0998:                            jndiBinding = getJndiName(); // default to jndiName
0999:                        }
1000:                        invokerBindings.put(invokerBindingName, jndiBinding);
1001:
1002:                        // set the external ejb-references (optional)
1003:                        Iterator ejbrefiterator = getChildrenByTagName(node,
1004:                                "ejb-ref");
1005:                        while (ejbrefiterator.hasNext()) {
1006:                            Element ejbRef = (Element) ejbrefiterator.next();
1007:                            String ejbRefName = getElementContent(getUniqueChild(
1008:                                    ejbRef, "ejb-ref-name"));
1009:                            EjbRefMetaData ejbRefMetaData = getEjbRefByName(ejbRefName);
1010:                            if (ejbRefMetaData == null) {
1011:                                throw new DeploymentException(
1012:                                        "ejb-ref "
1013:                                                + ejbRefName
1014:                                                + " found in jboss.xml but not in ejb-jar.xml");
1015:                            }
1016:                            ejbRefMetaData.importJbossXml(invokerBindingName,
1017:                                    ejbRef);
1018:                        }
1019:                    }
1020:                }
1021:
1022:                // Determine if the bean is to be deployed in the cluster (more
1023:                // advanced config will be added in the future)
1024:                String clusteredElt = getElementContent(getOptionalChild(
1025:                        element, "clustered"), (clustered ? "True" : "False"));
1026:                clustered = clusteredElt.equalsIgnoreCase("True");
1027:
1028:                Element clusterConfigElement = getOptionalChild(element,
1029:                        "cluster-config");
1030:                if (clusterConfigElement != null) {
1031:                    this .clusterConfig = new ClusterConfigMetaData();
1032:                    clusterConfig.init(this );
1033:                    clusterConfig.importJbossXml(clusterConfigElement);
1034:                }
1035:
1036:                //Get depends object names
1037:                for (Iterator dependsElements = getChildrenByTagName(element,
1038:                        "depends"); dependsElements.hasNext();) {
1039:                    Element dependsElement = (Element) dependsElements.next();
1040:                    String dependsName = getElementContent(dependsElement);
1041:                    depends.add(ObjectNameFactory.create(dependsName));
1042:                } // end of for ()
1043:
1044:                // ior-security-config optional element
1045:                Element iorSecurityConfigEl = getOptionalChild(element,
1046:                        "ior-security-config");
1047:                if (iorSecurityConfigEl != null) {
1048:                    iorSecurityConfig = new IorSecurityConfigMetaData(
1049:                            iorSecurityConfigEl);
1050:                }
1051:
1052:            }
1053:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.