001/* 002 * (C) Copyright 2006-2012 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 * Bogdan Stefanescu 018 * Florent Guillaume 019 */ 020package org.nuxeo.ecm.core.schema; 021 022import java.util.Collection; 023import java.util.Collections; 024import java.util.HashSet; 025import java.util.List; 026import java.util.Set; 027 028import org.nuxeo.ecm.core.schema.types.CompositeTypeImpl; 029import org.nuxeo.ecm.core.schema.types.Schema; 030 031/** 032 * Implementation of a document type. 033 */ 034public class DocumentTypeImpl extends CompositeTypeImpl implements DocumentType { 035 036 private static final long serialVersionUID = 1L; 037 038 protected Set<String> facets; 039 040 protected PrefetchInfo prefetchInfo; 041 042 /** 043 * Constructs a document type. Schemas and facets must include those from the super type. 044 */ 045 public DocumentTypeImpl(String name, DocumentType superType, List<Schema> schemas, Collection<String> facets, 046 PrefetchInfo prefetchInfo) { 047 super(superType, SchemaNames.DOCTYPES, name, schemas); 048 if (facets == null) { 049 this.facets = Collections.emptySet(); 050 } else { 051 this.facets = new HashSet<String>(facets); 052 } 053 this.prefetchInfo = prefetchInfo; 054 } 055 056 public DocumentTypeImpl(String name) { 057 this(name, null, Collections.<Schema> emptyList(), Collections.<String> emptySet(), null); 058 } 059 060 public void setPrefetchInfo(PrefetchInfo prefetchInfo) { 061 this.prefetchInfo = prefetchInfo; 062 } 063 064 @Override 065 public PrefetchInfo getPrefetchInfo() { 066 return prefetchInfo; 067 } 068 069 @Override 070 public boolean isFile() { 071 return !facets.contains(FacetNames.FOLDERISH); 072 } 073 074 @Override 075 public boolean isFolder() { 076 return facets.contains(FacetNames.FOLDERISH); 077 } 078 079 @Override 080 public boolean isOrdered() { 081 return facets.contains(FacetNames.ORDERABLE); 082 } 083 084 @Override 085 public Set<String> getFacets() { 086 return facets; 087 } 088 089 @Override 090 public boolean hasFacet(String facetName) { 091 return facets.contains(facetName); 092 } 093 094}