001/*
002 * (C) Copyright 2006-2011 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 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.core.api.model.impl;
023
024import java.io.Serializable;
025
026import org.nuxeo.ecm.core.api.PropertyException;
027import org.nuxeo.ecm.core.api.model.Property;
028import org.nuxeo.ecm.core.api.model.PropertyVisitor;
029import org.nuxeo.ecm.core.schema.types.ComplexType;
030import org.nuxeo.ecm.core.schema.types.Field;
031
032/**
033 * Phantom properties are not stored as children objects.
034 *
035 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
036 */
037public class MapProperty extends ComplexProperty {
038
039    private static final long serialVersionUID = 8061007679778603750L;
040
041    /**
042     * The corresponding field.
043     */
044    protected final Field field;
045
046    public MapProperty(Property parent, Field field) {
047        super(parent);
048        this.field = field;
049    }
050
051    public MapProperty(Property parent, Field field, int flags) {
052        super(parent, flags);
053        this.field = field;
054    }
055
056    @Override
057    public void internalSetValue(Serializable value) throws PropertyException {
058    }
059
060    @Override
061    public boolean isContainer() {
062        return true;
063    }
064
065    @Override
066    public String getName() {
067        return field.getName().getPrefixedName();
068    }
069
070    @Override
071    public ComplexType getType() {
072        return (ComplexType) field.getType();
073    }
074
075    @Override
076    public Field getField() {
077        return field;
078    }
079
080    @Override
081    public Object clone() throws CloneNotSupportedException {
082        MapProperty clone = (MapProperty) super.clone();
083        return clone;
084    }
085
086    @Override
087    public void accept(PropertyVisitor visitor, Object arg) throws PropertyException {
088        arg = visitor.visit(this, arg);
089        if (arg != null) {
090            visitChildren(visitor, arg);
091        }
092    }
093
094}