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.EnvEntry; 30 import org.jboss.util.xml.JBossEntityResolver; 31 import org.jboss.xb.binding.JBossXBException; 32 import org.jboss.xb.binding.Unmarshaller; 33 import org.jboss.xb.binding.UnmarshallerFactory; 34 import org.jboss.xb.binding.UnmarshallingContext; 35 import org.xml.sax.Attributes ; 36 37 45 public class ApplicationClientDDObjectFactory extends DDObjectFactory 46 { 47 private static final Logger log = Logger.getLogger(ApplicationClientDDObjectFactory.class); 48 49 public ApplicationClientDDObjectFactory() 51 { 52 53 } 54 55 public static ApplicationClientDD parse(URL ddResource) throws JBossXBException, IOException 56 { 57 if(ddResource == null) 58 return null; 59 60 log.debug("found application-client.xml " + ddResource); 61 62 ApplicationClientDDObjectFactory factory = new ApplicationClientDDObjectFactory(); 63 UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance(); 64 unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, true); 65 Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller(); 66 JBossEntityResolver entityResolver = new JBossEntityResolver(); 67 unmarshaller.setEntityResolver(entityResolver); 68 69 ApplicationClientDD dd = (ApplicationClientDD) unmarshaller.unmarshal(ddResource.openStream(), factory, null); 70 71 return dd; 72 } 73 74 77 public void addChild(ApplicationClientDD parent, EnvEntry entry, UnmarshallingContext navigator, String namespaceURI, String localName) 78 { 79 parent.addEnvEntry(entry); 80 } 81 82 public void addChild(ApplicationClientDD parent, LifecycleCallback lifecycleCallback, UnmarshallingContext navigator, String namespaceURI, String localName) 83 { 84 if(localName.equals("post-construct")) 85 parent.getPostConstructs().add(lifecycleCallback); 86 else if(localName.equals("pre-destroy")) 87 parent.getPreDestroys().add(lifecycleCallback); 88 else 89 throw new IllegalArgumentException (localName); 90 } 91 92 public Object completeRoot(Object root, UnmarshallingContext ctx, String uri, String name) 93 { 94 throw new RuntimeException ("NYI"); 95 } 96 97 public Object newChild(ApplicationClientDD parent, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 98 { 99 Object child = super.newEnvRefGroupChild(localName); 100 if(child != null) return child; 101 102 if(localName.equals("post-construct") || localName.equals("pre-destroy")) 103 { 104 child = new LifecycleCallback(); 105 } 106 107 109 return child; 110 } 111 112 public Object newRoot(Object root, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 113 { 114 final ApplicationClientDD dd; 115 if(root == null) 116 root = dd = new ApplicationClientDD(); 117 else 118 dd = (ApplicationClientDD) root; 119 120 if(attrs.getLength() > 0) 121 { 122 for (int i = 0; i < attrs.getLength(); ++i) 123 { 124 if (attrs.getLocalName(i).equals("version")) 125 { 126 dd.setVersion(attrs.getValue(i)); 127 } 128 else if(attrs.getLocalName(i).equals("metadata-complete")) 129 { 130 dd.setMetadataComplete(Boolean.parseBoolean(attrs.getValue(i))); 131 } 132 else if(attrs.getLocalName(i).equals("schemaLocation")) 133 { 134 } 136 else 137 throw new IllegalArgumentException (attrs.getLocalName(i)); 138 } 139 } 140 141 return root; 142 } 143 144 147 public void setValue(ApplicationClientDD dd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 148 { 149 if (localName.equals("display-name")) 150 { 151 dd.setDisplayName(getValue(localName, value)); 152 } 153 } 160 161 public void setValue(LifecycleCallback lifecycleCallback, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 162 { 163 if(localName.equals("lifecycle-callback-class")) 164 lifecycleCallback.setLifecycleCallbackClass(value); 165 else if(localName.equals("lifecycle-callback-method")) 166 lifecycleCallback.setLifecycleCallbackMethod(value); 167 else 168 throw new IllegalArgumentException (localName); 169 } 170 } 171 | Popular Tags |