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.io.Serializable;
023import java.util.HashMap;
024import java.util.Map;
025
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XNodeMap;
028import org.nuxeo.common.xmap.annotation.XObject;
029import org.nuxeo.ecm.platform.relations.api.GraphDescription;
030import org.nuxeo.runtime.api.Framework;
031
032/**
033 * Graph descriptor.
034 */
035@XObject("graph")
036public class GraphDescriptor implements GraphDescription, Serializable {
037
038    private static final long serialVersionUID = 1L;
039
040    @XNode("@name")
041    public String name;
042
043    @XNode("@type")
044    public String graphType;
045
046    public Map<String, String> options = new HashMap<String, String>();
047
048    @XNodeMap(value = "namespaces/namespace", key = "@name", type = HashMap.class, componentType = String.class)
049    public Map<String, String> namespaces = new HashMap<String, String>();
050
051    @Override
052    public String getName() {
053        return name;
054    }
055
056    @Override
057    public String getGraphType() {
058        return graphType;
059    }
060
061    @Override
062    public Map<String, String> getOptions() {
063        return options;
064    }
065
066    @XNodeMap(value = "option", key = "@name", type = HashMap.class, componentType = String.class)
067    public void setOptions(Map<String, String> options) {
068        // expand vars on the options
069        Map<String, String> map = new HashMap<String, String>();
070        for (Map.Entry<String, String> entry : options.entrySet()) {
071            String value = entry.getValue();
072            map.put(entry.getKey(), Framework.getRuntime().expandVars(value));
073        }
074        this.options = map;
075    }
076
077    @Override
078    public Map<String, String> getNamespaces() {
079        return namespaces;
080    }
081
082}