001/*
002 * (C) Copyright 2008 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: AbstractCreationContainerListProvider.java 30586 2008-02-26 14:30:17Z ogrisel $
020 */
021
022package org.nuxeo.ecm.platform.filemanager.service.extension;
023
024import java.util.Arrays;
025
026/**
027 * Helper class to contribute CreationContainerListProvider implementation to the FileManagerService.
028 *
029 * @author Olivier Grisel (ogrisel@nuxeo.com)
030 */
031public abstract class AbstractCreationContainerListProvider implements CreationContainerListProvider {
032
033    private String name = "";
034
035    private String[] docTypes;
036
037    public boolean accept(String docType) {
038        if (docTypes == null || docTypes.length == 0) {
039            return true;
040        } else {
041            return Arrays.asList(docTypes).contains(docType);
042        }
043    }
044
045    public String getName() {
046        return name;
047    }
048
049    public void setName(String name) {
050        this.name = name;
051    }
052
053    public String[] getDocTypes() {
054        return docTypes;
055    }
056
057    public void setDocTypes(String[] docTypes) {
058        this.docTypes = docTypes;
059    }
060
061    @Override
062    public boolean equals(Object o) {
063        if (o instanceof CreationContainerListProvider) {
064            // casting on the interface gives no guarantee that the equals
065            // relationship will be symmetric but this is documented in the interface
066            // javadoc of the getName method
067            CreationContainerListProvider provider = (CreationContainerListProvider) o;
068            return name != null && name.equals(provider.getName());
069        }
070        return false;
071    }
072
073    @Override
074    public int hashCode() {
075        return name != null ? name.hashCode() : 0;
076    }
077
078}