1 22 package org.jboss.ejb3.metamodel; 23 24 import java.io.IOException ; 25 import java.net.URL ; 26 27 import org.jboss.logging.Logger; 28 import org.jboss.metamodel.descriptor.DDObjectFactory; 29 import org.jboss.metamodel.descriptor.EjbRef; 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.Unmarshaller; 37 import org.jboss.xb.binding.UnmarshallerFactory; 38 import org.jboss.xb.binding.UnmarshallingContext; 39 import org.xml.sax.Attributes ; 40 41 49 public class JBossClientDDObjectFactory extends DDObjectFactory 50 { 51 private static final Logger log = Logger.getLogger(JBossClientDDObjectFactory.class); 52 53 private ApplicationClientDD dd; 54 55 public static ApplicationClientDD parse(URL ddResource, ApplicationClientDD dd) 56 throws JBossXBException, IOException 57 { 58 if(dd == null) 60 dd = new ApplicationClientDD(); 61 62 if(ddResource == null) 63 return dd; 64 65 log.debug("found jboss-client.xml " + ddResource); 66 67 JBossClientDDObjectFactory factory = new JBossClientDDObjectFactory(dd); 68 UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance(); 69 unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, Boolean.TRUE); 70 Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller(); 71 JBossEntityResolver entityResolver = new JBossEntityResolver(); 72 unmarshaller.setEntityResolver(entityResolver); 73 74 dd = (ApplicationClientDD) unmarshaller.unmarshal(ddResource.openStream(), factory, null); 75 76 return dd; 77 } 78 79 public JBossClientDDObjectFactory(ApplicationClientDD dd) 80 { 81 this.dd = dd; 82 } 83 84 public void addChild(ApplicationClientDD parent, EjbRef ref, UnmarshallingContext navigator, String namespaceURI, String localName) 85 { 86 dd.updateEjbRef(ref); 87 } 88 89 public void addChild(ApplicationClientDD parent, MessageDestinationRef ref, UnmarshallingContext navigator, String namespaceURI, String localName) 90 { 91 dd.updateMessageDestinationRef(ref); 92 } 93 94 public void addChild(ApplicationClientDD parent, ServiceRef ref, UnmarshallingContext navigator, String namespaceURI, String localName) 95 { 96 dd.addServiceRef(ref); 97 } 98 99 public void addChild(ApplicationClientDD dd, ResourceEnvRef envRef, UnmarshallingContext navigator, String namespaceURI, String localName) 100 { 101 dd.updateResourceEnvRef(envRef); 102 } 103 104 public void addChild(ApplicationClientDD parent, ResourceRef ref, UnmarshallingContext navigator, String namespaceURI, String localName) 105 { 106 dd.updateResourceRef(ref); 107 } 108 109 public Object completeRoot(Object root, UnmarshallingContext navigator, String uri, String name) 110 { 111 return root; 112 } 113 114 public Object newChild(ApplicationClientDD dd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 115 { 116 Object child = null; 117 118 child = newEnvRefGroupChild(localName); 119 if(child != null) 120 return child; 121 122 124 return child; 125 } 126 127 public Object newRoot(Object root, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 128 { 129 return dd; 130 } 131 132 public void setValue(ApplicationClientDD dd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 133 { 134 if(localName.equals("jndi-name")) 135 dd.setJndiName(value); 136 else if(localName.equals("depends")) 137 dd.addDependency(value); 138 } 139 } 140 | Popular Tags |