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 2005/08/12 22:45:46 UTC

svn commit: r232376 [7/112] - in /webservices/muse/trunk/src/examples/client: ./ bin/ bin/axis/ bin/axis/com/ bin/axis/com/xyz/ bin/org/ bin/org/apache/ bin/org/apache/ws/ bin/org/apache/ws/client/ bin/org/apache/ws/client/async/ bin/org/apache/ws/clie...

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncCallProvider.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncCallProvider.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncCallProvider.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncCallProvider.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,163 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 27, 2004
+ *
+ * $RCSfile: AsyncCallProvider.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:13 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.async;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import EDU.oswego.cs.dl.util.concurrent.TimeoutException;
+
+/**
+ * This class allows an existing class to provide asyncronus 
+ * access to it calls.
+ * @author wire
+ *
+ */
+public class AsyncCallProvider implements Runnable {
+    Hashtable m_threadContext=new Hashtable();
+    Vector m_listners=new Vector();
+    private Method m_monitorMethod;
+    /** The logger for this class. */
+    private static final Log LOG = LogFactory.getLog( AsyncCallProvider.class );
+    
+    /**
+     * 
+     */
+    public AsyncCallProvider() {
+        super();
+        try {
+            m_monitorMethod=getClass().getMethod("timeoutOnContext",new Class[]{AsyncThreadContext.class});
+        } catch (SecurityException e) {
+        } catch (NoSuchMethodException e) {
+        }
+    }
+    /* (non-Javadoc)
+     * @see java.lang.Runnable#run()
+     */
+    public void run() {
+        // Get context for this thread
+        AsyncThreadContext context= (AsyncThreadContext) m_threadContext.get(Thread.currentThread());
+        if(context==null){
+            throw new IllegalStateException("This thread does not have a context. Register one before continuing.");
+        }
+        
+        // Call method in context
+        Object returnValue;
+        Method execMethod=context.getMethod();
+        try {
+            returnValue=execMethod.invoke(this,context.getParams());
+        } catch (IllegalArgumentException e) {
+            throw new RuntimeException(e);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+        } catch (InvocationTargetException e) {
+            throw new RuntimeException(e);
+        }
+        
+        if(Thread.currentThread().isInterrupted()){
+            LOG.info("This thread has been interrupted.");
+            unregisterContext(context);
+            return;
+        }
+        
+        // create event and send to all listeners
+        if(context.getMonitorThread()!=null){
+            // Nobody wants to hear about monitor terminations
+            notifyListeners(context,returnValue);
+        }
+        unregisterContext(context);
+        
+        // Dispose of monitor thread
+        if(context.getMonitorThread()!=null)
+            context.getMonitorThread().interrupt();
+    }
+    
+	/**
+     * @param method class method to call
+     * @param arguments array of object arguments
+     * @param timeout time to wait for method completion before failing.
+     */
+    protected void performAsync(Method method, Object[] arguments, long timeout) {
+        Thread execThread=new Thread(this,"AsyncWorker - "+method.getName());
+        Thread monitorThread=new Thread(this,"AsyncMonitor - "+method.getName());
+        
+        // Register context for exec thread
+        AsyncThreadContext context=new AsyncThreadContext(execThread,monitorThread,method,arguments,timeout);
+        registerContext(context); 
+        
+        // Register context for timeout thread
+        registerContext(new AsyncThreadContext(monitorThread,null,m_monitorMethod,new Object[]{context},timeout));
+        monitorThread.start();
+        execThread.start();
+        
+    }
+    
+    /**
+     * @param object
+     */
+    private void registerContext(AsyncThreadContext context) {
+        LOG.info("Registered context "+context);
+        if(m_threadContext.contains(context.getExecThread())){
+            throw new IllegalStateException("This thread already has a context. unregister the existing one before continuing.");
+        }
+        m_threadContext.put(context.getExecThread(),context);
+    }
+
+    private void unregisterContext(AsyncThreadContext context) {
+        LOG.info("Unregistered context "+context);
+        if(m_threadContext.contains(context.getExecThread())){
+            m_threadContext.remove(context.getExecThread());
+        }        
+    }
+    
+    public void timeoutOnContext(AsyncThreadContext contextToMonitor){
+        
+        LOG.info("Thread "+Thread.currentThread().getName()+" entered timeoutOnContext and going to sleep for "+contextToMonitor.getTimeout()+" seconds");
+        try {
+            Thread.sleep(contextToMonitor.getTimeout());
+        } catch (InterruptedException e) {
+            // operation completed, timeout aborts
+            LOG.info("Thread woke up"+Thread.currentThread().getName()+" cancelled due to function "+contextToMonitor.getMethod().getName()+" completion");
+            return;
+        }
+        LOG.info("Thread woke up "+Thread.currentThread().getName()+" to cancel timed out process.");
+        
+        // Interrupt the exec thread, send events and then die
+        Thread execThread=contextToMonitor.getExecThread();
+        execThread.interrupt();
+        notifyListeners(contextToMonitor, new TimeoutException(contextToMonitor.getTimeout(),"Timeout Exceeded"));
+    }
+    
+    private void notifyListeners(AsyncThreadContext context, Object returnValue){
+        LOG.info("Sending event: "+context+" with value "+returnValue);
+        AsyncEvent event = new AsyncEvent(context,returnValue);
+        for (int index = 0; index < m_listners.size(); index++) {
+            AsyncListener listener = (AsyncListener) m_listners.get(index);
+            listener.asyncCompletionEvent(event);
+        }
+    }
+    
+	public void addListener(AsyncListener listner){
+	    m_listners.add(listner);
+	}
+	
+	public void removeListener(AsyncListener listner){
+	    m_listners.remove(listner);
+	}
+	
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncEvent.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncEvent.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncEvent.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncEvent.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,38 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 27, 2004
+ *
+ * $RCSfile: AsyncEvent.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:14 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.async;
+
+import java.util.EventObject;
+
+/**
+ * @author wire
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class AsyncEvent extends EventObject {
+    Object m_source;
+    private Object m_returnValue;
+    /**
+     * @param source
+     * @param returnValue
+     */
+    public AsyncEvent(Object source, Object returnValue) {
+        super(source);
+        m_returnValue=returnValue;
+    }
+
+    public Object getReturnValue() {
+        return m_returnValue;
+    }
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncListener.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncListener.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncListener.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncListener.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,28 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 27, 2004
+ *
+ * $RCSfile: AsyncListener.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:14 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.async;
+
+import java.util.EventListener;
+
+/**
+ * @author wire
+ *
+ */
+public interface AsyncListener extends EventListener{
+
+    /**
+     * @param object
+     */
+    public void asyncCompletionEvent(AsyncEvent event);
+
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncThreadContext.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncThreadContext.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncThreadContext.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/async/AsyncThreadContext.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,79 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 27, 2004
+ *
+ * $RCSfile: AsyncThreadContext.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:14 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.async;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author wire
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class AsyncThreadContext {
+    Thread m_execThread;
+    Method m_method;
+    long m_timeout;
+    Object[] m_params;
+    private Thread m_monitorThread;
+    
+    /**
+     * @param execThread
+     * @param monitorThread
+     * @param method
+     * @param timeout
+     */
+    public AsyncThreadContext(Thread execThread, Thread monitorThread, Method method, Object[] params,long timeout) {
+        
+        if(execThread==null){
+            throw new NullPointerException("execThread cannot be null");
+        }
+        if(method==null){
+            throw new NullPointerException("method cannot be null");
+        }
+        if(params==null){
+            throw new NullPointerException("params cannot be null");
+        }
+        m_execThread=execThread;
+        m_method=method;
+        m_timeout=timeout;
+        m_monitorThread=monitorThread;
+        m_params=params;
+    }
+    
+    public Thread getExecThread() {
+        return m_execThread;
+    }
+    public Thread getMonitorThread() {
+        return m_monitorThread;
+    }
+    public Method getMethod() {
+        return m_method;
+    }
+    public long getTimeout() {
+        return m_timeout;
+    }
+    public Object[] getParams() {
+        return m_params;
+    }
+    
+    public String toString() {
+        String monitorThreadText;
+        if(m_monitorThread!=null){
+            monitorThreadText=m_monitorThread.getName();
+        } else {
+            monitorThreadText="none";
+        }
+        return "{ execThread="+m_execThread.getName()+", monitorThread="+monitorThreadText+ ", "+m_method.getName()+"}";
+    }
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmClient.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmClient.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmClient.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmClient.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,67 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 16, 2004
+ *
+ * $RCSfile: WsdmClient.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:14 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * @author wire
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public interface WsdmClient {
+
+    /**
+     * Attempts to make a simple request from the server.
+     * @return returns the time in millis for this request to complete or -1 if
+     * the remote server failes to respond.
+     */
+    public long ping();
+    
+    /**
+     * Creates an array of WsdmResources.
+     * @return An array of WsdmResources which can be though of as a collection of resource instances which
+     * share a common interface and purpose.
+     * @throws SecurityException
+     * @throws IllegalArgumentException
+     * @throws NoSuchMethodException
+     * @throws IllegalAccessException
+     * @throws InvocationTargetException
+     * @throws Exception
+     */
+    public WsdmResource[] getResources() throws SecurityException,
+            IllegalArgumentException, NoSuchMethodException,
+            IllegalAccessException, InvocationTargetException, Exception;
+
+    /**
+     * Allows a specific resource name to be asked for. Usually used when a resource
+     * name is known in advance. 
+     * @param resourceName
+     * @return
+     * @throws Exception
+     * @throws InvocationTargetException
+     * @throws IllegalAccessException
+     * @throws NoSuchMethodException
+     * @throws IllegalArgumentException
+     * @throws SecurityException
+     */
+    public WsdmResource getResource(String resourceName) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, Exception;
+    
+    /**
+     * Returns a meaningful name for this client.
+     * @return a string containing a name which can be used to represent this client.
+     */
+    public String getName();
+    
+}
\ No newline at end of file

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmClientFactory.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmClientFactory.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmClientFactory.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmClientFactory.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,51 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 16, 2004
+ *
+ * $RCSfile: WsdmClientFactory.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:15 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model;
+
+import java.io.IOException;
+
+import javax.wsdl.WSDLException;
+
+import org.apache.ws.client.DynamicSchemaClassBuilder;
+import org.apache.ws.client.model.impl.WsdmClientImpl;
+
+/**
+ * @author wire
+ *
+ */
+public class WsdmClientFactory {
+    public static final int AXIS_CLIENT_TYPE=0;
+    
+    /**
+     * Creates a WsdmClient in a SOAP client independent manner. Should be used to create
+     * a WsdmClient.
+     * 
+     * @param clientType
+     * @param hostName
+     * @param servletContext
+     * @return an initalized WsdmClient.
+     * @throws WSDLException
+     * @throws IOException
+     */
+    public static WsdmClient create(int clientType, String hostName,String servletContext) throws WSDLException, IOException{
+        return new WsdmClientImpl(hostName,servletContext);        
+    }
+    /**
+     * Clears the cache of generated classes in the users home directory;
+     * Should be used in unit tests and to flush generated classes if a wsdl on the
+     * server has changed and the client classes should be re-generated.
+     */
+    public static void clearGeneratedClassCache(){
+        DynamicSchemaClassBuilder.dispose();
+    }
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmInstance.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmInstance.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmInstance.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmInstance.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,60 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 16, 2004
+ *
+ * $RCSfile: WsdmInstance.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:15 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Hashtable;
+
+import javax.xml.namespace.QName;
+
+import org.apache.xmlbeans.XmlObject;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+
+/**
+ * @author wire
+ *
+ */
+public interface WsdmInstance {
+
+    public abstract String getName();
+
+    public abstract void refresh() throws Exception;
+
+    public abstract String[] getPropertyNames() throws Exception;
+
+    public abstract XmlObject getPropertyValue(String propertyName) throws Exception;
+
+    public abstract XmlObject[] getPropertyValue(QName propertyName) throws Exception;
+
+    public abstract void setPropertyValue(String propertyName,XmlObject value) throws Exception;
+
+    public abstract void setPropertyValue(QName propertyName, XmlObject value) throws Exception;
+
+    public abstract WsdmOperation[] getOperations() throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+    public abstract WsdmOperation findOperation(String operationName) throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+    public abstract XmlObject[] invoke(WsdmOperation operation,
+            Hashtable parameters) throws Exception;
+    
+    public abstract EndpointReferenceType getEPR() throws Exception;
+
+    /**
+     * Requests a list of Topic XPaths.
+     * @return a list of topic XPaths
+     */
+    public abstract String[] getListenerTopics();
+    
+    public WsdmResource getParent();
+
+}
\ No newline at end of file

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmOperation.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmOperation.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmOperation.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmOperation.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,45 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 16, 2004
+ *
+ * $RCSfile: WsdmOperation.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:15 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model;
+
+/**
+ * 
+ * An abstraction for representing an operation. Enables access to
+ * its name and a description of its parameters and there respective
+ * java classes. 
+ * @author wire
+ *
+ */
+public interface WsdmOperation {
+    /**
+     * 
+     * @return The name for this operations
+     */
+    public abstract String getName();
+    /**
+     * 
+     * @return a String[] containing all the operation names for this method.
+     */
+    public abstract String[] getParameterNames();
+
+    /**
+     * Resolves a parameters type when given its name.
+     * @param parameterName The name of this parameter
+     * @return the java class name for this type.
+     */
+    public abstract String getParameterType(String parameterName);
+    /**
+     * @return
+     */
+    public String[] getParameterTypes();
+}
\ No newline at end of file

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmResource.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmResource.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmResource.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/WsdmResource.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,46 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 16, 2004
+ *
+ * $RCSfile: WsdmResource.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:15 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model;
+
+
+
+/**
+ * A representation of a WsdmResource. A resource is a collection of
+ * Managed Instances which share the same interface and it is implied that
+ * they are simillar in function or behavior.
+ * 
+ * @author wire
+ *
+ */
+public interface WsdmResource {
+    /**
+     * Returns a name that can be used to represent this resources
+     * @return
+     */
+    public String getName();
+    /**
+     * Returns an array of specific managed instances of this type of resource.
+     * @return an array of managed instances.
+     * @throws Exception
+     */
+    public WsdmInstance[] getInstances() throws Exception;
+    /**
+     * Returns a specific instance. Usually used when a resource id is known in advance.
+     * @param resourceId
+     * @return
+     */
+    public WsdmInstance getInstance(String resourceId);
+    
+    public WsdmClient getParent();
+
+}
\ No newline at end of file

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmClientImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmClientImpl.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmClientImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmClientImpl.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,245 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 10, 2004
+ */
+package org.apache.ws.client.model.impl;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Hashtable;
+
+import javax.naming.OperationNotSupportedException;
+import javax.wsdl.Operation;
+import javax.wsdl.WSDLException;
+import javax.xml.namespace.QName;
+
+import org.apache.ws.client.DynamicSchemaClassBuilder;
+import org.apache.ws.client.DynamicSoapClient;
+import org.apache.ws.client.async.AsyncCallProvider;
+import org.apache.ws.client.model.WsdmClient;
+import org.apache.ws.client.model.WsdmInstance;
+import org.apache.ws.client.model.WsdmResource;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
+import org.xmlsoap.schemas.soap.envelope.impl.FaultImpl;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+
+/**
+ * This class represents a remote instance of a Wsdm capable servlet.
+ * @author wire
+ *
+ */
+public class WsdmClientImpl extends AsyncCallProvider implements WsdmClient {
+    private WsdmResource[] m_resourceCache;
+	private String m_hostname;
+	private String m_servletContext;
+	private DynamicSoapClient m_registrySoapClient;
+	public static final String s_wsdmNamspaceURI="http://docs.oasis-open.org/wsdm/2004/04/muws-0.5/schema";
+	private long m_lastPingTime;
+	/**
+	 * Constructs a new WsdmServer. These servers are expected to be stored in the
+	 * client apps configurations and passed to this constructor. This constructor
+	 * does not connect with the server to make any requests but does ask the server
+	 * for wsdl information.
+	 * 
+	 * Hostname could be "myhost.com:8080" as an example.
+	 * serveltContext is the name of the soap servlet hosting the server. an example would be "axis"
+	 * 
+	 * @throws IOException
+	 * @throws WSDLException
+	 * 
+	 */
+	public WsdmClientImpl(String hostname,String servletContext) throws WSDLException, IOException {
+		super();
+		
+		// Save constructor info
+		m_hostname=hostname;
+		m_servletContext=servletContext;
+		
+		// Initalize event support
+//		m_propChangeSupport=new PropertyChangeSupport(this);
+		
+		// Create a soap client for registry service access
+		URL serverURL=new URL("http://"+m_hostname+"/"+servletContext+"/services/registry");
+		URL wsdlURL=new URL("http://"+m_hostname+"/"+servletContext+"/services/registry?wsdl");		
+		m_registrySoapClient=new DynamicSoapClient(wsdlURL,serverURL);
+	}
+	
+	public void pingAsync() throws SecurityException, NoSuchMethodException{
+	    Method pingMethod=getClass().getMethod("ping",new Class[]{});
+	    performAsync(pingMethod,new Object[]{},30000);
+	}
+	
+
+    /* (non-Javadoc)
+	 * @see org.apache.ws.client.model.WsdmClient#ping()
+	 */
+	public long ping()  {
+		Date startDate=new Date();
+		
+		Operation[] operations = m_registrySoapClient.findOperation("GetResourceProperty");
+		if(operations.length==0)
+			return -1;
+		
+		Operation opGetResoureProperty=operations[0];		
+		Hashtable params=new Hashtable();
+		params.put("QName",new QName(s_wsdmNamspaceURI,"Version"));
+		XmlObject[] responses;
+			try {
+                responses = m_registrySoapClient.execute(opGetResoureProperty,params);
+            } catch (Exception e) {
+                return -1;
+            }
+		XmlObject response=responses[0];
+		if(response instanceof FaultImpl){
+			return -1;
+		}
+		Date endDate=new Date();
+		long newPingTime=endDate.getTime()-startDate.getTime();
+		long oldPingTime=m_lastPingTime;
+		m_lastPingTime=newPingTime;
+//		m_propChangeSupport.firePropertyChange("LastPingTime",new Long(newPingTime),new Long(m_lastPingTime));		
+		return m_lastPingTime;
+	}
+	
+    /** 
+	 * Queries the server's registy service and returns its resource id's
+	 * that are available for this resource. 
+	 */
+	public String[] getInstances(String resourceName) throws Exception{
+
+		Operation[] operations = m_registrySoapClient.findOperation("findResourcesByServiceName");
+		if(operations.length==0)
+			throw new OperationNotSupportedException("findResourcesByServiceName could not be found in the Registry service.");
+		
+		Operation opGetResoureProperty=operations[0];		
+		Hashtable params=new Hashtable();
+		params.put("serviceName",resourceName);
+		XmlObject[] responses;
+        responses = m_registrySoapClient.execute(opGetResoureProperty,params);
+		XmlObject response=responses[0];
+		if(response instanceof FaultImpl){
+		    FaultImpl fault=(FaultImpl)response;
+			throw new Exception(fault.getFaultstring());
+		}
+		
+		EndpointReferenceType[] ERTypes = (EndpointReferenceType[])DynamicSchemaClassBuilder.getProperty(response,"ItemArray");
+		ArrayList ret=new ArrayList();
+		for (int index = 0; index < ERTypes.length; index++) {
+            EndpointReferenceType type = ERTypes[index];
+            
+            //ReferencePropertiesType rps = type.getReferenceProperties();
+            XmlCursor cursor = type.newCursor();
+            //cursor.toFirstChild();
+            // TODO wire TO specific. This must be changed
+            if(!cursor.toChild(new QName("urn:proposedstandard.org/muse/addressing","ResourceID"))){
+                cursor.toChild(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","ReferenceProperties"));
+                if(!cursor.toChild(new QName("urn:proposedstandard.org/muse/addressing","ResourceID"))){
+                    break;
+                }
+            }
+            String resourceID = cursor.getTextValue();
+            ret.add(resourceID);
+        }
+        
+		return (String[])ret.toArray(new String[0]);
+	    
+	 }
+	
+	public EndpointReferenceType getErpFor(String serviceName,String resourceID) throws Exception{
+	    Operation[] operations = m_registrySoapClient.findOperation("findResource");
+		if(operations.length==0){
+			throw new NoSuchMethodException("Method findResource could not be found.");
+		}
+		Operation findResourceOp=operations[0];
+	    Hashtable params = new Hashtable();
+	    params.put("serviceName",serviceName);
+	    params.put("id",resourceID);
+		XmlObject[] responses = m_registrySoapClient.execute(findResourceOp,params);
+
+	    return (EndpointReferenceType)responses[0];
+	    
+	}
+	
+	public WsdmResource[] getResources() throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, Exception{
+		if(m_resourceCache!=null)
+		    return m_resourceCache;
+	    
+	    Operation[] operations = m_registrySoapClient.findOperation("findAllServiceNames");
+		if(operations.length==0){
+			throw new NoSuchMethodException("Method findAllServiceNames could not be found.");
+		}
+		
+		Operation opGetAllServiceNames=operations[0];		
+		XmlObject[] responses = m_registrySoapClient.execute(opGetAllServiceNames,null);
+		if(responses.length==0){
+			return new WsdmResource[]{};
+		}
+
+		XmlObject response=responses[0];
+		if(response instanceof FaultImpl){
+			FaultImpl fault=(FaultImpl)response;
+			throw new Exception(fault.getFaultstring());
+		}
+		
+		String[] arrayOfServiceNames=(String[])DynamicSchemaClassBuilder.getProperty(responses[0],"ItemArray");
+
+		ArrayList resources=new ArrayList();
+		for (int i = 0; i < arrayOfServiceNames.length; i++) {
+			String serviceName= arrayOfServiceNames[i];
+			resources.add(new WsdmResourceImpl(serviceName,m_hostname,m_servletContext,this));
+		}
+		m_resourceCache=(WsdmResource[])resources.toArray(new WsdmResource[0]);
+		return m_resourceCache;
+	}
+		
+//	public void addListener(PropertyChangeListener listner){
+//		m_propChangeSupport.addPropertyChangeListener(listner);
+//	}
+//	public void removeListener(PropertyChangeListener listner){
+//		m_propChangeSupport.removePropertyChangeListener(listner);
+//	}
+
+    public String getName(){
+        return toString();
+    }
+    
+    public String toString() {
+        return "Server - "+m_hostname ;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.model.WsdmClient#getResource(java.lang.String)
+     */
+    public WsdmResource getResource(String resourceName) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, Exception {
+        WsdmResource[] resources = getResources();
+        for (int index = 0; index < resources.length; index++) {
+            WsdmResource resource = resources[index];
+            if(resource.getName().equals(resourceName))
+                return resource;
+        }
+        return null;
+    }
+    
+    public WsdmInstance findInstance(EndpointReferenceType epr) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, Exception{
+        XmlCursor cursor = epr.newCursor();
+        //TODO wire get rid of these hard coded namspaces!
+        cursor.toChild(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","ServiceName"));
+        String ServiceName=cursor.getAttributeText(new QName("PortName"));
+        cursor.dispose();
+        
+        cursor = epr.newCursor();
+        cursor.toChild(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","ReferenceProperties"));
+        cursor.toChild(new QName("urn:proposedstandard.org/muse/addressing","ResourceID"));
+        String ResourceId=cursor.getTextValue();
+        cursor.dispose();
+    
+        WsdmResource resource=getResource(ServiceName);
+        return resource.getInstance(ResourceId);
+    }
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmInstanceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmInstanceImpl.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmInstanceImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmInstanceImpl.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,337 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ *
+ * Created on Sep 11, 2004
+ *
+ */
+package org.apache.ws.client.model.impl;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+
+import javax.wsdl.Operation;
+import javax.xml.namespace.QName;
+
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+
+import org.apache.ws.client.DynamicSoapClient;
+import org.apache.ws.client.async.AsyncCallProvider;
+import org.apache.ws.client.model.WsdmInstance;
+import org.apache.ws.client.model.WsdmOperation;
+import org.apache.ws.client.model.WsdmResource;
+import org.apache.ws.resource.faults.BaseFaultException;
+import org.apache.ws.resource.properties.query.xpath.XPathConstants;
+import com.ibm.xmlns.stdwip.webServices.wsResourceProperties.QueryExpressionType;
+
+/**
+ * @author wire
+ * 
+ * Represents an instance of a managed resource inside the Wsdm Server.
+ */
+public class WsdmInstanceImpl extends AsyncCallProvider implements WsdmInstance {
+    private PropertyChangeSupport m_propChangeSupport;
+    /** DOCUMENT_ME */
+    static ArrayList m_reservedOperationsList;
+    static String[] m_reservedOperations =
+        new String[]
+        {
+           "GetResourceProperty",
+           "GetMultipleResourceProperties",
+           "SetResourceProperties",
+           "QueryResourceProperties",
+        };
+    static {
+        m_reservedOperationsList = new ArrayList(  );
+	    for ( int index = 0; index < m_reservedOperations.length; index++ )
+	    {
+	       String string = m_reservedOperations[index];
+	       m_reservedOperationsList.add( string );
+	    }
+    }
+
+    String m_name;
+
+    private WsdmResourceImpl m_parent;
+
+    private XmlObject[] m_response;
+
+    public WsdmInstanceImpl(String resourceID,WsdmResourceImpl parent) {
+        super();
+        m_name=resourceID;
+        m_parent=parent;
+    }
+
+    public void addListener(PropertyChangeListener listner) {
+        m_propChangeSupport.addPropertyChangeListener(listner);
+    }
+
+    public void removeListener(PropertyChangeListener listner) {
+        m_propChangeSupport.removePropertyChangeListener(listner);
+    }
+
+    public String getName() {
+        if(m_name==null||m_name.length()==0){
+            return "Singleton";
+        }
+        else
+            return m_name;
+    }
+    
+    public void refresh() throws Exception{
+        DynamicSoapClient resourceSoapClient = m_parent.getResourceSoapClient();
+        Operation[] queryOperation = resourceSoapClient.findOperation("QueryResourceProperties");
+        if(queryOperation==null)
+            return;
+        Hashtable params=new Hashtable();
+        
+        com.ibm.xmlns.stdwip.webServices.wsResourceProperties.QueryExpressionDocument queryExpressionDocument = (com.ibm.xmlns.stdwip.webServices.wsResourceProperties.QueryExpressionDocument)com.ibm.xmlns.stdwip.webServices.wsResourceProperties.QueryExpressionDocument.Factory.newInstance();
+        QueryExpressionType queryExpressionType = queryExpressionDocument.addNewQueryExpression();
+        queryExpressionType.setDialect(XPathConstants.DIALECT_URI__XPATH1_0);
+        XmlCursor xmlCursor = queryExpressionType.newCursor();
+        xmlCursor.toChild(0);
+        xmlCursor.setTextValue("*");
+        xmlCursor.dispose();
+        
+        params.put("QueryExpression",(QueryExpressionType)queryExpressionType);
+        m_response = resourceSoapClient.execute(queryOperation[0],params,getName());
+    }
+
+    public String[] getPropertyNames() throws Exception {
+        if(m_response==null)
+            refresh();
+        //TODO wire faults? what faults????
+        
+        XmlObject response=m_response[0];
+        
+        XmlCursor cursor = response.newCursor();
+        ArrayList ret=new ArrayList();
+        
+        cursor.toFirstChild();
+        cursor.toFirstChild();
+        Hashtable uniquenessTable=new Hashtable(); 
+        while(cursor.toNextSibling()){
+	        
+	        XmlObject propPart=cursor.getObject();
+	        QName nodeName=cursor.getName();
+	        int index=0;
+	        if(uniquenessTable.containsKey(nodeName)){
+	            Integer count=(Integer)uniquenessTable.get(nodeName);
+	            index=count.intValue()+1;
+	            uniquenessTable.put(nodeName,new Integer(index));	            
+	        } else {
+	            uniquenessTable.put(nodeName,new Integer(0));
+	        }
+	        
+	        ret.add(nodeName.toString()+"["+index+"]");
+        }
+        
+        cursor.dispose();
+        
+        return (String[])ret.toArray(new String[0]);
+    }
+
+    public XmlObject getPropertyValue(String propertyName) throws Exception {
+        
+        String[] parts = propertyName.split("}");
+        String uriPart=parts[0].substring(1);
+        String xPathElementName=parts[1];
+        String[] xPathElementNameparts=xPathElementName.split("[\\[\\]]");
+        String elementName=xPathElementNameparts[0];
+        String elementIndex=xPathElementNameparts[1];
+        int index=Integer.parseInt(elementIndex);
+        
+        if(m_response==null)
+            refresh();
+        XmlObject response=m_response[0];
+        //TODO wire faults? what faults????
+                
+      XmlCursor cursor = response.newCursor();
+        ArrayList ret=new ArrayList();
+        
+       cursor.toFirstChild();
+        
+        XmlObject obj = cursor.getObject();
+        // declare namespace s='http://www.openuri.org/sample' " +".//s:owner"
+        String path="declare namespace s='"+uriPart+"' " +"s:"+elementName;
+        XmlObject[] matches=obj.selectPath(path);
+        XmlObject match = matches[index];
+        return match;
+    }
+
+   /**
+    * @see WsdmInstance#getPropertyValue(QName)
+    */
+   public XmlObject[] getPropertyValue(QName propertyName) throws Exception
+   {
+      // make sure the query has been performed and all props have been received
+      if (m_response == null)
+      {
+         refresh();
+      }
+
+      // create a cursor on the query response element
+      XmlObject response = m_response[0];
+      XmlCursor cursor1 = response.newCursor();
+      
+      // skip ahead to the actual property children
+      if (!cursor1.toFirstChild())
+      {
+         return null;
+      }
+      
+      if (!cursor1.toFirstChild())
+      {
+         return null;
+      }
+      
+      // find the property values that we are looking for and add them to our return list
+      ArrayList retValues = new ArrayList();
+      
+      if (propertyName.equals(cursor1.getName()))
+      {
+         retValues.add( cursor1.getObject() );
+      }
+
+      while (cursor1.toNextSibling())
+      {
+         if (propertyName.equals(cursor1.getName()))
+         {
+            retValues.add( cursor1.getObject() );
+         }
+      }
+
+      // clean up our cursor and return the array of property values that we found
+      cursor1.dispose();
+      return (XmlObject[]) retValues.toArray(new XmlObject[retValues.size()]);
+   }
+
+    
+    public WsdmOperation[] getOperations() throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+      ArrayList ret=new ArrayList();
+      DynamicSoapClient resourceSoapClient = m_parent.getResourceSoapClient();
+      Operation[] wsdlOperations = resourceSoapClient.getWsdlOperations();
+      for (int index = 0; index < wsdlOperations.length; index++) {
+          Operation operation = wsdlOperations[index];
+          String opName=operation.getName();
+          String[] params=resourceSoapClient.getParameters(operation);
+          if(!isAProperty(operation)){
+              ret.add(new WsdmOperationImpl(operation.getName(),params));
+          }          
+      }
+      return (WsdmOperation[])ret.toArray(new WsdmOperationImpl[0]);
+    }
+
+    /**
+     * Compares operation to a list of operation names which are part of wsrf.
+     * @param operation An operation
+     * @return true if operation is part of the wsrf spec, else false.
+     */
+    private boolean isASpecReservedOperartion(Operation operation) {
+        return m_reservedOperationsList.contains(operation.getName());
+    }
+
+    /**
+     * Compares an operation to see if it begins with get or set.
+     * @param operation An oepration
+     * @return true if operation name does not begin with get or set, else false;
+     */
+    private boolean isAProperty(Operation operation) {
+        return operation.getName().toLowerCase().startsWith("get")||operation.getName().toLowerCase().startsWith("set");
+    }
+
+    public XmlObject[] invoke(WsdmOperation operation, Hashtable parameters) throws Exception {
+        DynamicSoapClient soapClient = m_parent.getResourceSoapClient();
+        Operation[] soapOperation = soapClient.findOperation(operation.getName());
+        if(soapOperation==null||soapOperation.length==0){
+            throw new ArrayIndexOutOfBoundsException("Soap response array invalid or empty.");
+        }
+        if(soapOperation[0] instanceof BaseFaultException){
+            BaseFaultException e=(BaseFaultException)soapOperation[0];
+            throw new InvocationTargetException(e,"Invoke failed.");
+        }
+        XmlObject[] response = soapClient.execute(soapOperation[0],parameters,m_name);
+        return response;
+    }
+
+    public String toString() {
+        String name=getName();
+        if(name==null||name.length()==0){
+            return "Singleton";
+        }
+        else
+            return getName();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.model.WsdmInstance#addListener(java.lang.String, java.beans.PropertyChangeListener)
+     */
+    public void addListener(String topicXPath, PropertyChangeListener listner) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.model.WsdmInstance#removeListener(java.lang.String, java.beans.PropertyChangeListener)
+     */
+    public void removeListener(String topicXPath, PropertyChangeListener listner) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.model.WsdmInstance#getListenerTopics()
+     */
+    public String[] getListenerTopics() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.model.WsdmInstance#findOperation()
+     */
+    public WsdmOperation findOperation(String operationName) throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+        WsdmOperation[] ops = getOperations();
+        for (int index = 0; index < ops.length; index++) {
+            WsdmOperation operation = ops[index];
+            if(operation.getName().equals(operationName)){
+                return operation;
+            }            
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.model.WsdmInstance#getEPR()
+     */
+    public EndpointReferenceType getEPR() throws Exception {
+        WsdmClientImpl client=(WsdmClientImpl)m_parent.getParent();
+        return client.getErpFor(m_parent.getName(),m_name);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.model.WsdmInstance#setPropertyValue(java.lang.String, org.apache.xmlbeans.XmlObject)
+     */
+    public void setPropertyValue(String propertyName, XmlObject value) throws Exception {
+        // SetResourceProperties
+        
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.model.WsdmInstance#setPropertyValue(javax.xml.namespace.QName, org.apache.xmlbeans.XmlObject)
+     */
+    public void setPropertyValue(QName propertyName, XmlObject value) throws Exception {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public WsdmResource getParent() {
+        return (WsdmResource)m_parent;
+    }
+}
\ No newline at end of file

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmOperationImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmOperationImpl.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmOperationImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmOperationImpl.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,96 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 11, 2004
+ *
+ * $RCSfile: WsdmOperationImpl.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:16 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import org.apache.ws.client.model.WsdmOperation;
+
+/**
+ * @author wire
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class WsdmOperationImpl implements WsdmOperation {
+
+    private String m_name;
+    private Hashtable m_paramHash;
+
+//    public WsdmOperationImpl(Operation wsdlOperation) {
+//       // this(wsdlOperation.getName(),wsdlOperation.getInput().)
+//        // place parameters in a hash
+//        m_paramHash=new Hashtable();
+//        m_name=wsdlOperation.getName();
+//        
+//        QName elementQName;
+//        DynamicSchemaClassBuilder.getEmptyInstanceOfXMLBean(elementQName);
+//        for (int index = 0; index < parameters.length; index++) {
+//            String paramString = parameters[index];
+//            String[] parts = paramString.split("\\[");
+//            String paramName=parts[0];
+//            String className=parts[1].substring(0,parts[1].length()-1);
+//            m_paramHash.put(paramName,className);
+//        }
+//
+//
+//    
+//    }
+    
+    /**
+     * 
+     */
+    public WsdmOperationImpl(String name,String[] parameters) {
+        super();
+        // place parameters in a hash
+        m_paramHash=new Hashtable();
+        for (int index = 0; index < parameters.length; index++) {
+            String paramString = parameters[index];
+            String[] parts = paramString.split("\\[");
+            String paramName=parts[0];
+            String className=parts[1].substring(0,parts[1].length()-1);
+            m_paramHash.put(paramName,className);
+        }
+        m_name=name;
+    }
+
+    public String getName() {
+        return m_name;
+    }
+    
+    public String[] getParameterNames(){
+        Enumeration enum = m_paramHash.keys();
+        ArrayList retList=new ArrayList();
+        while(enum.hasMoreElements()){
+            String key=(String)enum.nextElement();
+            retList.add(key);
+        }
+        return (String[])retList.toArray(new String[0]);
+    }
+    
+    public String[] getParameterTypes(){
+        ArrayList retList=new ArrayList();
+        Collection enum = m_paramHash.values();
+        for (Iterator iter = enum.iterator(); iter.hasNext();) {
+            String typeName = (String) iter.next();
+            retList.add(typeName);
+        }
+        return (String[])retList.toArray(new String[0]);
+    }
+
+    public String getParameterType(String parameterName){ return (String)m_paramHash.get(parameterName);}
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmResourceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmResourceImpl.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmResourceImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/impl/WsdmResourceImpl.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,93 @@
+/*
+ * Created on Sep 10, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.ws.client.model.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+
+import javax.wsdl.WSDLException;
+
+import org.apache.ws.client.DynamicSoapClient;
+import org.apache.ws.client.model.WsdmClient;
+import org.apache.ws.client.model.WsdmInstance;
+import org.apache.ws.client.model.WsdmResource;
+
+/**
+ * @author wire
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class WsdmResourceImpl implements WsdmResource {
+
+	String m_name;
+	String m_hostname;
+	String m_context;
+	WsdmClientImpl m_parent;
+	private DynamicSoapClient m_ServiceSoapClient;
+
+
+	/**
+	 * @param serviceName
+	 * @param m_hostname
+	 * @param context
+	 * @param client
+	 * @throws MalformedURLException,WSDLException
+	 */
+	public WsdmResourceImpl(String name, String hostname, String context, WsdmClientImpl parent) throws MalformedURLException,WSDLException,IOException {
+		m_name=name;
+		m_hostname=hostname;
+		m_context=context;
+		m_parent=parent;
+		
+		URL serverURL=new URL("http://"+m_hostname+"/"+m_context+"/services/"+name+"");
+		URL wsdlURL=new URL("http://"+m_hostname+"/"+m_context+"/services/"+name+"?wsdl");
+		System.out.println("Creating DynamicSoapClient("+wsdlURL+","+serverURL+")");
+		m_ServiceSoapClient=new DynamicSoapClient(wsdlURL,serverURL);
+		System.out.println("Creation Complete DynamicSoapClient("+wsdlURL+","+serverURL+")");
+	}
+	
+	public String getName() {
+		return m_name;
+	}
+	
+	DynamicSoapClient getResourceSoapClient(){ return m_ServiceSoapClient;}
+
+	public WsdmInstance[] getInstances() throws Exception{
+	    String[] resourceIds = m_parent.getInstances(m_name);
+	    if(resourceIds!=null&&resourceIds.length==0){
+	        return new WsdmInstance[]{new WsdmInstanceImpl(null,this)};
+	    }
+	    else
+	    {
+	    ArrayList retInst=new ArrayList();
+	    for (int index = 0; index < resourceIds.length; index++) {
+            String id = resourceIds[index];
+            retInst.add(new WsdmInstanceImpl(id,this));
+        }
+		return (WsdmInstance[])retInst.toArray(new WsdmInstance[0]);
+	    }
+	}
+	
+	
+    public String toString() {
+        return getName();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.model.WsdmResource#getInstance(java.lang.String)
+     */
+    public WsdmInstance getInstance(String resourceId) {        
+	        return new WsdmInstanceImpl(resourceId,this);
+    }
+
+    public WsdmClient getParent() {
+        return m_parent;
+    }
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/GetServerFrame.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/GetServerFrame.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/GetServerFrame.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/GetServerFrame.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,181 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Oct 7, 2004
+ *
+ * $RCSfile: GetServerFrame.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:17 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+
+package org.apache.ws.client.model.swing;
+
+import javax.swing.JFrame;
+
+/**
+ *
+ * @author  wire
+ */
+public class GetServerFrame extends javax.swing.JDialog {
+    String m_Hostname;
+    String m_Context;
+    boolean m_proceed=false;
+    
+    public boolean isProceed() {
+        return m_proceed;
+    }
+    public void setProceed(boolean proceed) {
+        m_proceed = proceed;
+    }
+    public String getContext() {
+        return m_Context;
+    }
+    public void setContext(String context) {
+        m_Context = context;
+    }
+    public String getHostname() {
+        return m_Hostname;
+    }
+    public void setHostname(String hostname) {
+        m_Hostname = hostname;
+    }
+    /** Creates new form GetServerFrame */
+    public GetServerFrame() {
+        initComponents();
+        this.setLocation(100,150);
+        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+    }
+    
+    /** This method is called from within the constructor to
+     * initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is
+     * always regenerated by the Form Editor.
+     */
+    private void initComponents() {
+        java.awt.GridBagConstraints gridBagConstraints;
+
+        jLabelHostname = new javax.swing.JLabel();
+        jLabelContext = new javax.swing.JLabel();
+        jButtonCancel = new javax.swing.JButton();
+        jButtonConnect = new javax.swing.JButton();
+        jTextFieldHost = new javax.swing.JTextField();
+        jTextFieldContext = new javax.swing.JTextField();
+
+        getContentPane().setLayout(new java.awt.GridBagLayout());
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+        setTitle("Connect to a server....");
+        jLabelHostname.setFont(new java.awt.Font("MS Sans Serif", 1, 11));
+        jLabelHostname.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+        jLabelHostname.setText("Server Host:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 0;
+        gridBagConstraints.ipadx = 22;
+        gridBagConstraints.ipady = 5;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
+        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
+        getContentPane().add(jLabelHostname, gridBagConstraints);
+
+        jLabelContext.setFont(new java.awt.Font("MS Sans Serif", 1, 11));
+        jLabelContext.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+        jLabelContext.setText("Servlet Context:");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 1;
+        gridBagConstraints.gridwidth = 2;
+        gridBagConstraints.ipadx = 12;
+        gridBagConstraints.ipady = 5;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
+        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
+        getContentPane().add(jLabelContext, gridBagConstraints);
+
+        jButtonCancel.setText("Cancel");
+        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                jButtonCancelActionPerformed(evt);
+            }
+        });
+
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 3;
+        gridBagConstraints.gridy = 2;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
+        gridBagConstraints.insets = new java.awt.Insets(20, 17, 14, 0);
+        getContentPane().add(jButtonCancel, gridBagConstraints);
+
+        jButtonConnect.setText("Connect");
+        jButtonConnect.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                jButtonConnectActionPerformed(evt);
+            }
+        });
+
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 2;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
+        gridBagConstraints.insets = new java.awt.Insets(20, 110, 14, 0);
+        getContentPane().add(jButtonConnect, gridBagConstraints);
+
+        jTextFieldHost.setText("localhost:8000");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 0;
+        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints.ipadx = 249;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
+        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 19);
+        getContentPane().add(jTextFieldHost, gridBagConstraints);
+
+        jTextFieldContext.setText("wsdm");
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 1;
+        gridBagConstraints.gridwidth = 3;
+        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints.ipadx = 249;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
+        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 19);
+        getContentPane().add(jTextFieldContext, gridBagConstraints);
+
+        pack();
+    }
+
+    private void jButtonConnectActionPerformed(java.awt.event.ActionEvent evt) {
+        setContext(jTextFieldContext.getText());
+        setHostname(jTextFieldHost.getText());
+        setProceed(true);
+        this.dispose();
+    }
+
+    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {
+        this.dispose();
+    }
+    
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String args[]) {
+        java.awt.EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                new GetServerFrame().setVisible(true);
+            }
+        });
+    }
+    
+    // Variables declaration - do not modify
+    private javax.swing.JButton jButtonCancel;
+    private javax.swing.JButton jButtonConnect;
+    private javax.swing.JLabel jLabelContext;
+    private javax.swing.JLabel jLabelHostname;
+    private javax.swing.JTextField jTextFieldContext;
+    private javax.swing.JTextField jTextFieldHost;
+    // End of variables declaration
+    
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/OperationsTableModel.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/OperationsTableModel.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/OperationsTableModel.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/OperationsTableModel.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,110 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 14, 2004
+ *
+ * $RCSfile: OperationsTableModel.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:17 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model.swing;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.swing.table.AbstractTableModel;
+
+import org.apache.ws.client.model.impl.WsdmInstanceImpl;
+
+/**
+ * @author wire
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class OperationsTableModel extends AbstractTableModel {
+
+    private WsdmInstanceImpl m_instance;
+
+    /**
+     * 
+     */
+    public OperationsTableModel(WsdmInstanceImpl instanceToDisplay) {
+        super();
+        m_instance=instanceToDisplay;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.table.TableModel#getColumnCount()
+     */
+    public int getColumnCount() {
+        return 2;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.table.TableModel#getRowCount()
+     */
+    public int getRowCount() {        
+        try {
+       return m_instance.getOperations().length;
+        } catch (SecurityException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalArgumentException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (ClassNotFoundException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (NoSuchMethodException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (InvocationTargetException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return -1;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.table.TableModel#getValueAt(int, int)
+     */
+    public Object getValueAt(int rowIndex, int columnIndex) {
+        try {
+	        switch (columnIndex) {
+	        case 0:
+	                    return m_instance.getOperations()[rowIndex].getName();
+	         case 1:
+	            return m_instance.getOperations()[rowIndex].getParameterNames().toString();
+	        case 2:
+	            return m_instance.getOperations()[rowIndex].getParameterTypes().toString();            
+	        }
+        } catch (SecurityException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalArgumentException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (ClassNotFoundException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (NoSuchMethodException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (InvocationTargetException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/PropertiesTableModel.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/PropertiesTableModel.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/PropertiesTableModel.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/PropertiesTableModel.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,70 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 14, 2004
+ *
+ * $RCSfile: PropertiesTableModel.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:17 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model.swing;
+
+import javax.swing.table.AbstractTableModel;
+
+import org.apache.ws.client.model.impl.WsdmInstanceImpl;
+
+/**
+ * @author wire
+ *
+ */
+public class PropertiesTableModel extends AbstractTableModel {
+    private WsdmInstanceImpl m_instance;
+    /**
+     * 
+     */
+    public PropertiesTableModel(WsdmInstanceImpl instanceToDisplay) {
+        super();
+        m_instance=instanceToDisplay;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.table.TableModel#getColumnCount()
+     */
+    public int getColumnCount() {
+        return 2;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.table.TableModel#getRowCount()
+     */
+    public int getRowCount() {
+        try {
+            return m_instance.getPropertyNames().length;
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return 0;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.table.TableModel#getValueAt(int, int)
+     */
+    public Object getValueAt(int rowIndex, int columnIndex) {
+        try {
+        switch (columnIndex) {
+        case 0:
+                    return m_instance.getPropertyNames()[rowIndex];
+        case 1:
+            return m_instance.getPropertyValue(m_instance.getPropertyNames()[rowIndex]);
+        }
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return null;
+    }
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/Registry.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/Registry.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/Registry.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/Registry.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,35 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 13, 2004
+ *
+ * $RCSfile: Registry.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:17 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model.swing;
+
+import java.util.Vector;
+
+/**
+ * A Dummy Root node for the Tree Model
+ * @author wire
+ *
+ */
+public class Registry extends Vector {
+
+    /**
+     * 
+     */
+    public Registry() {
+        super();
+    }
+    
+    public synchronized String toString() {
+        // TODO Auto-generated method stub
+        return "WSDM Neighborhood";
+    }
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/WsdmTreeModel.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/WsdmTreeModel.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/WsdmTreeModel.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/model/swing/WsdmTreeModel.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,186 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 13, 2004
+ *
+ * $RCSfile: WsdmTreeModel.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:07:17 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model.swing;
+
+import java.util.Iterator;
+
+import javax.swing.event.TreeModelListener;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreePath;
+
+import org.apache.ws.client.model.WsdmInstance;
+import org.apache.ws.client.model.WsdmResource;
+import org.apache.ws.client.model.impl.WsdmInstanceImpl;
+import org.apache.ws.client.model.impl.WsdmResourceImpl;
+import org.apache.ws.client.model.impl.WsdmClientImpl;
+
+/**
+ * A Swing Tree Model build from Wsdm Client Classes.
+ * @author wire
+ *
+ */
+public class WsdmTreeModel implements TreeModel {
+    
+    private Registry mRootNode; 
+    
+    /**
+     * 
+     */
+    public WsdmTreeModel(WsdmClientImpl[] wsdmServers) {
+        super();
+        mRootNode=new Registry();
+        for (int index = 0; index < wsdmServers.length; index++) {
+            WsdmClientImpl client = wsdmServers[index];
+            mRootNode.add(client);            
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeModel#getRoot()
+     */
+    public Object getRoot() {
+        return mRootNode;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object)
+     */
+    public int getChildCount(Object parent) {
+        if(parent instanceof Registry){
+            return mRootNode.size();
+        } else if (parent instanceof WsdmClientImpl){
+            WsdmClientImpl node = (WsdmClientImpl)parent;
+            try {
+                return node.getResources().length;
+            } catch (Exception e) {
+                return 0;
+            } 
+        } else if (parent instanceof WsdmResourceImpl){
+            WsdmResourceImpl node = (WsdmResourceImpl)parent;
+            try {
+                return node.getInstances().length;
+            } catch (Exception e) {
+                return 0;
+            }
+        } else if (parent instanceof WsdmInstanceImpl){
+            return 0;
+        }
+        return 0;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeModel#isLeaf(java.lang.Object)
+     */
+    public boolean isLeaf(Object node) {
+        if(node instanceof WsdmInstanceImpl)
+            return true;
+        else
+            return false;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeModel#addTreeModelListener(javax.swing.event.TreeModelListener)
+     */
+    public void addTreeModelListener(TreeModelListener l) {
+        // TODO wire Not Yet Implemented
+
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeModel#removeTreeModelListener(javax.swing.event.TreeModelListener)
+     */
+    public void removeTreeModelListener(TreeModelListener l) {
+        // TODO wire Not Yet Implemented
+
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int)
+     */
+    public Object getChild(Object parent, int index) {
+        if(parent instanceof Registry){
+            return mRootNode.get(index);
+        } else if (parent instanceof WsdmClientImpl){
+            WsdmClientImpl node = (WsdmClientImpl)parent;
+            try {
+                return node.getResources()[index];
+            } catch (Exception e) {
+                return null;
+            } 
+        } else if (parent instanceof WsdmResourceImpl){
+            WsdmResourceImpl node = (WsdmResourceImpl)parent;
+            try {
+                return node.getInstances()[index];
+            } catch (Exception e) {
+                return null;
+            }
+        } else if (parent instanceof WsdmInstanceImpl){
+            return null;
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeModel#getIndexOfChild(java.lang.Object, java.lang.Object)
+     */
+    public int getIndexOfChild(Object parent, Object child) {
+        if(parent instanceof Registry){
+            mRootNode.size();
+            int index=0;
+            for (Iterator iter = mRootNode.iterator(); iter.hasNext();) {
+                WsdmClientImpl node = (WsdmClientImpl) iter.next();
+                if(node==child){
+                    return index;
+                }
+                index++;
+            }
+        } else if (parent instanceof WsdmClientImpl){
+            WsdmClientImpl node = (WsdmClientImpl)parent;
+            try {
+                WsdmResource[] resources = node.getResources();
+                for (int index = 0; index < resources.length; index++) {
+                    WsdmResource resource = resources[index];
+                    if(resource==child){
+                        return index;
+                    }
+                }
+            } catch (Exception e) {
+                return 0;
+            } 
+        } else if (parent instanceof WsdmResourceImpl){
+            WsdmResourceImpl node = (WsdmResourceImpl)parent;
+            try {
+                WsdmInstance[] resources = node.getInstances();
+                for (int index = 0; index < resources.length; index++) {
+                    WsdmInstance resource = resources[index];
+                    if(resource==child){
+                        return index;
+                    }
+                }
+            } catch (Exception e) {
+                return 0;
+            } 
+        } else if (parent instanceof WsdmInstanceImpl){
+            return -1;
+        }
+        return -1;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeModel#valueForPathChanged(javax.swing.tree.TreePath, java.lang.Object)
+     */
+    public void valueForPathChanged(TreePath path, Object newValue) {
+        // TODO wire Not Yet Implemented. Non Read-Write
+    }
+
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/util/BodyWrapper.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/util/BodyWrapper.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/util/BodyWrapper.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/util/BodyWrapper.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,84 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*/
+package org.apache.ws.client.util;
+
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
+import org.xmlsoap.schemas.soap.envelope.Body;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Wraps an XmlBean generated Body to provide
+ * utility methods for getting at the XmlBean objects.
+ *
+ * @author Ian Springer, Sal Campana
+ */
+public class BodyWrapper
+{
+   private Body m_body;
+
+   /**
+    * Creates a new {@link BodyWrapper} object.
+    *
+    * @param body DOCUMENT_ME
+    */
+   public BodyWrapper( Body body )
+   {
+      m_body = body;
+   }
+
+   /**
+    * Returns the top-level elements from the Body as an XmlBean Object[].
+    *
+    * @return XmlObject[] body elements
+    */
+   public XmlObject[] getBodyElements(  )
+   {
+      XmlCursor xmlCursor = m_body.newCursor(  );
+      xmlCursor.toNextToken(  );
+
+      //get the first child of the body i.e. the response message, or fault
+      XmlObject xmlBeanResponseMessage = xmlCursor.getObject(  );
+      List      xmlObjects = new ArrayList(  );
+      xmlObjects.add( xmlBeanResponseMessage );
+
+      //add the rest of the top-level-elements to the list
+      while ( xmlCursor.toNextSibling(  ) )
+      {
+         xmlObjects.add( xmlCursor.getObject(  ) );
+      }
+
+      xmlCursor.dispose(  );
+      return (XmlObject[]) xmlObjects.toArray( new XmlObject[0] );
+   }
+
+   /**
+    * Returns the top-level body elements with the specified name.
+    *
+    * @return the top-level body elements with the specified name
+    */
+   public XmlObject[] getBodyElements( QName qName )
+   {
+      if ( qName == null )
+      {
+         throw new IllegalArgumentException( "Null name is not allowed." );
+      }
+
+      XmlObject[] allBodyElems = getBodyElements(  );
+      List        bodyElems = new ArrayList(  );
+      for ( int i = 0; i < allBodyElems.length; i++ )
+      {
+         if ( qName.equals( allBodyElems[i].schemaType(  ).getName(  ) ) )
+         {
+            bodyElems.add( allBodyElems[i] );
+         }
+      }
+
+      return (XmlObject[]) bodyElems.toArray( new XmlObject[0] );
+   }
+
+}
\ 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