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