001/**
002 *   GRANITE DATA SERVICES
003 *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004 *
005 *   This file is part of the Granite Data Services Platform.
006 *
007 *   Granite Data Services is free software; you can redistribute it and/or
008 *   modify it under the terms of the GNU Lesser General Public
009 *   License as published by the Free Software Foundation; either
010 *   version 2.1 of the License, or (at your option) any later version.
011 *
012 *   Granite Data Services is distributed in the hope that it will be useful,
013 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
015 *   General Public License for more details.
016 *
017 *   You should have received a copy of the GNU Lesser General Public
018 *   License along with this library; if not, write to the Free Software
019 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
020 *   USA, or see <http://www.gnu.org/licenses/>.
021 */
022package org.granite.config.flex;
023
024import org.granite.util.XMap;
025
026/**
027 * @author Franck WOLFF
028 */
029public class Channel {
030
031    private static final String LEGACY_XML = "serialization/legacy-xml";
032    private static final String LEGACY_COLLECTION = "serialization/legacy-collection";
033
034    private final String id;
035    private final String className;
036    private final EndPoint endPoint;
037    private final XMap properties;
038
039    private final boolean legacyXml;
040    private final boolean legacyCollection;
041
042    public Channel(String id, String className, EndPoint endPoint, XMap properties) {
043        this.id = id;
044        this.className = className;
045        this.endPoint = endPoint;
046        this.properties = properties;
047        this.legacyCollection = Boolean.TRUE.toString().equals(properties.get(LEGACY_COLLECTION));
048        this.legacyXml = Boolean.TRUE.toString().equals(properties.get(LEGACY_XML));
049    }
050
051    public String getId() {
052        return id;
053    }
054
055    public String getClassName() {
056        return className;
057    }
058
059    public EndPoint getEndPoint() {
060        return endPoint;
061    }
062
063    public XMap getProperties() {
064        return properties;
065    }
066
067    public boolean isLegacyXmlSerialization() {
068        return legacyXml;
069    }
070
071    public boolean isLegacyCollectionSerialization() {
072        return legacyCollection;
073    }
074
075    public static Channel forElement(XMap element) {
076        String id = element.get("@id");
077        String className = element.get("@class");
078
079        XMap endPointElt = element.getOne("endpoint");
080        if (endPointElt == null)
081            throw new RuntimeException("Excepting a 'endpoint' element in 'channel-definition': " + id);
082        EndPoint endPoint = EndPoint.forElement(endPointElt);
083
084        XMap properties = new XMap(element.getOne("properties"));
085
086        return new Channel(id, className, endPoint, properties);
087    }
088}