001package conexp.fx.core.xml;
002
003/*
004 * #%L
005 * Concept Explorer FX
006 * %%
007 * Copyright (C) 2010 - 2023 Francesco Kriegel
008 * %%
009 * This program is free software: you can redistribute it and/or modify
010 * it under the terms of the GNU General Public License as
011 * published by the Free Software Foundation, either version 3 of the
012 * License, or (at your option) any later version.
013 * 
014 * This program is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 * 
019 * You should have received a copy of the GNU General Public
020 * License along with this program.  If not, see
021 * <http://www.gnu.org/licenses/gpl-3.0.html>.
022 * #L%
023 */
024
025
026import java.util.Collections;
027import java.util.HashMap;
028import java.util.Map;
029
030import org.jsoup.nodes.Element;
031
032import conexp.fx.core.collections.Pair;
033
034public final class Metadata extends Data<Element> {
035
036  public Metadata(final Element element) throws NullPointerException, IndexOutOfBoundsException {
037    super(Datatype.METADATA, "metadata", JsoupUtil.firstChildByTag(element, "metadata"));
038  }
039
040  public synchronized final String getSubkey() throws NullPointerException {
041    return JsoupUtil.firstChildByTag(value, "subkey").text();
042  }
043
044  public synchronized final Map<String, Pair<Datatype, Metadata>> getKeyDatatypeMap() throws NullPointerException {
045    final Map<String, Pair<Datatype, Metadata>> map = new HashMap<String, Pair<Datatype, Metadata>>();
046    for (Element data : JsoupUtil.childrenByTag(value, "data")) {
047      final String key = JsoupUtil.firstChildByTag(data, "key").text();
048      final Datatype type = Datatype.valueOf(JsoupUtil.firstChildByTag(data, "type").text());
049      switch (type) {
050      case COMPOUND:
051      case COMPOUND_LIST:
052      case BOOLEAN_LIST:
053      case INTEGER_LIST:
054      case STRING_LIST:
055        map.put(key, new Pair<Datatype, Metadata>(type, new Metadata(data)));
056        break;
057      default:
058        map.put(key, new Pair<Datatype, Metadata>(type, null));
059      }
060    }
061    return Collections.unmodifiableMap(map);
062  }
063
064}