1 23 24 package com.sun.enterprise.deployment.node; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.logging.Level ; 30 import java.util.Map ; 31 32 import org.xml.sax.Attributes ; 33 import org.w3c.dom.Node ; 34 import com.sun.enterprise.deployment.xml.ApplicationTagNames; 35 import com.sun.enterprise.deployment.Descriptor; 36 import com.sun.enterprise.deployment.EjbBundleDescriptor; 37 import com.sun.enterprise.deployment.WebBundleDescriptor; 38 import com.sun.enterprise.deployment.Application; 39 import com.sun.enterprise.deployment.util.ModuleDescriptor; 40 import com.sun.enterprise.deployment.xml.EjbTagNames; 41 42 import com.sun.enterprise.deployment.util.DOLUtils; 43 44 50 public class ApplicationNode extends BundleNode implements RootXMLNode{ 51 52 55 public final static String PUBLIC_DTD_ID = "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"; 56 public final static String PUBLIC_DTD_ID_12 = "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN"; 57 60 public final static String SYSTEM_ID = "http://java.sun.com/dtd/application_1_3.dtd"; 61 public final static String SYSTEM_ID_12 = "http://java.sun.com/dtd/application_1_2.dtd"; 62 63 public final static String SCHEMA_ID_14 = "application_1_4.xsd"; 64 65 public final static String SCHEMA_ID = "application_5.xsd"; 66 public final static String SPEC_VERSION = "5"; 67 private static List <String > systemIDs = null; 68 69 public final static XMLElement tag = new XMLElement(ApplicationTagNames.APPLICATION); 71 72 private Application descriptor; 74 75 81 public static String registerBundle(Map publicIDToDTD) { 82 publicIDToDTD.put(PUBLIC_DTD_ID, SYSTEM_ID); 83 publicIDToDTD.put(PUBLIC_DTD_ID_12, SYSTEM_ID_12); 84 return tag.getQName(); 85 } 86 87 88 public ApplicationNode() { 89 super(); 90 registerElementHandler(new XMLElement(ApplicationTagNames.MODULE), ModuleNode.class, "addModule"); 91 registerElementHandler(new XMLElement(ApplicationTagNames.ROLE), SecurityRoleNode.class, "addAppRole"); 92 } 93 94 97 protected XMLElement getXMLRootTag() { 98 return tag; 99 } 100 101 107 public void setElementValue(XMLElement element, String value) { 108 Application application = (Application)getDescriptor(); 109 if (element.getQName().equals( 110 ApplicationTagNames.LIBRARY_DIRECTORY)) { 111 application.setLibraryDirectory(value); 112 } else super.setElementValue(element, value); 113 } 114 115 116 122 public void addDescriptor(Object newDescriptor) { 123 if (newDescriptor instanceof EjbBundleDescriptor) { 124 if(DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) { 125 DOLUtils.getDefaultLogger().fine("In " + toString() + 126 " adding descriptor " + newDescriptor); 127 } 128 descriptor.addEjbBundleDescriptor((EjbBundleDescriptor) newDescriptor); 129 } else if (newDescriptor instanceof WebBundleDescriptor) { 130 DOLUtils.getDefaultLogger().fine("In " + toString() + " adding web descriptor " + newDescriptor); 131 descriptor.addWebBundleDescriptor((WebBundleDescriptor) newDescriptor); 132 } 133 } 134 135 138 public Object getDescriptor() { 139 if (descriptor==null) { 140 descriptor = (Application) DescriptorFactory.getDescriptor(getXMLPath()); 141 } 142 return descriptor; 143 } 144 145 148 public String getDocType() { 149 return null; 150 } 151 152 155 public String getSystemID() { 156 return SCHEMA_ID; 157 } 158 159 162 public List <String > getSystemIDs() { 163 if (systemIDs != null) { 164 return systemIDs; 165 } 166 167 systemIDs = new ArrayList <String >(); 168 systemIDs.add(SCHEMA_ID); 169 systemIDs.add(SCHEMA_ID_14); 170 return systemIDs; 171 } 172 173 179 public Node writeDescriptor(Node parent, Descriptor descriptor) { 180 if (! (descriptor instanceof Application)) { 181 throw new IllegalArgumentException (getClass() + " cannot handles descriptors of type " + descriptor.getClass()); 182 } 183 Application application = (Application) descriptor; 184 Node appNode = super.writeDescriptor(parent, application); 185 186 ModuleNode moduleNode = new ModuleNode(); 188 for (Iterator modules = application.getModules();modules.hasNext();) { 189 ModuleDescriptor next = (ModuleDescriptor) modules.next(); 190 moduleNode.writeDescriptor(appNode, ApplicationTagNames.MODULE, next); 191 } 192 193 197 198 if (application.getLibraryDirectoryRawValue() != null) { 200 appendTextChild(appNode, ApplicationTagNames.LIBRARY_DIRECTORY, 201 application.getLibraryDirectoryRawValue()); 202 } 203 return appNode; 204 } 205 206 209 public String getSpecVersion() { 210 return SPEC_VERSION; 211 } 212 213 } 214 | Popular Tags |