You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by wi...@apache.org on 2004/12/21 23:27:13 UTC

svn commit: r123005 - in incubator/muse/trunk/client/src/test/org/apache/ws/resource: . example example/discovery

Author: wire
Date: Tue Dec 21 14:27:12 2004
New Revision: 123005

URL: http://svn.apache.org/viewcvs?view=rev&rev=123005
Log:
Added files from muse that are required for client unit tests since client uses disk as it test resource.
Added:
   incubator/muse/trunk/client/src/test/org/apache/ws/resource/
   incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/
   incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/Disk.java
   incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/ExampleConstants.java
   incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/StateInfo.java
   incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/discovery/
   incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/discovery/DiskDiscoveryAgent.java

Added: incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/Disk.java
Url: http://svn.apache.org/viewcvs/incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/Disk.java?view=auto&rev=123005
==============================================================================
--- (empty file)
+++ incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/Disk.java	Tue Dec 21 14:27:12 2004
@@ -0,0 +1,309 @@
+/*=============================================================================*
+ *  Copyright 2004 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.resource.example;
+
+import org.apache.xmlbeans.GDuration;
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Example bean representing a "backend" managed resource.
+ *
+ * NOTE: Here's a high-level algo for mapping resource prop XSD types to member var types:
+ * <pre>
+ * if ( minOccurs == "1" && maxOccurs == "1" )
+ *    type = single object or primitive
+ * elif ( maxOccurs != "unbounded" )
+ *    type = array of objects or primitives w/ size=maxOccurs
+ * elif
+ *    type = java.util.List
+ * fi
+ * </pre>
+ *
+ * @author Ian P. Springer
+ */
+public class Disk
+   implements Serializable
+{
+   private BigInteger   m_number_of_blocks = ExampleConstants.INITIAL_PROP_VALUE__NUMBER_OF_BLOCKS;
+   private Set          m_filesystems    = buildFileSystemSet(  );
+   private Set          m_state_info_set = buildStateInfoSet(  );
+   private String       m_manufacturer   = ExampleConstants.INITIAL_PROP_VALUE__MANUFACTURER;
+   private int          m_block_size     = ExampleConstants.INITIAL_PROP_VALUE__BLOCK_SIZE;
+   private boolean      m_isStarted;
+   private final String m_serialNumber;
+   private GDuration    m_activeTime     = ExampleConstants.INITIAL_PROP_VALUE__ACTIVE_TIME;
+
+   /**
+    * Creates a new {@link Disk} object with the specified serial number.
+    */
+   public Disk( String serialNumber )
+   {
+      m_serialNumber = serialNumber;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param activeTime DOCUMENT_ME
+    */
+   public void setActiveTime( GDuration activeTime )
+   {
+      m_activeTime = activeTime;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public GDuration getActiveTime(  )
+   {
+      return m_activeTime;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param blockSize DOCUMENT_ME
+    */
+   public void setBlockSize( int blockSize )
+   {
+      m_block_size = blockSize;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public int getBlockSize(  )
+   {
+      return m_block_size;
+   }
+
+   /**
+    * Returns the current capacity, computed via the formula: NumberOfBlocks * BlockSize
+    */
+   public BigInteger getCapacity(  )
+   {
+      return computeCapacity( m_number_of_blocks, m_block_size );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public String getSerialNumber(  )
+   {
+      return m_serialNumber;
+   }
+
+   /**
+    * Computes the capacity of a disk with the specified number of blocks and block size.
+    *
+    * @param numberOfBlocks number of blocks
+    * @param blockSize block size
+    *
+    * @return the capacity of a disk with specified number of blocks and block size
+    */
+   public static BigInteger computeCapacity( BigInteger numberOfBlocks,
+                                             int        blockSize )
+   {
+      return numberOfBlocks.multiply( new BigInteger( String.valueOf( blockSize ) ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public String[] getFilesystems(  )
+   {
+      return (String[]) m_filesystems.toArray( new String[0] );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param manufacturer DOCUMENT_ME
+    */
+   public void setManufacturer( String manufacturer )
+   {
+      m_manufacturer = manufacturer;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public String getManufacturer(  )
+   {
+      return m_manufacturer;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param numberOfBlocks DOCUMENT_ME
+    */
+   public void setNumberOfBlocks( BigInteger numberOfBlocks )
+   {
+      m_number_of_blocks = numberOfBlocks;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public BigInteger getNumberOfBlocks(  )
+   {
+      return m_number_of_blocks;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public boolean isStarted(  )
+   {
+      return m_isStarted;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public StateInfo[] getStateInfoList(  )
+   {
+      return (StateInfo[]) m_state_info_set.toArray( new StateInfo[0] );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param filesystem DOCUMENT_ME
+    */
+   public void addFilesystem( String filesystem )
+   {
+      m_filesystems.add( filesystem );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param stateInfo DOCUMENT_ME
+    */
+   public void addStateInfo( StateInfo stateInfo )
+   {
+      m_state_info_set.add( stateInfo );
+   }
+
+   /**
+    * DOCUMENT_ME
+    */
+   public void removeAllFilesystems(  )
+   {
+      m_filesystems = new HashSet(  );
+   }
+
+   /**
+    * DOCUMENT_ME
+    */
+   public void removeAllStateInfos(  )
+   {
+      m_state_info_set.clear(  );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param filesystem DOCUMENT_ME
+    */
+   public void removeFilesystem( String filesystem )
+   {
+      m_filesystems.remove( filesystem );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param stateInfo DOCUMENT_ME
+    */
+   public void removeStateInfo( StateInfo stateInfo )
+   {
+      m_state_info_set.remove( stateInfo );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @throws Exception DOCUMENT_ME
+    */
+   public void start(  )
+   throws Exception
+   {
+      if ( !m_isStarted )
+      {
+         m_isStarted = true;
+         System.out.println( "Backend disk with serial # " + m_serialNumber + " has been started." );
+      }
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @throws Exception DOCUMENT_ME
+    */
+   public void stop(  )
+   throws Exception
+   {
+      if ( m_isStarted )
+      {
+         m_isStarted = false;
+         System.out.println( "Backend disk with serial # " + m_serialNumber + " has been stopped." );
+      }
+   }
+
+   private Set buildFileSystemSet(  )
+   {
+      Set set = new HashSet(  );
+      set.add( "/" );
+      return set;
+   }
+
+   private Set buildStateInfoSet(  )
+   {
+      Set       set        = new HashSet(  );
+      StateInfo stateInfo1 = new StateInfo(  );
+      stateInfo1.setState( "http://stopped" );
+      stateInfo1.setTimeEntered( Calendar.getInstance(  ) );
+      set.add( stateInfo1 );
+      StateInfo stateInfo2 = new StateInfo(  );
+      stateInfo2.setState( "http://starting" );
+      stateInfo2.setTimeEntered( Calendar.getInstance(  ) );
+      set.add( stateInfo2 );
+      return set;
+   }
+}
\ No newline at end of file

Added: incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/ExampleConstants.java
Url: http://svn.apache.org/viewcvs/incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/ExampleConstants.java?view=auto&rev=123005
==============================================================================
--- (empty file)
+++ incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/ExampleConstants.java	Tue Dec 21 14:27:12 2004
@@ -0,0 +1,83 @@
+/*=============================================================================*
+ *  Copyright 2004 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.resource.example;
+
+import org.apache.xmlbeans.GDuration;
+import javax.xml.namespace.QName;
+import java.math.BigInteger;
+
+/**
+ * Example-related constants.
+ *
+ * @author Ian P. Springer
+ */
+public interface ExampleConstants
+{
+   /** DOCUMENT_ME */
+   BigInteger INITIAL_PROP_VALUE__NUMBER_OF_BLOCKS = new BigInteger( "20000000000" );
+
+   /** Target namespace prefix for the disk WSDL */
+   String NSPREFIX_XYZ = "xyz";
+
+   /** Target namespace URI of the disk WSDL */
+   String NSURI_XYZ = "http://xyz.com/";
+
+   /** QNames */
+   QName RESOURCE_PROP_QNAME_ACTIVE_TIME = new QName( NSURI_XYZ, "ActiveTime", NSPREFIX_XYZ );
+
+   /** DOCUMENT_ME */
+   QName RESOURCE_PROP_QNAME_BLOCK_SIZE = new QName( NSURI_XYZ, "BlockSize", NSPREFIX_XYZ );
+
+   /** DOCUMENT_ME */
+   QName RESOURCE_PROP_QNAME_CAPACITY = new QName( NSURI_XYZ, "Capacity", NSPREFIX_XYZ );
+
+   /** DOCUMENT_ME */
+   QName RESOURCE_PROP_QNAME_FILE_SYSTEM = new QName( NSURI_XYZ, "FileSystem", NSPREFIX_XYZ );
+
+   /** DOCUMENT_ME */
+   QName RESOURCE_PROP_QNAME_MANUFACTURER = new QName( NSURI_XYZ, "Manufacturer", NSPREFIX_XYZ );
+
+   /** DOCUMENT_ME */
+   QName RESOURCE_PROP_QNAME_NUMBER_OF_BLOCKS = new QName( NSURI_XYZ, "NumberOfBlocks", NSPREFIX_XYZ );
+
+   /** DOCUMENT_ME */
+   QName RESOURCE_PROP_QNAME_STATE_INFO = new QName( NSURI_XYZ, "StateInfo", NSPREFIX_XYZ );
+
+   /** DOCUMENT_ME */
+   QName RESOURCE_PROP_QNAME_TOPIC_SPACE = new QName( NSURI_XYZ, "TopicSpace", NSPREFIX_XYZ );
+
+   /** DOCUMENT_ME */
+   String INITIAL_PROP_VALUE__MANUFACTURER = "Hewlett-Packard Company";
+
+   /** Name of the deployed disk Web service */
+   String SERVICE_NAME = "disk";
+
+   /** Qualified name of the deployed disk Web service */
+   QName SERVICE_QNAME = new QName( NSURI_XYZ, SERVICE_NAME );
+
+   /** URL path of the disk Web service */
+   String SERVICE_URL_PATH = "/axis/services/" + SERVICE_NAME;
+
+   /** DOCUMENT_ME */
+   int INITIAL_PROP_VALUE__BLOCK_SIZE = 1024;
+
+   /** DOCUMENT_ME */
+   BigInteger INITIAL_PROP_VALUE__CAPACITY =
+      Disk.computeCapacity( INITIAL_PROP_VALUE__NUMBER_OF_BLOCKS, INITIAL_PROP_VALUE__BLOCK_SIZE );
+
+   /** DOCUMENT_ME */
+   GDuration INITIAL_PROP_VALUE__ACTIVE_TIME = new GDuration( "P0M" );
+}
\ No newline at end of file

Added: incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/StateInfo.java
Url: http://svn.apache.org/viewcvs/incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/StateInfo.java?view=auto&rev=123005
==============================================================================
--- (empty file)
+++ incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/StateInfo.java	Tue Dec 21 14:27:12 2004
@@ -0,0 +1,69 @@
+/*=============================================================================*
+ *  Copyright 2004 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.resource.example;
+
+import java.io.Serializable;
+import java.util.Calendar;
+
+/**
+ * @author Ian P. Springer
+ */
+public class StateInfo
+   implements Serializable
+{
+   private Calendar m_timeEntered;
+   private String   m_state;
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param state DOCUMENT_ME
+    */
+   public void setState( String state )
+   {
+      m_state = state;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public String getState(  )
+   {
+      return m_state;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param timeEntered DOCUMENT_ME
+    */
+   public void setTimeEntered( Calendar timeEntered )
+   {
+      m_timeEntered = timeEntered;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public Calendar getTimeEntered(  )
+   {
+      return ( m_timeEntered );
+   }
+}
\ No newline at end of file

Added: incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/discovery/DiskDiscoveryAgent.java
Url: http://svn.apache.org/viewcvs/incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/discovery/DiskDiscoveryAgent.java?view=auto&rev=123005
==============================================================================
--- (empty file)
+++ incubator/muse/trunk/client/src/test/org/apache/ws/resource/example/discovery/DiskDiscoveryAgent.java	Tue Dec 21 14:27:12 2004
@@ -0,0 +1,100 @@
+package org.apache.ws.resource.example.discovery;
+	    
+
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.resource.discovery.DiscoveryAgent;
+import org.apache.ws.resource.discovery.RegistrationManager;
+import org.apache.ws.resource.discovery.faults.RegistrationFailureException;
+import org.apache.ws.resource.discovery.impl.DiscoveryAgentProperty;
+
+import axis.com.xyz.DiskWsdmServiceWSResource;
+
+/**
+ * This is a sample discovery agent that will add one new instance of a
+ * disk resource for each Agent property with an id of ResourceID.
+ * Its value will be the resource id to be used.
+ * <p/>
+ * Below is a sample of how to instantiate 2 instances of
+ * disk resource, one with the id of 1234 and another with one
+ * of 5678.
+ * <p/>
+ * <pre>
+ *  <agent-list >
+ *   <agent>
+ *       <name>Disk Resource Discovery Agent</name>
+ *       <class>org.apache.ws.resource.example.discovery.DiskDiscoveryAgent</class>
+ *       <properties>
+ *           <property id="ResourceID">1234</property>
+ *           <property id="ResourceID">5678</property>
+ *       </properties>
+ *    </agent>
+ *   </agent-list>
+ * </pre>
+ *
+ * @author wire
+ * @version $Revision: 1.1 $
+ */
+public class DiskDiscoveryAgent
+   implements DiscoveryAgent
+{
+   /**
+    * Provides log access for this class.
+    */
+   private static final Log LOG = LogFactory.getLog( DiskDiscoveryAgent.class );
+
+   /**
+    * @see DiscoveryAgent#discover(String, RegistrationManager, DiscoveryAgentProperty[])
+    */
+   public void discover( String                   agentname,
+                         RegistrationManager      registrationManager,
+                         DiscoveryAgentProperty[] agentProps )
+   {
+      // See how many agentProps there are with ResourceID
+      // For each one, create a DiskResource and register it
+      int discoveredCount = 0;
+      for ( int i = 0; i < agentProps.length; i++ )
+      {
+         DiscoveryAgentProperty agentProp = agentProps[i];
+         if ( agentProp.getId(  ).equals( "ResourceID" ) )
+         {
+            DiskWsdmServiceWSResource resource = null;
+            try
+            {
+               String resourceId = agentProp.getValue(  );
+               resource = new DiskWsdmServiceWSResource( resourceId );
+               resource.getPropertiesManager(  ).setReadOnly(new QName( "http://xyz.com/", "Capacity", "xyz" ), true );
+               discoveredCount++;
+            }
+            catch ( Throwable t )
+            {
+               LOG.error( "Discovery failed for DiskWsdmServiceWSResource with Id " + agentProp.getId(  ), t );
+               continue;
+            }
+
+            LOG.info( "Attempting to register an instance of DiskWsdmServiceWSResource ResourceID="
+                      + agentProp.getValue(  ) );
+            try
+            {
+               registrationManager.register( resource );
+            }
+            catch ( RegistrationFailureException rfe )
+            {
+               LOG.error( "Discovery failed to register " + agentProp.getId(  ), rfe );
+            }
+         }
+      }
+
+      //Just for conveniance, if nothing was discovered, write that to the log.
+      if ( discoveredCount == 0 )
+      {
+         LOG.warn( "Discovery completed on agent " + agentname + " but no new resources where added." );
+      }
+      else
+      {
+         LOG.info( "Discovery agent <" + agentname + "> finished." );
+      }
+   }
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org