001/** 002 * 003 * Copyright the original author or authors 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.pubsub; 018 019import org.jivesoftware.smack.packet.ExtensionElement; 020 021/** 022 * A class which represents a common element within the pubsub defined 023 * schemas. One which has a <b>node</b> as an attribute. This class is 024 * used on its own as well as a base class for many others, since the 025 * node is a central concept to most pubsub functionality. 026 * 027 * @author Robin Collier 028 */ 029public class NodeExtension implements ExtensionElement 030{ 031 private final PubSubElementType element; 032 private final String node; 033 034 /** 035 * Constructs a <tt>NodeExtension</tt> with an element name specified 036 * by {@link PubSubElementType} and the specified node id. 037 * 038 * @param elem Defines the element name and namespace 039 * @param nodeId Specifies the id of the node 040 */ 041 public NodeExtension(PubSubElementType elem, String nodeId) 042 { 043 element = elem; 044 this.node = nodeId; 045 } 046 047 /** 048 * Constructs a <tt>NodeExtension</tt> with an element name specified 049 * by {@link PubSubElementType}. 050 * 051 * @param elem Defines the element name and namespace 052 */ 053 public NodeExtension(PubSubElementType elem) 054 { 055 this(elem, null); 056 } 057 058 /** 059 * Gets the node id 060 * 061 * @return The node id 062 */ 063 public String getNode() 064 { 065 return node; 066 } 067 068 public String getElementName() 069 { 070 return element.getElementName(); 071 } 072 073 public String getNamespace() 074 { 075 return element.getNamespace().getXmlns(); 076 } 077 078 public CharSequence toXML() 079 { 080 return '<' + getElementName() + (node == null ? "" : " node='" + node + '\'') + "/>"; 081 } 082 083 @Override 084 public String toString() 085 { 086 return getClass().getName() + " - content [" + toXML() + "]"; 087 } 088}