All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.enterprise.deployment.node.runtime.common.MessageNode Maven / Gradle / Ivy

The newest version!
/*
 * 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.common;

import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.EjbDescriptor;
import com.sun.enterprise.deployment.MethodDescriptor;
import com.sun.enterprise.deployment.ServiceRefPortInfo;
import com.sun.enterprise.deployment.WebBundleDescriptor;
import com.sun.enterprise.deployment.WebServiceEndpoint;
import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
import com.sun.enterprise.deployment.node.MethodNode;
import com.sun.enterprise.deployment.node.XMLElement;
import com.sun.enterprise.deployment.node.XMLNode;
import com.sun.enterprise.deployment.runtime.common.MessageDescriptor;
import com.sun.enterprise.deployment.xml.RuntimeTagNames;
import com.sun.enterprise.deployment.xml.WebServicesTagNames;

import org.w3c.dom.Node;

/**
 * This node handles message element
 */
public class MessageNode extends DeploymentDescriptorNode {

    private static final String ALL_METHODS = "*";
    private MessageDescriptor descriptor;

    public MessageNode() {
        registerElementHandler(new XMLElement(RuntimeTagNames.JAVA_METHOD), MethodNode.class, "setMethodDescriptor");
    }


    /**
     * @return the descriptor instance to associate with this XMLNode
     */
    @Override
    public MessageDescriptor getDescriptor() {
        if (descriptor == null) {
            descriptor = new MessageDescriptor();
            setMiscDescriptors();
        }
        return descriptor;
    }


    /**
     * receives notification 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 (WebServicesTagNames.OPERATION_NAME.equals(element.getQName())) {
            descriptor.setOperationName(value);
        } else {
            super.setElementValue(element, value);
        }
    }


    @Override
    public Node writeDescriptor(Node parent, String nodeName, MessageDescriptor messageDesc) {
        Node messageNode = super.writeDescriptor(parent, nodeName, messageDesc);

        // for empty message case, set the method descriptor
        // to a method descriptor with "*" as name
        if (messageDesc.getOperationName() == null && messageDesc.getMethodDescriptor() == null) {
            MethodDescriptor allMethodDesc = new MethodDescriptor();
            allMethodDesc.setName(ALL_METHODS);
            messageDesc.setMethodDescriptor(allMethodDesc);
        }

        // java-method
        MethodDescriptor methodDesc = messageDesc.getMethodDescriptor();
        if (methodDesc != null) {
            MethodNode methodNode = new MethodNode();
            methodNode.writeJavaMethodDescriptor(messageNode, RuntimeTagNames.JAVA_METHOD, methodDesc);
        }

        // operation-name
        appendTextChild(messageNode, WebServicesTagNames.OPERATION_NAME, messageDesc.getOperationName());

        return messageNode;
    }


    private void setMiscDescriptors() {
        XMLNode parentNode = getParentNode().getParentNode().getParentNode();

        // get the endpoint or portinfo descriptor
        Object parentDesc = parentNode.getDescriptor();
        if (parentDesc instanceof ServiceRefPortInfo) {
            descriptor.setServiceRefPortInfo((ServiceRefPortInfo) parentDesc);
        } else if (parentDesc instanceof WebServiceEndpoint) {
            descriptor.setWebServiceEndpoint((WebServiceEndpoint) parentDesc);
        }

        // Get the bundle descriptor of which this belongs
        BundleDescriptor bundleDesc = null;
        parentNode = parentNode.getParentNode().getParentNode();
        if (parentNode.getDescriptor() instanceof WebBundleDescriptor) {
            // In the cases of used in
            // 1. webservice-endpoint for web component
            // 2. port-info for web component
            bundleDesc = (WebBundleDescriptor) parentNode.getDescriptor();
        } else if (parentNode.getDescriptor() instanceof BundleDescriptor) {
            // In the cases of used in port-info for app client
            bundleDesc = (BundleDescriptor) parentNode.getDescriptor();
        } else {
            // In the case of used in webservice-endpoint for ejb component
            if (parentNode.getDescriptor() instanceof EjbDescriptor) {
                EjbDescriptor ejbDesc = (EjbDescriptor) parentNode.getDescriptor();
                bundleDesc = ejbDesc.getEjbBundleDescriptor();
            } else {
                // In the case of used in port-info for ejb component
                parentNode = parentNode.getParentNode();
                if (parentNode.getDescriptor() instanceof EjbDescriptor) {
                    EjbDescriptor ejbDesc = (EjbDescriptor) parentNode.getDescriptor();
                    bundleDesc = ejbDesc.getEjbBundleDescriptor();
                }
            }
        }
        descriptor.setBundleDescriptor(bundleDesc);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy