001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS (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 *     Florent Guillaume
016 *
017 * $Id: SubDirectoryDescriptor.java 24597 2007-09-05 16:04:04Z fguillaume $
018 */
019
020package org.nuxeo.ecm.directory.multi;
021
022import java.util.Arrays;
023
024import org.nuxeo.common.xmap.annotation.XNode;
025import org.nuxeo.common.xmap.annotation.XNodeList;
026import org.nuxeo.common.xmap.annotation.XObject;
027
028/**
029 * @author Florent Guillaume
030 */
031@XObject("subDirectory")
032public class SubDirectoryDescriptor {
033
034    @XNode("@name")
035    public String name;
036
037    @XNode("optional")
038    public boolean isOptional = false;
039
040    @XNodeList(value = "field", type = FieldDescriptor[].class, componentType = FieldDescriptor.class)
041    public FieldDescriptor[] fields;
042
043    @Override
044    public String toString() {
045        return String.format("{subdirectory name=%s fields=%s", name, Arrays.toString(fields));
046    }
047
048    /**
049     * @since 5.6
050     */
051    public SubDirectoryDescriptor clone() {
052        SubDirectoryDescriptor clone = new SubDirectoryDescriptor();
053        clone.name = name;
054        clone.isOptional = isOptional;
055        if (fields != null) {
056            clone.fields = new FieldDescriptor[fields.length];
057            for (int i = 0; i < fields.length; i++) {
058                clone.fields[i] = fields[i].clone();
059            }
060        }
061        return clone;
062    }
063}