/******************************************************************************* * Copyright (c) 2011 IRIS/DMC. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * IRIS/DMC- initial API and implementation * * ACKNOWLEDGEMENT * This software was developed as part of a project supported by * Cooperative Agreement Number G10AC00533 from the United States * Geological Survey. Its contents are solely the responsibility of * the authors and the USGS is not responsible for the efficacy, * safety, or suitability of this software. ******************************************************************************/ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.joda.time.DateTime; public class Channel implements Node{ private Epoch epoch; private String code; private String location; private DateTime created; private DateTime terminated; private List epochs = new ArrayList(); public Channel(String code, String location){ this.code = code; this.location = location; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public DateTime getCreated() { return created; } public void setCreated(DateTime created) { this.created = created; } public DateTime getTerminated() { return terminated; } public void setTerminated(DateTime terminated) { this.terminated = terminated; } public List getEpochs() { return epochs; } public void setEpochs(List epochs) { this.epochs = epochs; } public Epoch getEpoch() { return epoch; } public void setEpoch(Epoch epoch) { this.epoch = epoch; } public void add(ChannelEpoch epoch){ epoch.setChannel(this); if(epoch == null){ return; } this.epochs.add(epoch); } @Override public String toString() { return "Channel [epoch=" + epoch + ", code=" + code + ", location=" + location + ", created=" + created + ", terminated=" + terminated + "]"; } public void writeXml(XMLWriter out, int level) throws IOException { Map attributes = new HashMap(); attributes.put("chan_code", code); attributes.put("loc_code", location); out.startElement(Schema.CHANNEL, attributes); out.startElement(Schema.CREATION_DATE); out.value(this.created.toString()); out.endElement(); for(ChannelEpoch epoch:epochs){ epoch.writeXml(out, level); } out.endElement(); out.flush(); } }