001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 *     Florent Guillaume
017 */
018package org.nuxeo.ecm.platform.relations.descriptors;
019
020import java.io.Serializable;
021import java.util.HashMap;
022import java.util.Map;
023
024import org.nuxeo.common.xmap.annotation.XNode;
025import org.nuxeo.common.xmap.annotation.XNodeMap;
026import org.nuxeo.common.xmap.annotation.XObject;
027import org.nuxeo.ecm.platform.relations.api.GraphDescription;
028import org.nuxeo.runtime.api.Framework;
029
030/**
031 * Graph descriptor.
032 */
033@XObject("graph")
034public class GraphDescriptor implements GraphDescription, Serializable {
035
036    private static final long serialVersionUID = 1L;
037
038    @XNode("@name")
039    public String name;
040
041    @XNode("@type")
042    public String graphType;
043
044    public Map<String, String> options = new HashMap<String, String>();
045
046    @XNodeMap(value = "namespaces/namespace", key = "@name", type = HashMap.class, componentType = String.class)
047    public Map<String, String> namespaces = new HashMap<String, String>();
048
049    @Override
050    public String getName() {
051        return name;
052    }
053
054    @Override
055    public String getGraphType() {
056        return graphType;
057    }
058
059    @Override
060    public Map<String, String> getOptions() {
061        return options;
062    }
063
064    @XNodeMap(value = "option", key = "@name", type = HashMap.class, componentType = String.class)
065    public void setOptions(Map<String, String> options) {
066        // expand vars on the options
067        Map<String, String> map = new HashMap<String, String>();
068        for (Map.Entry<String, String> entry : options.entrySet()) {
069            String value = entry.getValue();
070            map.put(entry.getKey(), Framework.getRuntime().expandVars(value));
071        }
072        this.options = map;
073    }
074
075    @Override
076    public Map<String, String> getNamespaces() {
077        return namespaces;
078    }
079
080}