001/*
002 * (C) Copyright 2010 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.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 *     Anahide Tchertchian
016 */
017package org.nuxeo.ecm.platform.forms.layout.api.impl;
018
019import org.nuxeo.ecm.platform.forms.layout.api.FieldDefinition;
020
021/**
022 * @author Anahide Tchertchian
023 * @since 5.4
024 */
025public class FieldDefinitionImpl implements FieldDefinition {
026
027    private static final long serialVersionUID = 1L;
028
029    protected String schema;
030
031    protected String field;
032
033    // needed by GWT serialization
034    protected FieldDefinitionImpl() {
035    }
036
037    public FieldDefinitionImpl(String schema, String field) {
038        this.schema = schema;
039        this.field = field;
040    }
041
042    public String getSchemaName() {
043        return schema;
044    }
045
046    public String getFieldName() {
047        return field;
048    }
049
050    public String getPropertyName() {
051        if (schema == null || schema.length() == 0) {
052            return field;
053        } else {
054            return schema + ":" + field;
055        }
056    }
057
058    @Override
059    public FieldDefinition clone() {
060        return new FieldDefinitionImpl(schema, field);
061    }
062
063    /**
064     * @since 7.1
065     */
066    @Override
067    public String toString() {
068        final StringBuilder buf = new StringBuilder();
069
070        buf.append("FieldDefinitionImpl");
071        buf.append(" {");
072        buf.append(" schema=");
073        buf.append(schema);
074        buf.append(", field=");
075        buf.append(field);
076        buf.append('}');
077
078        return buf.toString();
079    }
080
081    /**
082     * @since 7.2
083     */
084    @Override
085    public boolean equals(Object obj) {
086        if (!(obj instanceof FieldDefinitionImpl)) {
087            return false;
088        }
089        if (obj == this) {
090            return true;
091        }
092        FieldDefinitionImpl fd = (FieldDefinitionImpl) obj;
093        return new EqualsBuilder().append(schema, fd.schema).append(field, fd.field).isEquals();
094    }
095
096}