Package org.wsdmdemo.service.weatherStationDir

Source Code of org.wsdmdemo.service.weatherStationDir.WeatherStationDirResource

package org.wsdmdemo.service.weatherStationDir;

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.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.properties.ResourceProperty;
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 java.net.URL;

/**
* **** NOTE: This file will not be overwritten during generation ****
* <p/>
* A WeatherStationDir WS-Resource.
* <p/>
* NOTE: This class is generated but IS meant to be modified.
*/
public class WeatherStationDirResource extends AbstractWeatherStationDirResource

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

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

            //manageability
            resourceProperty.addChangeListener(manageabilityCharacteristicsCapability);
            /** END CAPABILITIES **/

            /** RESOURCE PROPERTIES **/
            // init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd}ResourceId Resource Property
            resourceProperty = resourcePropertySet.get(WeatherStationDirPropertyQNames.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(InteropConstants.DIR_RESOURCEID);//singleton
            resourceProperty.addChangeListener(identityCapability);
            resourceProperty.add(prop_resourceid);

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

            /** END RESOURCE PROPERTIES **/
        }
        catch (Exception e)
        {
            e.printStackTrace();
            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.




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

    /**
     * Initializes the default relationships
     *
     * @param resourceProperty
     * @throws Exception
     */
    private void initRelationships(ResourceProperty resourceProperty) throws Exception
    {
        org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType ws1Epr = InteropRequestUtils.getEndpointReference(new URL(InteropConstants.WEATHER_STATION_1_EPR_URL)).getEndpointReference();
        org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType ws2Epr = InteropRequestUtils.getEndpointReference(new URL(InteropConstants.WEATHER_STATION_2_EPR_URL)).getEndpointReference();
        addRelation(resourceProperty, ws1Epr);
        addRelation(resourceProperty, ws2Epr);
    }

    /**
     * Adds a relationship to this resource with a given epr as the child relation
     *
     * @param resourceProperty
     * @param childEpr
     */
    private void addRelation(ResourceProperty resourceProperty, EndpointReferenceType childEpr)
    {
        //define a relationship
        RelationshipDocument relationshipDocument = RelationshipDocument.Factory.newInstance();
        RelationshipType relationshipType = InteropRequestUtils.createRelationshipType(relationshipDocument.addNewRelationship());

        //add self as a participant
        RelationshipParticipantType parentRelationshipParticipantType = relationshipType.addNewParticipant();
        XmlBeansEndpointReference dirEpr = (XmlBeansEndpointReference) getEndpointReference();
        EndpointReferenceType dirEndpointReferenceType = (EndpointReferenceType) dirEpr.getXmlObject(AddressingConstants.NSURI_ADDRESSING_SCHEMA);
        parentRelationshipParticipantType.setResourceId(InteropConstants.DIR_RESOURCEID);
        parentRelationshipParticipantType.setRole(InteropConstants.PARENT_RELATION);//uri
        parentRelationshipParticipantType.setManageabilityEndpointReferenceArray(new EndpointReferenceType[]{dirEndpointReferenceType});


        //add the new ws as the other participant
        RelationshipParticipantType childRelationshipParticipantType = relationshipType.addNewParticipant();
        System.out.println("Getting the Resource ID for the EPR: " + childEpr.getAddress().getStringValue());
        String resourceId = InteropRequestUtils.getResourceId(childEpr);
        if(resourceId == null)
        {
            resourceId = "UNKNOWN";
        }
        childRelationshipParticipantType.setResourceId(resourceId);
        childRelationshipParticipantType.setRole(InteropConstants.CHILD_RELATION);//uri
        childRelationshipParticipantType.setManageabilityEndpointReferenceArray(new EndpointReferenceType[]{childEpr});

        resourceProperty.add(relationshipDocument);
    }

}
TOP

Related Classes of org.wsdmdemo.service.weatherStationDir.WeatherStationDirResource

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.