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