001/*
002 * (C) Copyright 2012 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 *     Antoine Taillefer
018 */
019package org.nuxeo.ecm.diff.service.impl;
020
021import java.util.ArrayList;
022import java.util.List;
023
024import org.nuxeo.common.xmap.annotation.XNode;
025import org.nuxeo.common.xmap.annotation.XNodeList;
026import org.nuxeo.common.xmap.annotation.XObject;
027import org.nuxeo.ecm.diff.model.DiffComplexFieldDefinition;
028import org.nuxeo.ecm.diff.model.DiffFieldItemDefinition;
029import org.nuxeo.ecm.diff.model.impl.DiffComplexFieldDefinitionImpl;
030
031/**
032 * Diff complex field descriptor.
033 *
034 * @author Antoine Taillefer (ataillefer@nuxeo.com)
035 * @since 5.6
036 */
037@XObject("diffComplexField")
038public class DiffComplexFieldDescriptor {
039
040    @XNode("@schema")
041    public String schema;
042
043    @XNode("@name")
044    public String name;
045
046    @XNodeList(value = "includedItems/item", type = ArrayList.class, componentType = DiffFieldItemDescriptor.class)
047    public List<DiffFieldItemDescriptor> includedItems;
048
049    @XNodeList(value = "excludedItems/item", type = ArrayList.class, componentType = DiffFieldItemDescriptor.class)
050    public List<DiffFieldItemDescriptor> excludedItems;
051
052    public String getSchema() {
053        return schema;
054    }
055
056    public void setSchema(String schema) {
057        this.schema = schema;
058    }
059
060    public String getName() {
061        return name;
062    }
063
064    public void setName(String name) {
065        this.name = name;
066    }
067
068    public List<DiffFieldItemDescriptor> getIncludedItems() {
069        return includedItems;
070    }
071
072    public void setIncludedItems(List<DiffFieldItemDescriptor> includedItems) {
073        this.includedItems = includedItems;
074    }
075
076    public List<DiffFieldItemDescriptor> getExcludedItems() {
077        return excludedItems;
078    }
079
080    public void setExcludedItems(List<DiffFieldItemDescriptor> excludedItems) {
081        this.excludedItems = excludedItems;
082    }
083
084    public DiffComplexFieldDefinition getDiffComplexFieldDefinition() {
085        return new DiffComplexFieldDefinitionImpl(getSchema(), getName(),
086                getDiffFieldItemDefinitions(getIncludedItems()), getDiffFieldItemDefinitions(getExcludedItems()));
087    }
088
089    protected List<DiffFieldItemDefinition> getDiffFieldItemDefinitions(List<DiffFieldItemDescriptor> itemDescriptors) {
090        List<DiffFieldItemDefinition> diffFieldItemDefinitions = new ArrayList<DiffFieldItemDefinition>();
091        for (DiffFieldItemDescriptor itemDescriptor : itemDescriptors) {
092            diffFieldItemDefinitions.add(itemDescriptor.getDiffFieldItemDefinition());
093        }
094        return diffFieldItemDefinitions;
095    }
096
097}