/*=============================================================================*
* Copyright 2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*=============================================================================*/
package org.apache.ws.muse.example.host;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.mows.v1_0.MowsConstants;
import org.apache.ws.mows.v1_0.capability.MetricsCapability;
import org.apache.ws.muse.example.ExampleConstants;
import org.apache.ws.muse.example.application.ApplicationPropertyQNames;
import org.apache.ws.muse.example.host.backend.HostInstance;
import org.apache.ws.muse.example.host.callback.AvailableMemoryCallback;
import org.apache.ws.muse.example.host.callback.CpuUsageCallback;
import org.apache.ws.muse.example.host.callback.HostNameCallback;
import org.apache.ws.muse.example.host.callback.NumProcessesCallback;
import org.apache.ws.muse.example.resourceadmin.properties.CreateParamsType;
import org.apache.ws.muws.v1_0.MuwsConstants;
import org.apache.ws.muws.v1_0.capability.DescriptionCapability;
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.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.TopicSpaceSet;
import org.apache.ws.notification.topics.impl.TopicSpaceImpl;
import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManageabilityCapabilityDocument;
import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.CurrentTimeDocument;
import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.LangString;
import java.util.Calendar;
/**
* @author Kinga Dziembowski
*
* A Host WS-Resource.
* <p/>
* NOTE: This class is generated but IS meant to be modified.
*/
public class HostResource
extends AbstractHostResource
{
/**
* 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( );
/** The value for the ImplementationProfile property **/
public static final String RESOURCE_TYPE = "HostMachine";
/** The value for the Caption property **/
public static final String CAPTION = "Host";
/** The value for the Version property **/
public static final String VERSION = "1.0";
/** The value for the Description property */
public static final String DESCRIPTION = "Host Resource";
/** A resource variable to hold the reference for backend */
private HostInstance m_instance = null;
/** A log object */
private static final Log LOG = LogFactory.getLog( HostResource.class.getName() );
/**
* Creates a new {@link HostResource} object.
*
* @param resourceId DOCUMENT_ME
* @param params DOCUMENT_ME
*/
public HostResource( Object resourceId,
CreateParamsType params )
{
setID( resourceId );
// params can have any important information for the creation of Resource
// in this example it is not used
}
/**
* 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
{
// create the backend object associated with this resource
m_instance = new HostInstance( getID( ).toString( ) );
TopicSpaceSet aSet = getTopicSpaceSet( );
//MUWS TopicSpace
TopicSpace muwsTopicSpace = new TopicSpaceImpl( MuwsConstants.NSURI_MUWS_PART2_TOPICS );
aSet.addTopicSpace( muwsTopicSpace );
ManagementEventTopic identityCapability =
new XmlBeansManagementEventTopicImpl( IdentityCapability.TOPIC_NAME );
muwsTopicSpace.addTopic( identityCapability );
ManagementEventTopic manageabilityCharacteristicsCapability =
new XmlBeansManagementEventTopicImpl( ManageabilityCharacteristicsCapability.TOPIC_NAME );
muwsTopicSpace.addTopic( manageabilityCharacteristicsCapability );
ManagementEventTopic muwsDescriptionCapability =
new XmlBeansManagementEventTopicImpl( DescriptionCapability.TOPIC_NAME );
muwsTopicSpace.addTopic( muwsDescriptionCapability );
ManagementEventTopic metricCapability =
new XmlBeansManagementEventTopicImpl( MetricsCapability.TOPIC_NAME );
muwsTopicSpace.addTopic( metricCapability );
//MOWS TopicSpace
TopicSpace mowsTopicSpace = new TopicSpaceImpl( MowsConstants.NSURI_MOWS_TOPICS );
getTopicSpaceSet( ).addTopicSpace( mowsTopicSpace );
ManagementEventTopic mowsMetricsCapability =
new XmlBeansManagementEventTopicImpl( MetricsCapability.TOPIC_NAME );
mowsTopicSpace.addTopic( mowsMetricsCapability );
// init the {http://ws.apache.org/muse/example/host/properties}CpuUsage Resource Property
resourceProperty = resourcePropertySet.get( HostPropertyQNames.CPUUSAGE );
org.apache.ws.muse.example.host.properties.CpuUsageDocument prop_cpuusage =
org.apache.ws.muse.example.host.properties.CpuUsageDocument.Factory.newInstance( );
org.apache.ws.namespaces.muse.muwsExt1.IntMetric cpuMetric =
org.apache.ws.namespaces.muse.muwsExt1.IntMetric.Factory.newInstance( );
cpuMetric.setIntValue( m_instance.getCPUUsage( ) );
Calendar calendarInst = Calendar.getInstance( );
cpuMetric.setLastUpdated( calendarInst );
prop_cpuusage.setCpuUsage( cpuMetric );
resourceProperty.add( prop_cpuusage );
resourceProperty.setCallback( new CpuUsageCallback( m_instance ) );
// init the {http://ws.apache.org/muse/example/host/properties}AvailableMemory Resource Property
resourceProperty = resourcePropertySet.get( HostPropertyQNames.AVAILABLEMEMORY );
org.apache.ws.muse.example.host.properties.AvailableMemoryDocument prop_availablememory =
org.apache.ws.muse.example.host.properties.AvailableMemoryDocument.Factory.newInstance( );
org.apache.ws.namespaces.muse.muwsExt1.LongMetric availableMemory =
org.apache.ws.namespaces.muse.muwsExt1.LongMetric.Factory.newInstance( );
availableMemory.setLongValue( m_instance.getAvailablememory( ) );
availableMemory.setLastUpdated( calendarInst );
prop_availablememory.setAvailableMemory( availableMemory );
resourceProperty.add( prop_availablememory );
resourceProperty.setCallback( new AvailableMemoryCallback( m_instance ) );
// init the {http://ws.apache.org/muse/example/host/properties}NumberOfProcesses Resource Property
resourceProperty = resourcePropertySet.get( HostPropertyQNames.NUMBEROFPROCESSES );
org.apache.ws.muse.example.host.properties.NumberOfProcessesDocument prop_numberofprocesses =
org.apache.ws.muse.example.host.properties.NumberOfProcessesDocument.Factory.newInstance( );
org.apache.ws.namespaces.muse.muwsExt1.IntMetric numberOfProcesses =
org.apache.ws.namespaces.muse.muwsExt1.IntMetric.Factory.newInstance( );
numberOfProcesses.setIntValue( m_instance.getNumberOfprocesses( ) );
numberOfProcesses.setLastUpdated( calendarInst );
prop_numberofprocesses.setNumberOfProcesses( numberOfProcesses );
resourceProperty.add( prop_numberofprocesses );
resourceProperty.setCallback( new NumProcessesCallback( m_instance ) );
// init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd}ResourceId Resource Property
resourceProperty = resourcePropertySet.get( HostPropertyQNames.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( getID( ).toString( ) );
resourceProperty.add( prop_resourceid );
resourceProperty.addChangeListener( identityCapability );
// init the {http://org.apache.ws.namespaces.muse.muwsExt1}ResourceHostname Resource Property
resourceProperty = resourcePropertySet.get( HostPropertyQNames.RESOURCEHOSTNAME );
org.apache.ws.namespaces.muse.muwsExt1.ResourceHostnameDocument prop_resourcehostname =
org.apache.ws.namespaces.muse.muwsExt1.ResourceHostnameDocument.Factory.newInstance( );
prop_resourcehostname.setResourceHostname( m_instance.getHostName( ) );
resourceProperty.add( prop_resourcehostname );
resourceProperty.setCallback( new HostNameCallback( m_instance ) );
// init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.xsd}Version Resource Property
resourceProperty = resourcePropertySet.get( HostPropertyQNames.VERSION );
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.VersionDocument prop_version =
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.VersionDocument.Factory.newInstance( );
prop_version.setVersion( VERSION );
resourceProperty.add( prop_version );
resourceProperty.addChangeListener( muwsDescriptionCapability );
// init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.xsd}Caption Resource Property
resourceProperty = resourcePropertySet.get( HostPropertyQNames.CAPTION );
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.CaptionDocument prop_caption =
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.CaptionDocument.Factory.newInstance( );
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.LangString lStringC =
LangString.Factory.newInstance( );
lStringC.setStringValue( CAPTION + "-" + getID( ).toString( ) );
lStringC.setLang( "en" );
prop_caption.setCaption( lStringC );
resourceProperty.add( prop_caption );
resourceProperty.addChangeListener( muwsDescriptionCapability );
// init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd}ManageabilityCapability Resource Property
resourceProperty = resourcePropertySet.get( ApplicationPropertyQNames.MANAGEABILITYCAPABILITY );
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 );
resourceProperty.addChangeListener( manageabilityCharacteristicsCapability );
prop_manageabilitycapability = ManageabilityCapabilityDocument.Factory.newInstance( );
prop_manageabilitycapability.setManageabilityCapability( org.apache.ws.muws.v1_0.capability.MetricsCapability.URI );
resourceProperty.add( prop_manageabilitycapability );
prop_manageabilitycapability = ManageabilityCapabilityDocument.Factory.newInstance( );
prop_manageabilitycapability.setManageabilityCapability( DescriptionCapability.URI );
resourceProperty.add( prop_manageabilitycapability );
prop_manageabilitycapability = ManageabilityCapabilityDocument.Factory.newInstance( );
prop_manageabilitycapability.setManageabilityCapability( MetricsCapability.URI );
resourceProperty.add( prop_manageabilitycapability );
prop_manageabilitycapability = ManageabilityCapabilityDocument.Factory.newInstance( );
prop_manageabilitycapability.setManageabilityCapability( ExampleConstants.MUWS_EXT_CAPABILITY_URI );
resourceProperty.add( prop_manageabilitycapability );
resourceProperty.addChangeListener( manageabilityCharacteristicsCapability );
// init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.xsd}Description Resource Property
resourceProperty = resourcePropertySet.get( HostPropertyQNames.DESCRIPTION );
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.DescriptionDocument prop_description =
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.DescriptionDocument.Factory.newInstance( );
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.LangString lString =
LangString.Factory.newInstance( );
lString.setStringValue( DESCRIPTION );
lString.setLang( "en" );
prop_description.setDescription( lString );
resourceProperty.add( prop_description );
resourceProperty.addChangeListener( muwsDescriptionCapability );
// init the {http://ws.apache.org/muse/example/shared}ResourceType Resource Property
resourceProperty = resourcePropertySet.get( HostPropertyQNames.RESOURCETYPE );
org.apache.ws.namespaces.muse.muwsExt1.ResourceTypeDocument prop_resourcetype =
org.apache.ws.namespaces.muse.muwsExt1.ResourceTypeDocument.Factory.newInstance( );
prop_resourcetype.setResourceType( RESOURCE_TYPE );
resourceProperty.add( prop_resourcetype );
//init the {http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.xsd}CurrentTime ResourceProperty
resourceProperty = resourcePropertySet.get( HostPropertyQNames.CURRENTTIME );
CurrentTimeDocument currentTimeDocument = CurrentTimeDocument.Factory.newInstance( );
currentTimeDocument.setCurrentTime( Calendar.getInstance( ) );
resourceProperty.add( currentTimeDocument );
resourceProperty.setCallback( new org.apache.ws.resource.lifetime.callback.CurrentTimeCallback( ) );
resourceProperty.addChangeListener( metricCapability );
// init the {http://ws.apache.org/namespaces/muse/muws-ext-1.xsd}Owner Resource Property
resourceProperty = resourcePropertySet.get(HostPropertyQNames.OWNER);
org.apache.ws.namespaces.muse.muwsExt1.OwnerDocument prop_owner = org.apache.ws.namespaces.muse.muwsExt1.OwnerDocument.Factory.newInstance();
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.LangString oString = LangString.Factory.newInstance( );
oString.setStringValue( ExampleConstants.HOST_OWNER);
oString.setLang( "en" );
prop_owner.setOwner( oString );
resourceProperty.add(prop_owner);
// init the {http://ws.apache.org/namespaces/muse/muws-ext-1.xsd}CreationTime Resource Property
resourceProperty = resourcePropertySet.get(HostPropertyQNames.CREATIONTIME);
org.apache.ws.namespaces.muse.muwsExt1.CreationTimeDocument prop_creationtime = org.apache.ws.namespaces.muse.muwsExt1.CreationTimeDocument.Factory.newInstance();
prop_creationtime.setCreationTime(Calendar.getInstance( ));
resourceProperty.add(prop_creationtime);
}
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.
}
}