1 22 package org.jboss.web.metamodel.descriptor; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.metamodel.descriptor.DDObjectFactory; 26 import org.jboss.metamodel.descriptor.EjbLocalRef; 27 import org.jboss.metamodel.descriptor.EjbRef; 28 import org.jboss.metamodel.descriptor.EnvEntry; 29 import org.jboss.metamodel.descriptor.MessageDestination; 30 import org.jboss.metamodel.descriptor.MessageDestinationRef; 31 import org.jboss.metamodel.descriptor.ResourceEnvRef; 32 import org.jboss.metamodel.descriptor.ResourceRef; 33 import org.jboss.metamodel.descriptor.ServiceRef; 34 import org.jboss.util.xml.JBossEntityResolver; 35 import org.jboss.xb.binding.JBossXBException; 36 import org.jboss.xb.binding.ObjectModelFactory; 37 import org.jboss.xb.binding.Unmarshaller; 38 import org.jboss.xb.binding.UnmarshallerFactory; 39 import org.jboss.xb.binding.UnmarshallingContext; 40 import org.xml.sax.Attributes ; 41 42 import java.io.IOException ; 43 import java.io.InputStream ; 44 import java.net.URL ; 45 46 53 public class JBossWebDDObjectFactory extends DDObjectFactory 54 { 55 private static final Logger log = Logger 56 .getLogger(JBossWebDDObjectFactory.class); 57 58 private WebDD dd; 59 60 public static WebDD parse(URL ddResource, WebDD dd) 61 throws JBossXBException, IOException 62 { 63 if (ddResource == null) return null; 64 log.debug("found jboss-web.xml " + ddResource); 65 66 InputStream is = ddResource.openStream(); 67 68 return parse(dd, is); 69 } 70 71 public static WebDD parse(WebDD dd, InputStream is) 72 throws JBossXBException 73 { 74 ObjectModelFactory factory = null; 75 Unmarshaller unmarshaller = null; 76 77 if (dd == null) dd = new WebDD(); 78 79 factory = new JBossWebDDObjectFactory(dd); 80 UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance(); 81 unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, Boolean.TRUE); 82 unmarshaller = unmarshallerFactory.newUnmarshaller(); 83 JBossEntityResolver entityResolver = new JBossEntityResolver(); 84 unmarshaller.setEntityResolver(entityResolver); 85 86 dd = (WebDD) unmarshaller.unmarshal(is, factory, null); 87 88 return dd; 89 } 90 91 public JBossWebDDObjectFactory(WebDD dd) 92 { 93 super(); 94 this.dd = dd; 95 } 96 97 100 public Object newRoot(Object root, UnmarshallingContext navigator, 101 String namespaceURI, String localName, Attributes attrs) 102 { 103 return dd; 104 } 105 106 public Object completeRoot(Object root, UnmarshallingContext ctx, 107 String uri, String name) 108 { 109 return root; 110 } 111 112 114 117 public Object newChild(WebDD dd, UnmarshallingContext navigator, 118 String namespaceURI, String localName, Attributes attrs) 119 { 120 Object child = null; 121 log.debug("newChild, "+localName); 122 if ((child = newEnvRefGroupChild(localName)) != null) 123 return child; 124 else if (localName.equals("security-role")) 125 child = new SecurityRole(); 126 else if (localName.equals("servlet")) 127 child = new Servlet(); 128 else if (localName.equals("replication-config")) 129 child = new ReplicationConfig(); 130 else if (localName.equals("message-destination")) 131 { 132 child = new MessageDestination(); 133 } 134 return child; 135 } 136 137 public void addChild(WebDD parent, ReplicationConfig config, 138 UnmarshallingContext navigator, String namespaceURI, String localName) 139 { 140 parent.setReplicationConfig(config); 141 } 142 143 public void addChild(WebDD parent, EjbLocalRef ref, 144 UnmarshallingContext navigator, String namespaceURI, String localName) 145 { 146 parent.updateEjbLocalRef(ref); 147 } 148 149 public void addChild(WebDD parent, EjbRef ref, 150 UnmarshallingContext navigator, String namespaceURI, String localName) 151 { 152 parent.updateEjbRef(ref); 153 } 154 155 public void addChild(WebDD parent, EnvEntry ref, 156 UnmarshallingContext navigator, String namespaceURI, String localName) 157 { 158 parent.addEnvEntry(ref); 159 } 160 161 public void addChild(WebDD parent, MessageDestination destination, 162 UnmarshallingContext navigator, String namespaceURI, String localName) 163 { 164 log.debug("addMessageDestination, "+destination); 165 parent.updateMessageDestination(destination); 166 String link = destination.getMessageDestinationName(); 168 if( link != null ) 169 { 170 MessageDestinationRef ref = parent.getMessageDestinationRefForLink(link); 171 if( ref != null ) 172 { 173 log.debug("ressolved "+ref+" to link mapedName: "+destination.getMappedName()); 174 ref.setMappedName(destination.getMappedName()); 175 } 176 } 177 } 178 179 public void addChild(WebDD parent, MessageDestinationRef ref, UnmarshallingContext navigator, String namespaceURI, String localName) 180 { 181 log.debug("addMessageDestinationRef, " + ref); 182 parent.updateMessageDestinationRef(ref); 183 } 184 185 public void addChild(WebDD parent, ServiceRef ref, UnmarshallingContext navigator, String namespaceURI, String localName) 186 { 187 parent.addServiceRef(ref); 188 } 189 190 public void addChild(WebDD parent, ResourceEnvRef ref, 191 UnmarshallingContext navigator, String namespaceURI, String localName) 192 { 193 parent.updateResourceEnvRef(ref); 194 } 195 196 public void addChild(WebDD parent, ResourceRef ref, 197 UnmarshallingContext navigator, String namespaceURI, String localName) 198 { 199 parent.updateResourceRef(ref); 200 } 201 202 public void addChild(WebDD parent, SecurityRole role, 203 UnmarshallingContext navigator, String namespaceURI, String localName) 204 { 205 parent.updateSecurityRole(role); 206 } 207 208 public void addChild(WebDD parent, Servlet servlet, 209 UnmarshallingContext navigator, String namespaceURI, String localName) 210 { 211 parent.updateServlet(servlet); 212 } 213 214 public void setValue(WebDD dd, 215 UnmarshallingContext navigator, String namespaceURI, String localName, 216 String value) 217 { 218 if (localName.equals("depends")) 219 { 220 dd.addDependency(value); 221 } 222 else if (localName.equals("security-domain")) 223 { 224 dd.setSecurityDomain(value); 225 } 226 } 227 228 public void setValue(ReplicationConfig config, 229 UnmarshallingContext navigator, String namespaceURI, String localName, 230 String value) 231 { 232 if (localName.equals("replication-trigger")) 233 { 234 config.setTrigger(value); 235 } 236 else if (localName.equals("replication-granularity")) 237 { 238 config.setGranularity(value); 239 } 240 else if (localName.equals("replication-field-batch-mode")) 241 { 242 config.setFieldBatchMode(value); 243 } 244 } 245 246 public void setValue(Servlet servlet, 247 UnmarshallingContext navigator, String namespaceURI, String localName, 248 String value) 249 { 250 if (localName.equals("servlet-name")) 251 { 252 servlet.setName(value); 253 } 254 else if (localName.equals("run-as-principal")) 255 { 256 servlet.addRunAsPrincipal(value); 257 } 258 } 259 260 public void setValue(ServletMapping mapping, 261 UnmarshallingContext navigator, String namespaceURI, String localName, 262 String value) 263 { 264 if (localName.equals("servlet-name")) 265 { 266 mapping.setName(value); 267 } 268 else if (localName.equals("url-pattern")) 269 { 270 mapping.setUrlPattern(value); 271 } 272 } 273 274 public void setValue(SecurityRole role, 275 UnmarshallingContext navigator, String namespaceURI, String localName, 276 String value) 277 { 278 if (localName.equals("principal-name")) 279 { 280 role.setPrincipalName(value); 281 } 282 else 283 super.setValue(role, navigator, namespaceURI, localName, value); 284 } 285 } 286 | Popular Tags |