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