Package org.wsdmdemo.service.weatherClientConfig

Source Code of org.wsdmdemo.service.weatherClientConfig.WeatherClientConfigResource

package org.wsdmdemo.service.weatherClientConfig;

import org.apache.ws.Soap1_1Constants;
import org.apache.ws.addressing.XmlBeansEndpointReference;
import org.apache.ws.addressing.v2004_08_10.AddressingConstants;
import org.apache.ws.muws.v1_0.MuwsConstants;
import org.apache.ws.muws.v1_0.capability.IdentityCapability;
import org.apache.ws.muws.v1_0.capability.ManageabilityCharacteristicsCapability;
import org.apache.ws.muws.v1_0.capability.OperationalStatusCapability;
import org.apache.ws.muws.v1_0.capability.RelationshipsCapability;
import org.apache.ws.muws.v1_0.topics.ManagementEventTopic;
import org.apache.ws.muws.v1_0.topics.impl.XmlBeansManagementEventTopicImpl;
import org.apache.ws.notification.topics.TopicSpace;
import org.apache.ws.notification.topics.impl.TopicSpaceImpl;
import org.apache.ws.resource.PropertiesResource;
import org.apache.ws.resource.ResourceException;
import org.apache.ws.resource.faults.FaultException;
import org.apache.ws.resource.properties.ResourceProperty;
import org.apache.ws.resource.properties.ResourcePropertySet;
import org.apache.ws.resource.properties.SetResourcePropertyCallback;
import org.apache.ws.resource.properties.impl.CallbackFailedException;
import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.OperationalStatusDocument;
import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.RelationshipDocument;
import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.RelationshipParticipantType;
import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.RelationshipType;
import org.wsdmdemo.service.InteropConstants;
import org.wsdmdemo.service.InteropRequestUtils;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;

import javax.xml.namespace.QName;
import java.net.MalformedURLException;
import java.net.URL;

/**
* **** NOTE: This file will not be overwritten during generation ****
* <p/>
* A WeatherClientConfig WS-Resource.
* <p/>
* NOTE: This class is generated but IS meant to be modified.
*/
public class WeatherClientConfigResource extends AbstractWeatherClientConfigResource implements SetResourcePropertyCallback

{

    /**
     * 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();

    /**
     * Initializes this resource's state (properties, etc.).
     */
    public void init()
    {
        super.init();              

        /**
         * The ResourcePropertySet which contains all the defined ResourceProperties
         */
        org.apache.ws.resource.properties.ResourcePropertySet resourcePropertySet = getResourcePropertySet();
        org.apache.ws.resource.properties.ResourceProperty resourceProperty = null;


        try
        {

            /** TOPICS **/
            TopicSpace muwsTopicSpace = new TopicSpaceImpl(MuwsConstants.NSURI_MUWS_PART2_TOPICS);
            getTopicSpaceSet().addTopicSpace(muwsTopicSpace);

            //identity
            ManagementEventTopic identityCapability = new XmlBeansManagementEventTopicImpl(IdentityCapability.TOPIC_NAME);
            muwsTopicSpace.addTopic(identityCapability);
            //manageability
            ManagementEventTopic manageabilityCharacteristicsCapability = new XmlBeansManagementEventTopicImpl(ManageabilityCharacteristicsCapability.TOPIC_NAME);
            muwsTopicSpace.addTopic(manageabilityCharacteristicsCapability);

            //operational status
            ManagementEventTopic operationalCapability = new XmlBeansManagementEventTopicImpl(OperationalStatusCapability.TOPIC_NAME);
            muwsTopicSpace.addTopic(operationalCapability);

            //relationships
            ManagementEventTopic relationshipCapability = new XmlBeansManagementEventTopicImpl(RelationshipsCapability.TOPIC_NAME);
            muwsTopicSpace.addTopic(relationshipCapability);
            /** END TOPICS **/


            /** CAPABILITIES **/
            // init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd}ManageabilityCapability Resource Property
            resourceProperty = resourcePropertySet.get(WeatherClientConfigPropertyQNames.MANAGEABILITYCAPABILITY);

            //identity
            org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManageabilityCapabilityDocument prop_manageabilitycapability = org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManageabilityCapabilityDocument.Factory.newInstance();
            prop_manageabilitycapability.setManageabilityCapability(IdentityCapability.URI);
            resourceProperty.add(prop_manageabilitycapability);

            //operational status
            prop_manageabilitycapability = org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManageabilityCapabilityDocument.Factory.newInstance();
            prop_manageabilitycapability.setManageabilityCapability(OperationalStatusCapability.URI);
            resourceProperty.add(prop_manageabilitycapability);

            //relationships
            prop_manageabilitycapability = org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManageabilityCapabilityDocument.Factory.newInstance();
            prop_manageabilitycapability.setManageabilityCapability(RelationshipsCapability.URI);
            resourceProperty.add(prop_manageabilitycapability);

            resourceProperty.addChangeListener(manageabilityCharacteristicsCapability);
            resourceProperty.add(prop_manageabilitycapability);
            /** END CAPABILITIES **/


            /** RESOURCE PROPERTIES **/
            // init the {http://wsdmdemo.org/service/weather-client-config}WeatherStationReference Resource Property
            resourceProperty = resourcePropertySet.get(WeatherClientConfigPropertyQNames.WEATHERSTATIONREFERENCE);
            org.wsdmdemo.service.weatherClientConfig.WeatherStationReferenceDocument prop_weatherstationreference = org.wsdmdemo.service.weatherClientConfig.WeatherStationReferenceDocument.Factory.newInstance();
            prop_weatherstationreference.setWeatherStationReference(getWeatherStationEPR());
            resourceProperty.add(prop_weatherstationreference);
            resourceProperty.setCallback(this);


            // init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd}ResourceId Resource Property
            resourceProperty = resourcePropertySet.get(WeatherClientConfigPropertyQNames.RESOURCEID);
            org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ResourceIdDocument prop_resourceid = org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ResourceIdDocument.Factory.newInstance();
            prop_resourceid.setResourceId("urn:" + getID());
            resourceProperty.addChangeListener(identityCapability);
            resourceProperty.add(prop_resourceid);


            // init the {http://wsdmdemo.org/service/weather-client-config}WeatherDataRefreshInterval Resource Property
            resourceProperty = resourcePropertySet.get(WeatherClientConfigPropertyQNames.WEATHERDATAREFRESHINTERVAL);
            org.wsdmdemo.service.weatherClientConfig.WeatherDataRefreshIntervalDocument prop_weatherdatarefreshinterval = org.wsdmdemo.service.weatherClientConfig.WeatherDataRefreshIntervalDocument.Factory.newInstance();
            prop_weatherdatarefreshinterval.setWeatherDataRefreshInterval(InteropConstants.INITIAL_REFRESH);
            resourceProperty.add(prop_weatherdatarefreshinterval);


            // init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.xsd}OperationalStatus Resource Property
            resourceProperty = resourcePropertySet.get(WeatherClientConfigPropertyQNames.OPERATIONALSTATUS);
            org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.OperationalStatusDocument prop_operationalstatus = org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.OperationalStatusDocument.Factory.newInstance();
            prop_operationalstatus.setOperationalStatus(OperationalStatusDocument.OperationalStatus.AVAILABLE);
            resourceProperty.addChangeListener(operationalCapability);
            resourceProperty.add(prop_operationalstatus);

            // init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.xsd}Relationship Resource Property
            resourceProperty = resourcePropertySet.get(WeatherClientConfigPropertyQNames.RELATIONSHIP);
            resourceProperty.addChangeListener(relationshipCapability);
            /** END RESOURCE PROPERTIES **/

        }
        catch (Exception e)
        {
            throw new javax.xml.rpc.JAXRPCException("There was a problem in initializing your resource properties.  Please check your init() method. Cause: " + e.getLocalizedMessage());
        }
        // Resource Property {http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd}FixedTopicSet is implemented by the framework.
        // Resource Property {http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd}Topic is implemented by the framework.
        // Resource Property {http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd}TopicExpressionDialects is implemented by the framework.



        /**
         * This method call will make all resource properties be exposed
         * as Topics.  If you would like to change that behaviour you can
         * call TopicUtils.addResourcePropertyValueChangeTopic for each
         * Topic you'd like to expose property change notifications for.
         */
        try
        {
            org.apache.ws.notification.topics.util.TopicUtils.addResourcePropertyValueChangeTopics(getResourcePropertySet(), getTopicSpaceSet());
        }
        catch (Exception e)
        {
            e.printStackTrace();
            throw new FaultException(Soap1_1Constants.FAULT_SERVER, "Unable to init the ResourceProperty Changed topics. Cause: " + e.getLocalizedMessage());
        }

        /**
         * Initializes the Topic, TopicExpressionDialects and FixedTopicSet resource properties
         *
         * </br>
         * <strong>NOTE this MUST be called last in the Resource.init() method to ensure all topics get registered</strong>
         * </br>
         * FixedTopicSet will be set based on the value returned from the {@see TopicSpaceSet#isFixed()} method.
         * </br>
         * Topic will have all root topics in the TopicSpaceSet, set to Simple dialect AND all child topics set ot
         * Concrete dialect.
         * </br>
         *
         * TopicExpressionDialects will be set to the engine's known Topic Dialects acquired from the TopicExpressionEngine
         *
         * @param topicSpaceSet
         * @param propSet
         */
        org.apache.ws.notification.topics.util.TopicUtils.initNotificationProducerProperties(getTopicSpaceSet(), getResourcePropertySet());
    }

    private EndpointReferenceType getWeatherStationEPR() throws Exception, ResourceException, MalformedURLException
    {
        return InteropRequestUtils.getEndpointReference(new URL(InteropConstants.WEATHER_STATION_1_EPR_URL)).getEndpointReference();
    }

    /**
     * Implement this method for handling "delete" on the backend.
     *
     * @param propQName
     * @throws CallbackFailedException An exception if the delete fails on the backend
     *                                 and you want the server to return a fault.
     */
    public void deleteProperty(QName propQName) throws CallbackFailedException
    {

    }

    /**
     * Implement this method for handling "insert" on the backend.
     *
     * @param propElems
     * @throws CallbackFailedException An exception if the insert fails on the backend
     *                                 and you want the server to return a fault.
     */
    public void insertProperty(Object[] propElems) throws CallbackFailedException
    {
        if (propElems.length == 1)
        {
            //get the request epr
            EndpointReferenceType weatherStationEpr = (EndpointReferenceType) propElems[0];
            ResourcePropertySet resourcePropertySet = ((PropertiesResource) this).getResourcePropertySet();
            ResourceProperty resourceProperty = resourcePropertySet.get(WeatherClientConfigPropertyQNames.RELATIONSHIP);

            //define a relationship
            RelationshipDocument relationshipDocument = RelationshipDocument.Factory.newInstance();
            RelationshipType relationshipType = InteropRequestUtils.createRelationshipType(relationshipDocument.addNewRelationship());

            //add self as a participant
            RelationshipParticipantType parentRelationshipParticipantType = relationshipType.addNewParticipant();
            XmlBeansEndpointReference xmlEpr = (XmlBeansEndpointReference) this.getEndpointReference();
            EndpointReferenceType configEndpointReferenceType = (EndpointReferenceType) xmlEpr.getXmlObject(AddressingConstants.NSURI_ADDRESSING_SCHEMA);
            parentRelationshipParticipantType.setResourceId("urn:" + getID());
            parentRelationshipParticipantType.setRole(InteropConstants.PARENT_RELATION);//uri
            parentRelationshipParticipantType.setManageabilityEndpointReferenceArray(new EndpointReferenceType[]{configEndpointReferenceType});


            //add the new ws as the other participant
            RelationshipParticipantType childRelationshipParticipantType = relationshipType.addNewParticipant();
            childRelationshipParticipantType.setResourceId(InteropRequestUtils.getResourceId(weatherStationEpr));
            childRelationshipParticipantType.setResourceId(InteropConstants.WS1_KEY);
            childRelationshipParticipantType.setRole(InteropConstants.CHILD_RELATION);//uri
            childRelationshipParticipantType.setManageabilityEndpointReferenceArray(new EndpointReferenceType[]{weatherStationEpr});

            resourceProperty.clear();           
            resourceProperty.add(relationshipDocument);

        }
        else
        {
            throw new CallbackFailedException("There was more than one reference passed!");
        }
    }

    /**
     * Implement this method for handling "update" on the backend.
     *
     * @param propElems
     * @throws CallbackFailedException An exception if the update fails on the backend
     *                                 and you want the server to return a fault.
     */
    public void updateProperty(Object[] propElems) throws CallbackFailedException
    {
        insertProperty(propElems);
    }

    /**
     * This method is called by the all of the WSRP PortType impls, prior
     * to performing any work, in order to ensure the resource properties
     * accurately reflect the current state of the managed resource.
     *
     * @param prop the property to be refreshed
     * @return the refreshed property
     * @throws CallbackFailedException An exception if the refresh fails on the backend
     *                                 and you want the server to return a fault instead of the current stored value.
     */
    public ResourceProperty refreshProperty(ResourceProperty prop) throws CallbackFailedException
    {
        return null;
    }
}
TOP

Related Classes of org.wsdmdemo.service.weatherClientConfig.WeatherClientConfigResource

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.