package edu.colorado.csdms.wmt.client.data;

import java.util.Vector;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;

/**
 * A GWT JavaScript overlay (JSO) type that describes a WMT component model,
 * with "id", "name", "url", "provides" and "uses" attributes. Declares JSNI
 * methods to access these attributes from a JSON and modify them in memory.
 * 
 * @see <a
 *      href="http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsOverlay.html">http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsOverlay.html</a>
 * @author Mark Piper (mark.piper@colorado.edu)
 * 
 */
public class ComponentJSO extends JavaScriptObject {

  // Overlay types have protected, no-arg, constructors.
  protected ComponentJSO() {
  }

  /**
   * A JSNI method to access the "id" attribute of a WMT component model. This
   * attribute is always present, and is a string.
   */
  public final native String getId() /*-{
		return this.id;
  }-*/;

  /**
   * A JSNI method to access the "name" attribute of a WMT component model.
   * This attribute is always present, and is a string.
   */
  public final native String getName() /*-{
		return this.name;
  }-*/;

  /**
   * A JSNI method to access the "url" attribute of a WMT component model.
   * This attribute is always present, and is a string.
   */
  public final native String getURL() /*-{
		return this.url;
  }-*/;

  /**
   * A JSNI method to access the "provides" attribute of a WMT component
   * model. This attribute is a JsArray of PortJSO objects. It's always
   * present, but it may be empty.
   */
  public final native JsArray<PortJSO> getPortsProvided() /*-{
		return this.provides;
  }-*/;

  /**
   * A JSNI method to access the "uses" attribute of a WMT component model.
   * This attribute is a JsArray of PortJSO objects. It's always present, but
   * it may be empty.
   */
  public final native JsArray<PortJSO> getPortsUsed() /*-{
		return this.uses;
  }-*/;

  /**
   * A JSNI method that returns the JsArray of component parameters.
   */
  public final native JsArray<ParameterJSO> getParameters() /*-{
		return this.parameters;
  }-*/;  

  /**
   * A JSNI method that returns a ParameterJSO by its "key" attribute.
   * 
   * @param key The key of the desired parameter, a String.
   */
  public final native ParameterJSO getParameter(String key) /*-{
		var parameterArray = this.parameters;
		for (var i = 0; i < parameterArray.length; i++) {
			parameter = parameterArray[i]
			if (parameter.key === key) {
				return parameter;
			}
		}
		return null;
  }-*/;  
  
  /**
   * A non-JSNI method for stringifying the attributes of a Component. Must be
   * final.
   */
  public final Vector<String> toStringVector() {

    Vector<String> retVal = new Vector<String>();
    retVal.add("id: " + getId());
    retVal.add("name: " + getName());
    retVal.add("url: " + getURL());
    for (int i = 0; i < getPortsProvided().length(); i++) {
      retVal.add("provides: " + getPortsProvided().get(i).toStringVector().toString());
    }
    for (int i = 0; i < getPortsUsed().length(); i++) {
      retVal.add("uses: " + getPortsUsed().get(i).toStringVector().toString());
    }
    return retVal;
  }
}

@@ -1404,32 +1404,1222 @@
 s.url;%0A  %7D-*/;%0A%0A
+  /**%0A   * A JSNI method to get the %22summary%22 attribute of a component.%0A   */%0A  public final native String getSummary() /*-%7B%0A%09%09return (typeof this.summary != 'undefined') ? this.summary : null;%0A  %7D-*/;%0A%0A  /**%0A   * A JSNI method to get the %22author%22 attribute of a component.%0A   */%0A  public final native String getAuthor() /*-%7B%0A%09%09return (typeof this.author != 'undefined') ? this.author : null;%0A  %7D-*/;%0A%0A  /**%0A   * A JSNI method to get the %22email%22 attribute of a component.%0A   */%0A  public final native String getEmail() /*-%7B%0A%09%09return (typeof this.email != 'undefined') ? this.email : null;%0A  %7D-*/;%0A%0A  /**%0A   * A JSNI method to get the %22version%22 attribute of a component.%0A   */%0A  public final native String getVersion() /*-%7B%0A%09%09return (typeof this.version != 'undefined') ? this.version : null;%0A  %7D-*/;%0A%0A  /**%0A   * A JSNI method to get the %22license%22 attribute of a component.%0A   */%0A  public final native String getLicense() /*-%7B%0A%09%09return (typeof this.license != 'undefined') ? this.license : null;%0A  %7D-*/;%0A%0A  /**%0A   * A JSNI method to get the %22doi%22 attribute of a component.%0A   */%0A  public final native String getDoi() /*-%7B%0A%09%09return (typeof this.doi != 'undefined') ? this.doi : null;%0A  %7D-*/;%0A%0A
   /**%0A   * A JSN
@@ -2681,16 +2681,16 @@
 mponent%0A
-
    * mod
@@ -3345,18 +3345,16 @@
 %0A  %7D-*/;
-  
 %0A%0A  /**%0A
@@ -3771,21 +3771,17 @@
 %0A  %7D-*/;
-  %0A  
+%0A
 %0A  /**%0A 
@@ -4136,32 +4136,32 @@
 ength(); i++) %7B%0A
-
       retVal.add
@@ -4169,24 +4169,34 @@
 %22provides: %22
+%0A         
  + getPortsP

Add methods to read new metadata fields in a component