com.sun.enterprise.deployment.node.runtime.RuntimeBundleNode Maven / Gradle / Ivy
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.enterprise.deployment.node.runtime;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.MessageDestinationDescriptor;
import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
import com.sun.enterprise.deployment.node.RootXMLNode;
import com.sun.enterprise.deployment.node.XMLElement;
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.deployment.xml.RuntimeTagNames;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.glassfish.deployment.common.RootDeploymentDescriptor;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public abstract class RuntimeBundleNode extends DeploymentDescriptorNode
implements RootXMLNode {
private static Boolean restrictDTDDeclarations;
protected T descriptor;
// we record the XML element to node class mapping when parsing and
// retrieve it when writing out
// The first level map is indexed by the parent element name, and the
// second level of the map is indexed by the sub element name and the
// corresponding handler node class name
protected HashMap>> elementToNodeMappings = new HashMap<>();
public RuntimeBundleNode(T descriptor) {
this.descriptor = descriptor;
init();
}
public RuntimeBundleNode() {
this(null);
}
/**
* Initializes the child handler;
*/
protected void init() {
// we do not care about standard DDs common tags
handlers = null;
}
/**
* Adds a new DOL descriptor instance to the descriptor instance associated with
* this XMLNode
*
* @param descriptor the new descriptor
*/
@Override
public void addDescriptor(Object descriptor) {
return;
}
/**
* @return the descriptor instance to associate with this XMLNode
*/
@Override
public T getDescriptor() {
return descriptor;
}
/**
* @return the default spec version level this node complies to
*/
@Override
public String getSpecVersion() {
return "1.5";
}
/**
* set the DOCTYPE as read in the input XML File
*
* @param docType
*/
@Override
public void setDocType(String docType) {
// I do not care about the version of the runtime descriptors
}
/**
* Sets the specVersion for this descriptor depending on the docType
*/
protected void setSpecVersion() {
// I do not care about the version of the runtime descriptors
}
/**
* writes the message destination references runtime information
*/
protected void writeMessageDestinationInfo(Node parent, BundleDescriptor descriptor) {
for (MessageDestinationDescriptor element : descriptor.getMessageDestinations()) {
MessageDestinationRuntimeNode node = new MessageDestinationRuntimeNode();
node.writeDescriptor(parent, RuntimeTagNames.MESSAGE_DESTINATION, element);
}
}
/**
* @return true if the runtime bundle node should only process
* the product FCS DTD declarations
*/
protected static final synchronized boolean restrictDTDDeclarations() {
if (restrictDTDDeclarations == null) {
restrictDTDDeclarations = Boolean
.valueOf(Boolean.getBoolean("com.sun.aas.deployment.restrictdtddeclarations"));
}
return restrictDTDDeclarations.booleanValue();
}
public static Element appendChildNS(Node parent, String elementName, String nameSpace) {
Element child = getOwnerDocument(parent).createElementNS(nameSpace, elementName);
parent.appendChild(child);
return child;
}
/**
* record mapping of sub element to node class for the current element
*/
public void recordNodeMapping(String currentElementName, String subElementName, Class> subElementHandler) {
LinkedHashMap> subElementMappings = elementToNodeMappings.get(currentElementName);
if (subElementMappings == null) {
subElementMappings = new LinkedHashMap<>();
elementToNodeMappings.put(currentElementName, subElementMappings);
}
subElementMappings.put(subElementName, subElementHandler);
}
public LinkedHashMap> getNodeMappings(String currentElementName) {
return elementToNodeMappings.get(currentElementName);
}
/**
* receives notiification of the value for a particular tag
*
* @param element the xml element
* @param value it's associated value
*/
@Override
public void setElementValue(XMLElement element, String value) {
if (!DOLUtils.setElementValue(element, value, getDescriptor())) {
super.setElementValue(element, value);
}
}
/**
* all sub-implementation of this class can use a dispatch table to map xml element to
* method name on the descriptor class for setting the element value.
*
* @return the map with the element name as a key, the setter method as a value
*/
@Override
protected Map getDispatchTable() {
Map dispatchTable = super.getDispatchTable();
dispatchTable.put("version", "setSpecVersion");
return dispatchTable;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy