FileDocCategorySizeDatePackage
JBIDescriptorReader.javaAPI DocGlassfish v2 API9169Fri May 25 01:19:40 BST 2007com.sun.enterprise.jbi.serviceengine.core

JBIDescriptorReader

public class JBIDescriptorReader extends Object
This class reads the SU jbi.xml and loads up the values.
author
Sun Microsystems

Fields Summary
private Document
mDoc
Document object of the XML config file.
private DescriptorEndpointInfo[]
mEPList
List of endpoints in the SU jbi.xml.
private int
mNoOfConsumers
Number of consumers.
private int
mNoOfProviders
Number of providers.
private String
mType
Type of deployment, WSDL, XML or WSDL11
private String
mSu_Name
private EndpointRegistry
registry
private static final String
prefix_NS
private static final String
ept_Mappings
private Map
wsdlEndpts
private Map
jbiEndpts
Constructors Summary
JBIDescriptorReader(String su_Name)
Creates a new ConfigReader object.


              
      
        mSu_Name = su_Name;
    
Methods Summary
intgetConsumerCount()
Returns the number of consumer endpoints.

return
consumer endpoint count.

        return mNoOfConsumers;
    
DescriptorEndpointInfo[]getEndpoints()

        return mEPList;
    
private java.lang.StringgetLocalName(java.lang.String qname)
Gets the local name from the quname.

param
qname Qualified name of service.
return
String local name

        StringTokenizer tok = new StringTokenizer(qname, ":");

        if (tok.countTokens() == 1) {
            return qname;
        }
        tok.nextToken();

        return tok.nextToken();
    
private java.lang.StringgetNamespace(java.lang.String qname)
Gets the namespace from the qname.

param
qname Qname of service
return
namespace namespace of service

        StringTokenizer tok = new StringTokenizer(qname, ":");
        String prefix;

        if (tok.countTokens() == 1) {
            return "";
        }
        prefix = tok.nextToken();

        NamedNodeMap map = mDoc.getDocumentElement().getAttributes();
        for (int j = 0; j < map.getLength(); j++) {
            Node n = map.item(j);

            if (n.getLocalName().trim().equals(prefix.trim())) {
                return n.getNodeValue();
            }
        }

        return "";
    
intgetProviderCount()
Returns the number of provider endpoints.

return
provider endpoint count.

        return mNoOfProviders;
    
java.lang.StringgetType()
Gets the type of artifact

        return mType;
    
voidinit(org.w3c.dom.Document doc)
Initializes the config file and loads services.

param
doc Name of the config file.

        mDoc = doc;
        mDoc.getDocumentElement().normalize();
        load();
    
voidload()
Loads the data.

        NodeList providers = mDoc.getElementsByTagName("provides");
        mNoOfProviders = providers.getLength();

        NodeList consumers = mDoc.getElementsByTagName("consumes");
        mNoOfConsumers = consumers.getLength();
        mEPList = new DescriptorEndpointInfo[mNoOfConsumers + mNoOfProviders];
        setArtifacts();
        for (int i = 0; i < mNoOfProviders; i++) {
            Node node = providers.item(i);
            DescriptorEndpointInfo sb = new DescriptorEndpointInfo(mSu_Name);
            setEndpoint(node, sb);
            sb.setProvider();
            mEPList[i] = sb;
        }

        for (int i = 0; i < mNoOfConsumers; i++) {
            Node node = consumers.item(i);
            DescriptorEndpointInfo sb = new DescriptorEndpointInfo(mSu_Name);
            setEndpoint(node, sb);
            mEPList[i + mNoOfProviders] = sb;
        }

        NodeList eptMappings = mDoc.getElementsByTagNameNS(prefix_NS, ept_Mappings);
        if(eptMappings.getLength() > 0)
            eptMappings = eptMappings.item(0).getChildNodes();
        for(int i = 0; i < eptMappings.getLength(); i++) {
            if(!eptMappings.item(i).getNodeName().contains("ept-mapping"))
                continue;
            NodeList nList = eptMappings.item(i).getChildNodes();
            DescriptorEndpointInfo dei = new DescriptorEndpointInfo(mSu_Name);
            DescriptorEndpointInfo dei1 = new DescriptorEndpointInfo(mSu_Name);
            for (int j = 0; j < nList.getLength(); j++) {
                Node node = nList.item(j);
                if(node.getNodeName().contains("java-ept")) {
                    setEndpoint(node, dei);
                    String type =
                            node.getAttributes().getNamedItem("type").getNodeValue();
                    if(type.equals("provider")) {
                        dei.setProvider();
                        dei1.setProvider();
                    }
                } else if(node.getNodeName().contains("wsdl-ept"))
                    setEndpoint(node, dei1);
            }
            wsdlEndpts.put(dei.getKey(), dei1);
            jbiEndpts.put(dei1.getKey(), dei);
        }

        if (!wsdlEndpts.isEmpty()) {
            for (int i = 0; i < mEPList.length; i++) {
                DescriptorEndpointInfo dei = mEPList[i];
                if(wsdlEndpts.get(dei.getKey())!=null)
                    mEPList[i] = wsdlEndpts.get(dei.getKey());
            }
        }
    
private voidsetArtifacts()

        NodeList namelist = mDoc.getElementsByTagNameNS("*", "artifactstype");

        if (namelist == null) {
            /* This means the tag is not present. default type is WSDL20
             */
            setType("WSDL20");
            return;
        }

        Element name = (Element) namelist.item(0);
        String sValue;

        try {
            sValue = (name.getChildNodes().item(0)).getNodeValue().trim();
        } catch (NullPointerException ne) {
            setType("WSDL20");
            return;
        }

        setType(sValue);
    
private voidsetEndpoint(org.w3c.dom.Node node, DescriptorEndpointInfo ep)
Sets the endpoitn attributes.

param
node provider/consumer node.
param
ep endpoint information.

        NamedNodeMap map = node.getAttributes();

        String epname = map.getNamedItem("endpoint-name").getNodeValue();
        String sername = map.getNamedItem("service-name").getNodeValue();
        String intername = map.getNamedItem("interface-name").getNodeValue();
        ep.setServiceName(new QName(getNamespace(sername), getLocalName(sername)));
        ep.setInterfaceName(new QName(getNamespace(intername), getLocalName(intername)));
        ep.setEndpointName(epname);
    
private voidsetType(java.lang.String type)
Sets the type of artifact.

        mType = type;