1 22 package org.jboss.deployment; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.metadata.SecurityRoleMetaData; 26 import org.jboss.mx.loading.LoaderRepositoryFactory; 27 import org.jboss.xb.binding.ObjectModelFactory; 28 import org.jboss.xb.binding.UnmarshallingContext; 29 import org.xml.sax.Attributes ; 30 31 37 public class JBossApplicationObjectFactory implements ObjectModelFactory 38 { 39 private static Logger log = Logger.getLogger(JBossApplicationObjectFactory.class); 40 private static ThreadLocal <J2eeApplicationMetaData> activeMetaData 41 = new ThreadLocal <J2eeApplicationMetaData>(); 42 43 public J2eeApplicationMetaData newRoot(Object root, UnmarshallingContext navigator, 44 String namespaceURI, String localName, Attributes attrs) 45 { 46 J2eeApplicationMetaData metaData = null; 47 if (root != null) 48 metaData = (J2eeApplicationMetaData) root; 49 else 50 metaData = new J2eeApplicationMetaData(); 51 activeMetaData.set(metaData); 52 return metaData; 53 } 54 55 public Object completeRoot(Object root, UnmarshallingContext ctx, 56 String uri, String name) 57 { 58 activeMetaData.set(null); 59 return root; 60 } 61 62 72 public Object newChild(J2eeApplicationMetaData dd, UnmarshallingContext navigator, 73 String namespaceURI, String localName, Attributes attrs) 74 { 75 Object child = null; 76 log.debug("newChild, " + localName); 77 78 if(localName.equals("module")) 80 child = new J2eeModuleMetaData(); 81 else if( localName.equals("security-role")) 82 child = new SecurityRoleMetaData(); 83 else if( localName.equals("loader-repository") ) 84 child = new LoaderRepositoryFactory.LoaderRepositoryConfig(); 85 else if (log.isTraceEnabled()) 86 { 87 log.trace("Ignoring: " + localName); 88 } 89 return child; 90 } 91 92 100 public void setValue(J2eeModuleMetaData module, 101 UnmarshallingContext navigator, String namespaceURI, String localName, 102 String value) 103 { 104 if( localName.equals("service") ) 105 { 106 module.setType(J2eeModuleMetaData.SERVICE); 107 module.setFileName(value); 108 } 109 else if( localName.equals("har") ) 110 { 111 module.setType(J2eeModuleMetaData.HAR); 112 module.setFileName(value); 113 } 114 } 115 116 public void addChild(J2eeApplicationMetaData parent, J2eeModuleMetaData module, 117 UnmarshallingContext navigator, String namespaceURI, String localName) 118 { 119 parent.addModule(module); 120 } 121 122 public void addChild(J2eeApplicationMetaData parent, LoaderRepositoryFactory.LoaderRepositoryConfig cfg, 123 UnmarshallingContext navigator, String namespaceURI, String localName) 124 { 125 parent.setLoaderCfg(cfg); 126 } 127 128 136 public void setValue(J2eeApplicationMetaData dd, 137 UnmarshallingContext navigator, String namespaceURI, String localName, 138 String value) 139 { 140 if( localName.equals("security-domain") ) 141 dd.setSecurityDomain(value); 142 else if( localName.equals("unauthenticated-principal") ) 143 dd.setUnauthenticatedPrincipal(value); 144 else if( localName.equals("jmx-name") ) 145 dd.setJMXName(value); 146 147 } 148 149 public void setValue(SecurityRoleMetaData role, 150 UnmarshallingContext navigator, String namespaceURI, String localName, 151 String value) 152 { 153 if( localName.equals("role-name") ) 154 { 155 role.setRoleName(value); 156 } 157 else if( localName.equals("principal-name") ) 158 { 159 J2eeApplicationMetaData metaData = activeMetaData.get(); 160 SecurityRoleMetaData srmd = metaData.getSecurityRole(role.getRoleName()); 161 if(srmd == null) 163 { 164 srmd = new SecurityRoleMetaData(); 165 srmd.setRoleName(role.getRoleName()); 166 metaData.addSecurityRole(srmd); 167 } 168 srmd.addPrincipalName(value); 169 } 170 } 171 172 180 public void setValue(LoaderRepositoryFactory.LoaderRepositoryConfig cfg, 181 UnmarshallingContext navigator, String namespaceURI, String localName, 182 String value) 183 { 184 if( localName.equals("loader-repository-config") ) 185 { 186 cfg.repositoryConfig = value; 187 } 188 } 189 190 } 191 | Popular Tags |