1 23 24 package com.sun.enterprise.deployment.node; 25 26 import java.util.Map ; 27 import java.util.Iterator ; 28 import java.util.StringTokenizer ; 29 import org.w3c.dom.Node ; 30 import org.w3c.dom.Element ; 31 import javax.enterprise.deploy.shared.ModuleType ; 32 import com.sun.enterprise.deployment.xml.TagNames; 33 import com.sun.enterprise.deployment.node.connector.ConnectorNode; 34 import com.sun.enterprise.deployment.Descriptor; 35 import com.sun.enterprise.deployment.BundleDescriptor; 36 import com.sun.enterprise.deployment.ConnectorDescriptor; 37 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 38 import com.sun.enterprise.deployment.MessageDestinationDescriptor; 39 40 46 public abstract class BundleNode extends DisplayableComponentNode implements RootXMLNode { 47 48 public final static String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; 49 public final static String W3C_XML_SCHEMA_INSTANCE = "http://www.w3.org/2001/XMLSchema-instance"; 50 51 protected final static String SCHEMA_LOCATION_TAG = "xsi:schemaLocation"; 52 53 protected String docType; 54 private Map namespaceContext=null; 55 56 60 public void setDocType(String docType) { 61 this.docType = docType; 62 setSpecVersion(); 63 } 64 65 public static Element appendChildNS(Node parent, String elementName, 66 String nameSpace) { 67 Element child = getOwnerDocument(parent).createElementNS(nameSpace, elementName); 68 parent.appendChild(child); 69 return child; 70 } 71 72 78 protected Map getDispatchTable() { 79 Map dispatchTable = super.getDispatchTable(); 80 dispatchTable.put(TagNames.NAME, "setDisplayName"); 81 dispatchTable.put(TagNames.VERSION, "setSpecVersion"); 82 return dispatchTable; 83 } 84 85 91 public void setElementValue(XMLElement element, String value) { 92 if (SCHEMA_LOCATION_TAG.equals(element.getCompleteName())) { 93 StringTokenizer st = new StringTokenizer (value); 95 StringBuffer sb = new StringBuffer (); 96 while (st.hasMoreElements()) { 97 String namespace = (String ) st.nextElement(); 98 String schema; 99 if (st.hasMoreElements()) { 100 schema = (String ) st.nextElement(); 101 } else { 102 schema = namespace; 103 namespace = TagNames.JAVAEE_NAMESPACE; 104 } 105 if (namespace.equals(TagNames.J2EE_NAMESPACE)) 106 continue; 107 if (namespace.equals(TagNames.JAVAEE_NAMESPACE)) 108 continue; 109 if (namespace.equals(W3C_XML_SCHEMA)) 110 continue; 111 sb.append(namespace); 112 sb.append(" "); 113 sb.append(schema); 114 } 115 String clientSchemaLocation = sb.toString(); 116 if (clientSchemaLocation!=null && clientSchemaLocation.length()!=0) { 117 Object o = getDescriptor(); 118 if (o instanceof RootDeploymentDescriptor) { 119 ((RootDeploymentDescriptor) o).setSchemaLocation(clientSchemaLocation); 120 } 121 } 122 } else if (element.getQName().equals(TagNames.METADATA_COMPLETE)) { 123 Object o = getDescriptor(); 124 if (o instanceof BundleDescriptor) { 125 ((BundleDescriptor) o).setFullAttribute(value); 126 } 127 } else { 128 super.setElementValue(element, value); 129 } 130 } 131 132 139 public Node writeDescriptor(Node parent, RootDeploymentDescriptor descriptor) { 140 Node bundleNode; 141 if (getDocType()==null) { 142 144 if (descriptor instanceof ConnectorDescriptor) { 146 bundleNode = appendChildNS(parent, getXMLRootTag().getQName(), 147 TagNames.J2EE_NAMESPACE); 148 } else { 149 bundleNode = appendChildNS(parent, getXMLRootTag().getQName(), 150 TagNames.JAVAEE_NAMESPACE); 151 } 152 addBundleNodeAttributes((Element ) bundleNode, descriptor); 153 } else { 154 bundleNode = appendChild(parent, getXMLRootTag().getQName()); 155 } 156 writeDisplayableComponentInfo(bundleNode, descriptor); 158 159 160 return bundleNode; 161 } 162 163 protected void writeMessageDestinations(Node parentNode, 164 Iterator msgDestinations) { 165 if ( (msgDestinations == null) || !msgDestinations.hasNext() ) 166 return; 167 168 MessageDestinationNode subNode = new MessageDestinationNode(); 169 for (;msgDestinations.hasNext();) { 170 MessageDestinationDescriptor next = 171 (MessageDestinationDescriptor) msgDestinations.next(); 172 subNode.writeDescriptor(parentNode, 173 TagNames.MESSAGE_DESTINATION, next); 174 } 175 } 176 177 180 protected void addBundleNodeAttributes(Element bundleNode, RootDeploymentDescriptor descriptor) { 181 String schemaLocation; 182 if (bundleNode instanceof ConnectorNode) { 184 bundleNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", TagNames.J2EE_NAMESPACE); 185 schemaLocation = TagNames.J2EE_NAMESPACE + " " + 186 getSchemaURL(); 187 } else { 188 bundleNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", TagNames.JAVAEE_NAMESPACE); 189 schemaLocation = TagNames.JAVAEE_NAMESPACE + " " + 190 getSchemaURL(); 191 } 192 bundleNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", W3C_XML_SCHEMA_INSTANCE); 193 194 addNamespaceDeclaration(bundleNode, descriptor); 196 String clientSchemaLocation = descriptor.getSchemaLocation(); 197 if (clientSchemaLocation!=null) { 198 schemaLocation = schemaLocation + " " + clientSchemaLocation; 199 } 200 bundleNode.setAttributeNS(W3C_XML_SCHEMA_INSTANCE, SCHEMA_LOCATION_TAG, schemaLocation); 201 bundleNode.setAttribute(TagNames.VERSION, getSpecVersion()); 202 203 if (descriptor instanceof BundleDescriptor) { 209 BundleDescriptor bundleDesc = (BundleDescriptor)descriptor; 210 if (! bundleDesc.isDDWithNoAnnotationAllowed()) { 211 bundleNode.setAttribute(TagNames.METADATA_COMPLETE, "true"); 212 } 213 } 214 } 215 216 219 public void addPrefixMapping(String prefix, String uri) { 220 if (uri.equals(TagNames.J2EE_NAMESPACE)) 222 return; 223 if (uri.equals(TagNames.JAVAEE_NAMESPACE)) 224 return; 225 if (uri.equals(W3C_XML_SCHEMA_INSTANCE)) 226 return; 227 super.addPrefixMapping(prefix, uri); 228 } 229 230 233 protected String getSchemaURL() { 234 return TagNames.JAVAEE_NAMESPACE + "/" + getSystemID(); 236 } 237 238 241 protected void setSpecVersion() { 242 if (docType==null) 243 return; 244 StringTokenizer st = new StringTokenizer (docType, "//"); 245 while (st.hasMoreElements()) { 246 String tmp = st.nextToken(); 247 if (tmp.startsWith("DTD")) { 248 StringTokenizer versionST = new StringTokenizer (tmp); 250 while (versionST.hasMoreElements()) { 251 String versionStr = versionST.nextToken(); 252 try { 253 Float.valueOf(versionStr); 254 RootDeploymentDescriptor rdd = (RootDeploymentDescriptor) getDescriptor(); 255 rdd.setSpecVersion(versionStr); 256 return; 257 } catch(NumberFormatException nfe) { 258 } 260 } 261 } 262 } 263 } 264 } 265 | Popular Tags |