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