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 * Nicolas Chapurlat <nchapurlat@nuxeo.com> 020 */ 021package org.nuxeo.ecm.core.schema.types; 022 023import java.util.HashSet; 024import java.util.Set; 025 026import org.nuxeo.ecm.core.schema.SchemaNames; 027import org.nuxeo.ecm.core.schema.types.constraints.Constraint; 028import org.nuxeo.ecm.core.schema.types.constraints.TypeConstraint; 029import org.nuxeo.ecm.core.schema.types.resolver.ObjectResolver; 030 031/** 032 * Primitive type (basic types like long, string, boolean, etc.). 033 */ 034public abstract class PrimitiveType extends AbstractType implements SimpleType { 035 036 private static final long serialVersionUID = -2698475002119528248L; 037 038 protected PrimitiveType(String name) { 039 super(null, SchemaNames.BUILTIN, name); 040 } 041 042 @Override 043 public abstract boolean validate(Object object); 044 045 @Override 046 public ObjectResolver getObjectResolver() { 047 return null; 048 } 049 050 @Override 051 public Type getSuperType() { 052 return null; 053 } 054 055 @Override 056 public Type[] getTypeHierarchy() { 057 return EMPTY_SUPERTYPES; 058 } 059 060 // FIXME: IType doesn't have an isPrimitive method. 061 @Override 062 public boolean isPrimitive() { 063 return true; 064 } 065 066 @Override 067 public boolean isSimpleType() { 068 return true; 069 } 070 071 @Override 072 public PrimitiveType getPrimitiveType() { 073 return this; 074 } 075 076 /** 077 * @return true if this primitive types supports this constraints, false otherwise. 078 * @since 7.1 079 */ 080 public abstract boolean support(Class<? extends Constraint> constraint); 081 082 @Override 083 public Set<Constraint> getConstraints() { 084 Set<Constraint> constraints = new HashSet<Constraint>(); 085 constraints.add(new TypeConstraint(this)); 086 return constraints; 087 } 088 089}