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 *     Nuxeo - initial API and implementation
018 *
019 * $Id: CreationContainerListProviderDescriptor.java 30594 2008-02-26 17:21:10Z ogrisel $
020 */
021
022package org.nuxeo.ecm.platform.filemanager.service.extension;
023
024import java.util.ArrayList;
025import java.util.List;
026
027import org.nuxeo.common.xmap.annotation.XNode;
028import org.nuxeo.common.xmap.annotation.XNodeList;
029import org.nuxeo.common.xmap.annotation.XObject;
030import org.nuxeo.ecm.core.api.NuxeoException;
031import org.nuxeo.runtime.model.Descriptor;
032
033@XObject("creationContainerListProvider")
034public class CreationContainerListProviderDescriptor implements Descriptor {
035
036    @XNode("@name")
037    protected String name;
038
039    /**
040     * @deprecated since 11.1.
041     */
042    @Deprecated(since = "11.1")
043    @XNode("@class")
044    protected String className;
045
046    @XNode("@class")
047    protected Class<? extends CreationContainerListProvider> klass;
048
049    @XNodeList(value = "docType", type = ArrayList.class, componentType = String.class)
050    protected List<String> docTypes = new ArrayList<>();
051
052    public String getName() {
053        return name;
054    }
055
056    /**
057     * @deprecated since 11.1.
058     */
059    @Deprecated(since = "11.1")
060    public String getClassName() {
061        return className;
062    }
063
064    public String[] getDocTypes() {
065        return docTypes.toArray(new String[docTypes.size()]);
066    }
067
068    /**
069     * @since 11.1
070     */
071    public CreationContainerListProvider newInstance() {
072        try {
073            CreationContainerListProvider provider = klass.getDeclaredConstructor().newInstance();
074            provider.setName(name);
075            provider.setDocTypes(getDocTypes());
076            return provider;
077        } catch (ReflectiveOperationException e) {
078            throw new NuxeoException(e);
079        }
080    }
081
082    @Override
083    public String getId() {
084        return name;
085    }
086}