package org.jboss.as.console.client.shared.subsys.ws;

import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.shared.BeanFactory;
import org.jboss.as.console.client.shared.subsys.ws.model.WebServiceEndpoint;
import org.jboss.dmr.client.ModelNode;
import org.jboss.dmr.client.Property;
import org.jboss.dmr.client.dispatch.DispatchAsync;

import java.util.List;

import static org.jboss.dmr.client.ModelDescriptionConstants.ADDRESS;
import static org.jboss.dmr.client.ModelDescriptionConstants.RESULT;

/**
 * @author Heiko Braun
 * @date 1/24/12
 */
public class BaseRegistry {

    final static String NO_METRICS = "WFLYWS0037: No metrics available";

    DispatchAsync dispatcher;BeanFactory factory;

    public BaseRegistry(BeanFactory factory, DispatchAsync dispatcher) {
        this.factory = factory;
        this.dispatcher = dispatcher;
    }

    protected void parseEndpoints(ModelNode model, List<WebServiceEndpoint> endpoints) {
        if(model.hasDefined(RESULT))
        {
            List<ModelNode> modelNodes = model.get(RESULT).asList();

            for(ModelNode node : modelNodes)
            {

                List<Property> addressTokens = node.get(ADDRESS).asPropertyList();

                ModelNode value = node.get(RESULT).asObject();
                WebServiceEndpoint endpoint = factory.webServiceEndpoint().as();

                endpoint.setName(value.get("name").asString());
                endpoint.setClassName(value.get("class").asString());
                endpoint.setContext(value.get("context").asString());
                endpoint.setType(value.get("type").asString());
                endpoint.setWsdl(value.get("wsdl-url").asString());
                endpoint.setDeployment(addressTokens.get(0).getValue().asString());

                // the following needs 'statistics-enabled == true'
                // TODO Is this error message valid / stable across community & product versions?
                if (NO_METRICS.equals(value.get("request-count").asString())) {
                    Console.warning("Web Service statistics are not enabled", "To see runtime data like number of requests, please turn on statistics in the webservice configuration.");
                } else {
                    endpoint.setRequestCount(value.get("request-count").asInt(0));
                    endpoint.setResponseCount(value.get("response-count").asInt(0));
                    endpoint.setFaultCount(value.get("fault-count").asInt(0));
                    endpoint.setMinProcessingTime(value.get("min-processing-time").asInt(0));
                    endpoint.setAverageProcessingTime(value.get("average-processing-time").asInt(0));
                    endpoint.setMaxProcessingTime(value.get("max-processing-time").asInt(0));
                    endpoint.setTotalProcessingTime(value.get("total-processing-time").asInt(0));
                }
                endpoints.add(endpoint);
            }
        }
    }
}

@@ -600,82 +600,8 @@
  %7B%0A%0A
-    final static String NO_METRICS = %22WFLYWS0037: No metrics available%22;%0A%0A
     
@@ -1059,24 +1059,102 @@
          %7B%0A%0A
+                WebServiceEndpoint endpoint = null;%0A                try %7B%0A    
             
@@ -1241,16 +1241,20 @@
         
+    
 ModelNod
@@ -1308,34 +1308,19 @@
         
-WebServiceEndpoint
+   
  endpoin
@@ -1355,24 +1355,28 @@
 nt().as();%0A%0A
+    
             
@@ -1435,32 +1435,36 @@
                 
+   
+ 
 endpoint.setClas
@@ -1493,32 +1493,36 @@
 %22).asString());%0A
+    
                 
@@ -1567,32 +1567,36 @@
 %22).asString());%0A
+    
                 
@@ -1651,32 +1651,36 @@
                 
+    
 endpoint.setWsdl
@@ -1707,32 +1707,36 @@
 %22).asString());%0A
+    
                 
@@ -1808,465 +1808,8 @@
 );%0A%0A
-                // the following needs 'statistics-enabled == true'%0A                // TODO Is this error message valid / stable across community & product versions?%0A                if (NO_METRICS.equals(value.get(%22request-count%22).asString())) %7B%0A                    Console.warning(%22Web Service statistics are not enabled%22, %22To see runtime data like number of requests, please turn on statistics in the webservice configuration.%22);%0A                %7D else %7B%0A
     
@@ -2448,32 +2448,226 @@
                %7D
+ catch (IllegalArgumentException e) %7B%0A                    Console.error(%22Failed to parse response. Are the statistics enabled?%22, e.getMessage());%0A                    continue;%0A                %7D%0A
 %0A               

Rollback HAL-895