package org.jivesoftware.smack.packet;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.util.XmlStringBuilder;

public class DefaultExtensionElement implements ExtensionElement {
   private String elementName;
   private String namespace;
   private Map<String, String> map;

   public DefaultExtensionElement(String elementName, String namespace) {
      this.elementName = elementName;
      this.namespace = namespace;
   }

   public String getElementName() {
      return this.elementName;
   }

   public String getNamespace() {
      return this.namespace;
   }

   public CharSequence toXML() {
      XmlStringBuilder buf = new XmlStringBuilder();
      buf.halfOpenElement(this.elementName).xmlnsAttribute(this.namespace).rightAngleBracket();
      Iterator i$ = this.getNames().iterator();

      while(i$.hasNext()) {
         String name = (String)i$.next();
         String value = this.getValue(name);
         buf.element(name, value);
      }

      buf.closeElement(this.elementName);
      return buf;
   }

   public synchronized Collection<String> getNames() {
      return this.map == null ? Collections.emptySet() : Collections.unmodifiableSet((new HashMap(this.map)).keySet());
   }

   public synchronized String getValue(String name) {
      return this.map == null ? null : (String)this.map.get(name);
   }

   public synchronized void setValue(String name, String value) {
      if (this.map == null) {
         this.map = new HashMap();
      }

      this.map.put(name, value);
   }
}
