throw new IllegalArgumentException(getClass() + " cannot handles descriptors of type " + descriptor.getClass());
}
WebBundleDescriptor bundleDescriptor = (WebBundleDescriptor) descriptor;
Element web = (Element)super.writeDescriptor(parent, descriptor);
SunWebApp sunWebApp = bundleDescriptor.getSunDescriptor();
// context-root?
appendTextChild(web, RuntimeTagNames.CONTEXT_ROOT, bundleDescriptor.getContextRoot());
// security-role-mapping
SecurityRoleMapping[] roleMappings = sunWebApp.getSecurityRoleMapping();
if (roleMappings!=null && roleMappings.length>0) {
SecurityRoleMappingNode srmn = new SecurityRoleMappingNode();
for (int i=0;i<roleMappings.length;i++) {
srmn.writeDescriptor(web, RuntimeTagNames.SECURITY_ROLE_MAPPING, roleMappings[i]);
}
}
// servlet
Set servlets = bundleDescriptor.getServletDescriptors();
if (servlets!=null) {
com.sun.enterprise.deployment.node.runtime.ServletNode node =
new com.sun.enterprise.deployment.node.runtime.ServletNode();
for (Iterator itr=servlets.iterator();itr.hasNext();) {
WebComponentDescriptor servlet = (WebComponentDescriptor) itr.next();
node.writeDescriptor(web, RuntimeTagNames.SERVLET, servlet);
}
}
// idempotent-url-pattern
IdempotentUrlPattern[] patterns = sunWebApp.getIdempotentUrlPatterns();
if (patterns != null && patterns.length > 0) {
IdempotentUrlPatternNode node = new IdempotentUrlPatternNode();
for (int i = 0;i < patterns.length; i++) {
node.writeDescriptor(web, RuntimeTagNames.IDEMPOTENT_URL_PATTERN, patterns[i]);
}
}
// session-config?
if (sunWebApp.getSessionConfig()!=null) {
SessionConfigNode scn = new SessionConfigNode();
scn.writeDescriptor(web, RuntimeTagNames.SESSION_CONFIG, sunWebApp.getSessionConfig());
}
// ejb-ref*
EjbRef[] ejbRefs = sunWebApp.getEjbRef();
if (ejbRefs!=null && ejbRefs.length>0) {
EjbRefNode node = new EjbRefNode();
for (int i=0;i<ejbRefs.length;i++) {
node.writeDescriptor(web, RuntimeTagNames.EJB_REF, ejbRefs[i]);
}
}
// resource-ref*
ResourceRef[] resourceRefs = sunWebApp.getResourceRef();
if (resourceRefs!=null && resourceRefs.length>0) {
ResourceRefNode node = new ResourceRefNode();
for (int i=0;i<resourceRefs.length;i++) {
node.writeDescriptor(web, RuntimeTagNames.RESOURCE_REF, resourceRefs[i]);
}
}
// resource-env-ref*
ResourceEnvRef[] resourceEnvRefs = sunWebApp.getResourceEnvRef();
if (resourceEnvRefs!=null && resourceEnvRefs.length>0) {
ResourceEnvRefNode node = new ResourceEnvRefNode();
for (int i=0;i<resourceEnvRefs.length;i++) {
node.writeDescriptor(web, RuntimeTagNames.RESOURCE_ENV_REF, resourceEnvRefs[i]);
}
}
// service-ref*
if (bundleDescriptor.hasServiceReferenceDescriptors()) {
ServiceRefNode serviceNode = new ServiceRefNode();
for (Iterator serviceItr=bundleDescriptor.getServiceReferenceDescriptors().iterator();
serviceItr.hasNext();) {
ServiceReferenceDescriptor next = (ServiceReferenceDescriptor) serviceItr.next();
serviceNode.writeDescriptor(web, WebServicesTagNames.SERVICE_REF, next);
}
}
// message-destination-ref*
MessageDestinationRefNode.writeMessageDestinationReferences(web,
bundleDescriptor);
// cache?
Cache cache = sunWebApp.getCache();
if (cache!=null) {
CacheNode cn = new CacheNode();
cn.writeDescriptor(web, RuntimeTagNames.CACHE, cache);
}
// class-loader?
ClassLoader classLoader = sunWebApp.getClassLoader();
if (classLoader!=null) {
ClassLoaderNode cln = new ClassLoaderNode();
cln.writeDescriptor(web, RuntimeTagNames.CLASS_LOADER, classLoader);
}
// jsp-config?
if (sunWebApp.getJspConfig()!=null) {
WebPropertyNode propertyNode = new WebPropertyNode();
Node jspConfig = appendChild(web, RuntimeTagNames.JSP_CONFIG);
propertyNode.writeDescriptor(jspConfig, RuntimeTagNames.PROPERTY, sunWebApp.getJspConfig().getWebProperty());
}
// locale-charset-info?
if (sunWebApp.getLocaleCharsetInfo()!=null) {
LocaleCharsetInfoNode localeNode = new LocaleCharsetInfoNode();
localeNode.writeDescriptor(web, RuntimeTagNames.LOCALE_CHARSET_INFO,
sunWebApp.getLocaleCharsetInfo());
}
// parameter-encoding?
if (sunWebApp.isParameterEncoding()) {
Element parameter = (Element) appendChild(web, RuntimeTagNames.PARAMETER_ENCODING);
if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.FORM_HINT_FIELD)!=null) {
setAttribute(parameter, RuntimeTagNames.FORM_HINT_FIELD,
(String) sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.FORM_HINT_FIELD));
}
if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.DEFAULT_CHARSET)!=null) {
setAttribute(parameter, RuntimeTagNames.DEFAULT_CHARSET,
(String) sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.DEFAULT_CHARSET));
}
}
// property*
if (sunWebApp.getWebProperty()!=null) {
WebPropertyNode props = new WebPropertyNode();
props.writeDescriptor(web, RuntimeTagNames.PROPERTY, sunWebApp.getWebProperty());
}
// message-destination*
RuntimeDescriptorNode.writeMessageDestinationInfo(web, bundleDescriptor);
// webservice-description*
WebServiceRuntimeNode webServiceNode = new WebServiceRuntimeNode();
webServiceNode.writeWebServiceRuntimeInfo(web, bundleDescriptor);
// error-url
if (sunWebApp.getAttributeValue(sunWebApp.ERROR_URL) != null) {
setAttribute(web, RuntimeTagNames.ERROR_URL, sunWebApp.getAttributeValue(sunWebApp.ERROR_URL));
}
// httpservlet-security-provider
if (sunWebApp.getAttributeValue(sunWebApp.HTTPSERVLET_SECURITY_PROVIDER) != null) {
setAttribute(web, RuntimeTagNames.HTTPSERVLET_SECURITY_PROVIDER,
sunWebApp.getAttributeValue(sunWebApp.HTTPSERVLET_SECURITY_PROVIDER));
}
return web;
}