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 *     Nicolas Chapurlat <nchapurlat@nuxeo.com>
016 */
017
018package org.nuxeo.ecm.core.api.model.resolver;
019
020import java.util.List;
021
022import org.nuxeo.ecm.core.api.model.Property;
023import org.nuxeo.ecm.core.schema.types.resolver.ObjectResolver;
024
025/**
026 * @since 7.1
027 */
028public class PropertyObjectResolverImpl implements PropertyObjectResolver {
029
030    protected Property property;
031
032    protected ObjectResolver resolver;
033
034    public PropertyObjectResolverImpl(Property property, ObjectResolver resolver) {
035        this.property = property;
036        this.resolver = resolver;
037    }
038
039    @Override
040    public List<Class<?>> getManagedClasses() {
041        return resolver.getManagedClasses();
042    }
043
044    @Override
045    public boolean validate() {
046        return resolver.validate(property.getValue());
047    }
048
049    @Override
050    public Object fetch() {
051        return resolver.fetch(property.getValue());
052    }
053
054    @Override
055    public <T> T fetch(Class<T> type) {
056        return resolver.fetch(type, property.getValue());
057    }
058
059    @Override
060    public void setObject(Object object) {
061        Object reference = resolver.getReference(object);
062        property.setValue(reference);
063    }
064
065    @Override
066    public ObjectResolver getObjectResolver() {
067        return resolver;
068    }
069
070}