001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Anahide Tchertchian
018 *     Florent Guillaume
019 */
020package org.nuxeo.ecm.platform.relations.descriptors;
021
022import java.util.HashMap;
023import java.util.Map;
024
025import org.nuxeo.common.xmap.annotation.XNode;
026import org.nuxeo.common.xmap.annotation.XNodeMap;
027import org.nuxeo.common.xmap.annotation.XObject;
028import org.nuxeo.ecm.platform.relations.api.GraphDescription;
029import org.nuxeo.runtime.api.Framework;
030
031/**
032 * Graph descriptor.
033 */
034@XObject("graph")
035public class GraphDescriptor implements GraphDescription {
036
037    @XNode("@name")
038    public String name;
039
040    @XNode("@type")
041    public String graphType;
042
043    public Map<String, String> options = new HashMap<>();
044
045    @XNodeMap(value = "namespaces/namespace", key = "@name", type = HashMap.class, componentType = String.class)
046    public Map<String, String> namespaces = new HashMap<>();
047
048    @Override
049    public String getName() {
050        return name;
051    }
052
053    @Override
054    public String getGraphType() {
055        return graphType;
056    }
057
058    @Override
059    public Map<String, String> getOptions() {
060        return options;
061    }
062
063    @XNodeMap(value = "option", key = "@name", type = HashMap.class, componentType = String.class)
064    public void setOptions(Map<String, String> options) {
065        // expand vars on the options
066        Map<String, String> map = new HashMap<>();
067        for (Map.Entry<String, String> entry : options.entrySet()) {
068            String value = entry.getValue();
069            map.put(entry.getKey(), Framework.getRuntime().expandVars(value));
070        }
071        this.options = map;
072    }
073
074    @Override
075    public Map<String, String> getNamespaces() {
076        return namespaces;
077    }
078
079}