001/** 002 * 003 * Copyright © 2016 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.iot.data.element; 018 019import java.util.Collections; 020import java.util.List; 021 022import org.jivesoftware.smack.util.XmlStringBuilder; 023 024import org.jivesoftware.smackx.iot.element.NodeInfo; 025 026public class NodeElement extends IoTDataExtensionElement { 027 028 public static final String ELEMENT = "node"; 029 030 private final NodeInfo nodeInfo; 031 private final List<TimestampElement> timestampElements; 032 033 public NodeElement(NodeInfo nodeInfo, TimestampElement timestampElement) { 034 this(nodeInfo, Collections.singletonList(timestampElement)); 035 } 036 037 public NodeElement(NodeInfo nodeInfo, List<TimestampElement> timestampElements) { 038 this.nodeInfo = nodeInfo; 039 this.timestampElements = Collections.unmodifiableList(timestampElements); 040 } 041 042 public List<TimestampElement> getTimestampElements() { 043 return timestampElements; 044 } 045 046 @Override 047 public String getElementName() { 048 return ELEMENT; 049 } 050 051 @Override 052 public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 053 XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace); 054 nodeInfo.appendTo(xml); 055 xml.rightAngleBracket(); 056 057 xml.append(timestampElements); 058 059 xml.closeElement(this); 060 return xml; 061 } 062 063}