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