001/*
002 * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Bogdan Stefanescu
011 *     Florent Guillaume
012 */
013package org.nuxeo.ecm.core.schema;
014
015import java.util.Collection;
016import java.util.Collections;
017import java.util.HashSet;
018import java.util.List;
019import java.util.Set;
020
021import org.nuxeo.ecm.core.schema.types.CompositeTypeImpl;
022import org.nuxeo.ecm.core.schema.types.Schema;
023
024/**
025 * Implementation of a document type.
026 */
027public class DocumentTypeImpl extends CompositeTypeImpl implements DocumentType {
028
029    private static final long serialVersionUID = 1L;
030
031    protected Set<String> facets;
032
033    protected PrefetchInfo prefetchInfo;
034
035    /**
036     * Constructs a document type. Schemas and facets must include those from the super type.
037     */
038    public DocumentTypeImpl(String name, DocumentType superType, List<Schema> schemas, Collection<String> facets,
039            PrefetchInfo prefetchInfo) {
040        super(superType, SchemaNames.DOCTYPES, name, schemas);
041        if (facets == null) {
042            this.facets = Collections.emptySet();
043        } else {
044            this.facets = new HashSet<String>(facets);
045        }
046        this.prefetchInfo = prefetchInfo;
047    }
048
049    public DocumentTypeImpl(String name) {
050        this(name, null, Collections.<Schema> emptyList(), Collections.<String> emptySet(), null);
051    }
052
053    public void setPrefetchInfo(PrefetchInfo prefetchInfo) {
054        this.prefetchInfo = prefetchInfo;
055    }
056
057    @Override
058    public PrefetchInfo getPrefetchInfo() {
059        return prefetchInfo;
060    }
061
062    @Override
063    public boolean isFile() {
064        return !facets.contains(FacetNames.FOLDERISH);
065    }
066
067    @Override
068    public boolean isFolder() {
069        return facets.contains(FacetNames.FOLDERISH);
070    }
071
072    @Override
073    public boolean isOrdered() {
074        return facets.contains(FacetNames.ORDERABLE);
075    }
076
077    @Override
078    public Set<String> getFacets() {
079        return facets;
080    }
081
082    @Override
083    public boolean hasFacet(String facetName) {
084        return facets.contains(facetName);
085    }
086
087}