Package org.wsdmdemo.service.weatherStation

Source Code of org.wsdmdemo.service.weatherStation.WeatherStationHome

package org.wsdmdemo.service.weatherStation;

import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.resource.Resource;
import org.apache.ws.resource.ResourceContext;
import org.apache.ws.resource.ResourceContextException;
import org.apache.ws.resource.ResourceException;
import org.apache.ws.resource.ResourceKey;
import org.apache.ws.resource.ResourceUnknownException;
import org.apache.ws.resource.impl.AbstractResourceHome;
import org.wsdmdemo.service.InteropConstants;

import javax.xml.namespace.QName;
import java.io.Serializable;

/**
* **** NOTE: This file will not be overwritten during generation ****
* <p/>
* Home for WeatherStation WS-Resources.
*/
public class WeatherStationHome
        extends AbstractResourceHome
        implements Serializable
{

    /**
     * The service endpoint name as registered with the SOAP Platform.  This is useful for building EPR's. *
     */
    public static final QName SERVICE_NAME = javax.xml.namespace.QName.valueOf("{http://wsdmdemo.org/service/weather-station}WeatherStation");

    /**
     * The management PortType associated with this resource. This is useful for building EPR's.*
     */
    public static final QName PORT_TYPE = javax.xml.namespace.QName.valueOf("{http://wsdmdemo.org/service/weather-station}WeatherStationPortType");

    /**
     * The WSDL Port name associated with the resource. This is useful for building EPR's. *
     */
    public static final String PORT_NAME = "weather-station";

    /**
     * The name of the resource key for this resource. *
     */
    public static final QName RESOURCE_KEY_NAME = javax.xml.namespace.QName.valueOf("{http://wsdmdemo.org/service/weather-station}ResourceIdentifier");

    /**
     * A NamespaceVerionHolder which maintains the QNames of Spec Wsdls
     */
    public static final org.apache.ws.muws.v1_0.impl.WsdmNamespaceVersionHolderImpl SPEC_NAMESPACE_SET = new org.apache.ws.muws.v1_0.impl.WsdmNamespaceVersionHolderImpl();
    /**
     * A constant for the JNDI Lookup name for this home. *
     */
    public static final String HOME_LOCATION =
            org.apache.ws.resource.JndiConstants.CONTEXT_NAME_SERVICES + "/" + SERVICE_NAME.getLocalPart() + "/" + org.apache.ws.resource.JndiConstants.ATOMIC_NAME_HOME;

    private static Object m_lock = new Object();

    public WeatherStationHome()
    {

    }

    /**
     * DOCUMENT_ME
     *
     * @throws Exception DOCUMENT_ME
     */
    public synchronized void init() throws Exception
    {
        super.init();
    }

    /**
     * @param resourceContext
     * @return A Resource
     * @throws ResourceException
     * @throws ResourceContextException
     * @throws ResourceUnknownException
     */
    public Resource getInstance(ResourceContext resourceContext)
            throws ResourceException,
                   ResourceContextException,
                   ResourceUnknownException
    {
        ResourceKey key = resourceContext.getResourceKey();
        Resource resource = null;
        try
        {
            synchronized (m_lock)
            {
                resource = find(key); //attempt to find from the underlying cache
            }
        }
        catch (ResourceException re)
        {
            Object id = key.getValue();
            if (InteropConstants.WS1_KEY.equals(id) || InteropConstants.WS2_KEY.equals(id))
            {
                String name = null;
                if(InteropConstants.WS1_KEY.equals(id))
                {
                    name = "Space Co.";
                }
                else
                {
                    name = "NASA";
                }
                try
                {
                    WeatherStationResource myresource = (WeatherStationResource) createInstance(key); //this will create the resource IF it is has default constructor. It also calls init() on the resource.
                    myresource.setName(name);
                    //the next line will create an EPR
                    EndpointReference epr = getEndpointReference(resourceContext.getBaseURL() + "/" + getServiceName().getLocalPart(), key, SPEC_NAMESPACE_SET.getAddressingNamespace());
                    myresource.setEndpointReference(epr); //make sure to set the EPR on your new instance
                    add(key, myresource); //make sure to add your instance to the underlying cache to be found in future requests using find(..)
                }
                catch (Exception e)
                {
                    throw new ResourceException(e);
                }
            }
            else
            {
                throw new ResourceUnknownException(id,
                                                   resourceContext.getServiceName());
            }
        }

        return resource;
    }


    public QName getServiceName()
    {
        return SERVICE_NAME;
    }

    public QName getPortType()
    {
        return PORT_TYPE;
    }

    public String getServicePortName()
    {
        return PORT_NAME;
    }

    public QName getResourceKeyNameQName()
    {
        return RESOURCE_KEY_NAME;
    }
}
TOP

Related Classes of org.wsdmdemo.service.weatherStation.WeatherStationHome

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.