001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS (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 *     <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
016 *
017 * $Id: WidgetTypeDescriptor.java 26053 2007-10-16 01:45:43Z atchertchian $
018 */
019
020package org.nuxeo.ecm.platform.forms.layout.descriptors;
021
022import java.util.ArrayList;
023import java.util.HashMap;
024import java.util.List;
025import java.util.Map;
026
027import org.nuxeo.common.xmap.annotation.XNode;
028import org.nuxeo.common.xmap.annotation.XNodeList;
029import org.nuxeo.common.xmap.annotation.XNodeMap;
030import org.nuxeo.common.xmap.annotation.XObject;
031import org.nuxeo.ecm.platform.forms.layout.api.WidgetTypeConfiguration;
032import org.nuxeo.ecm.platform.forms.layout.api.WidgetTypeDefinition;
033import org.nuxeo.ecm.platform.forms.layout.api.impl.WidgetTypeDefinitionImpl;
034
035/**
036 * Widget type descriptor.
037 *
038 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
039 */
040@XObject("widgetType")
041public class WidgetTypeDescriptor {
042
043    @XNode("@name")
044    String name;
045
046    /**
047     * @since 6.0
048     */
049    @XNodeList(value = "aliases/alias", type = ArrayList.class, componentType = String.class)
050    List<String> aliases;
051
052    @XNode("handler-class")
053    String handlerClassName;
054
055    @XNodeMap(value = "property", key = "@name", type = HashMap.class, componentType = String.class)
056    Map<String, String> properties;
057
058    @XNode("configuration")
059    WidgetTypeConfigurationDescriptor configuration;
060
061    @XNodeList(value = "categories/category", type = String[].class, componentType = String.class)
062    String[] categories = new String[0];
063
064    public String getName() {
065        return name;
066    }
067
068    public List<String> getAliases() {
069        return aliases;
070    }
071
072    public String getHandlerClassName() {
073        return handlerClassName;
074    }
075
076    public Map<String, String> getProperties() {
077        return properties;
078    }
079
080    public WidgetTypeConfiguration getConfiguration() {
081        if (configuration == null) {
082            return null;
083        }
084        return configuration.getWidgetTypeConfiguration();
085    }
086
087    /**
088     * Returns the categories for this widget type, so that it can be stored in the corresponding registries.
089     *
090     * @since 5.5
091     */
092    public String[] getCategories() {
093        return categories;
094    }
095
096    public WidgetTypeDefinition getWidgetTypeDefinition() {
097        WidgetTypeDefinitionImpl res = new WidgetTypeDefinitionImpl(name, handlerClassName, properties,
098                getConfiguration());
099        res.setAliases(getAliases());
100        return res;
101
102    }
103
104}