001/*
002 * (C) Copyright 2014 Nuxeo SA (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-2.1.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 *     tdelprat
016 */
017package org.nuxeo.ecm.restapi.jaxrs.io.types;
018
019import java.util.HashSet;
020import java.util.Set;
021
022import org.nuxeo.ecm.core.schema.DocumentType;
023import org.nuxeo.ecm.core.schema.types.Schema;
024
025public class DocumentTypes {
026
027    protected final DocumentType[] docTypes;
028
029    protected Set<Schema> usedSchemas = null;
030
031    public DocumentTypes(DocumentType[] docTypes) {
032        this.docTypes = docTypes;
033    }
034
035    protected Set<Schema> getUsedSchemas() {
036        if (usedSchemas == null) {
037            usedSchemas = new HashSet<Schema>();
038            for (DocumentType type : docTypes) {
039                for (Schema schema : type.getSchemas()) {
040                    usedSchemas.add(schema);
041                }
042            }
043        }
044        return usedSchemas;
045    }
046
047    public Schema[] getSchemas() {
048        Set<Schema> schemas = getUsedSchemas();
049        return schemas.toArray(new Schema[schemas.size()]);
050    }
051
052    public DocumentType[] getDocTypes() {
053        return docTypes;
054    }
055
056}