package storageresources.mo.config;

import java.util.Collection;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;

/**
 * @author moroz
 */
@XmlRootElement(name = "config")
public class Config {

    public static class Param {

        @XmlAttribute
        public String key;
      
        @XmlValue
        public String value;

        public Param() {
        }

        public Param(String key, String value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public int hashCode() {
            int hash = 7;
            hash = 61 * hash + (this.key != null ? this.key.hashCode() : 0);
            hash = 61 * hash + (this.value != null ? this.value.hashCode() : 0);
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Param other = (Param) obj;
            if ((this.key == null) ? (other.key != null) : !this.key.equals(other.key)) {
                return false;
            }
            if ((this.value == null) ? (other.value != null) : !this.value.equals(other.value)) {
                return false;
            }
            return true;
        }
        
    }

    private String key;

    private Collection<Param> params;

    private Collection<Config> configs;

    @XmlAttribute(name = "key")
    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    @XmlElementWrapper(name = "params")
    @XmlElement(name = "param")
    public Collection<Param> getParams() {
        return params;
    }

    public void setParams(Collection<Param> params) {
        this.params = params;
    }

    @XmlElementWrapper(name = "configs")
    @XmlElement(name = "config")
    public Collection<Config> getConfigs() {
        return configs;
    }

    public void setConfigs(Collection<Config> configs) {
        this.configs = configs;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + (this.key != null ? this.key.hashCode() : 0);
        hash = 79 * hash + (this.params != null ? this.params.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Config other = (Config) obj;
        if ((this.key == null) ? (other.key != null) : !this.key.equals(other.key)) {
            return false;
        }
        if (this.params != other.params && (this.params == null || !this.params.equals(other.params))) {
            return false;
        }
        if (this.configs != other.configs && (this.configs == null || !this.configs.equals(other.configs))) {
            return false;
        }
        return true;
    }

}

@@ -459,23 +459,17 @@
 ng key;%0A
-      
 %0A
+
         
@@ -656,32 +656,151 @@
 lue;%0A        %7D%0A%0A
+        public String get(String key) %7B%0A            return (this.key.equalsIgnoreCase(key)) ? value : null;%0A        %7D%0A%0A
         @Overrid
@@ -1642,17 +1642,9 @@
   %7D%0A
-        
 %0A
+
     
@@ -1706,24 +1706,24 @@
 m%3E params;%0A%0A
-
     private 
@@ -1747,24 +1747,601 @@
 %3E configs;%0A%0A
+    public String getParamValue(String configKey, String paramKey) %7B%0A%0A        if (this.key.equalsIgnoreCase(configKey)) %7B%0A            for (Param param : params) %7B%0A                String ret = param.get(paramKey);%0A                if (ret != null) %7B%0A                    return ret;%0A                %7D%0A            %7D%0A        %7D else %7B%0A            for (Config cfg : configs) %7B%0A                String ret = cfg.getParamValue(configKey, paramKey);%0A                if (ret != null) %7B%0A                    return ret;%0A                %7D%0A            %7D%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A
     @XmlAttr

work on config