org.newsml.toolkit
Interface PrimaryNode

All Superinterfaces:
BaseNode, IdNode
All Known Subinterfaces:
ContentItem, NewsComponent, NewsItem, NewsItemRef, NewsML

public interface PrimaryNode
extends BaseNode, IdNode

Base interface for the main nodes in the NewsML content tree.

There are five basic nodes types in the NewsML content tree:

  1. NewsML,
  2. NewsItem,
  3. NewsComponent,
  4. NewsItemRef, and
  5. ContentItem.

The basic grammar of the NewsML content tree is as follows:

 NewsML:        NewsItem+
 NewsItem:      NewsComponent?
 NewsComponent: ((NewsItem|NewsItemRef)+ | NewsComponent+ | ContentItem+)
 NewsItemRef:   [reference to another NewsItem]
 ContentItem:   [actual data inline or by reference]
 

Version:
1.0
Author:
Reuters PLC

Field Summary
static int CONTENT_ITEM
          Constant: node is a content item.
static int NEWS_COMPONENT
          Constant: node is a news component.
static int NEWS_ITEM
          Constant: node is a news item.
static int NEWS_ITEM_REF
          Constant: node is a reference to a news item.
static int NEWSML
          Constant: node is the top-level NewsML package.
 
Method Summary
 ContentItem asContentItem()
          Cast this node to a ContentItem node.
 NewsComponent asNewsComponent()
          Cast this node to a NewsComponent node.
 NewsItem asNewsItem()
          Cast this node to a NewsItem node.
 NewsItemRef asNewsItemRef()
          Cast this node to a NewsItemRef node.
 NewsML asNewsML()
          Cast this node to a NewsML node.
 PrimaryNode[] getChild()
          Get an array of primary child nodes.
 PrimaryNode getChild(int index)
          Return a child of the node by position.
 int getChildCount()
          Return the number of children for this node.
 PrimaryNode[] getNodePath()
          Return the path of nodes from the root to this node.
 PrimaryNode getParent()
          Get the parent of the node in the NewsML content tree.
 int getType()
          Get the type of the node in the NewsML content tree.
 
Methods inherited from interface org.newsml.toolkit.BaseNode
getSession, getXMLName
 
Methods inherited from interface org.newsml.toolkit.IdNode
getDuid, getEuid
 

Field Detail

NEWSML

public static final int NEWSML
Constant: node is the top-level NewsML package.
See Also:
getType()

NEWS_ITEM

public static final int NEWS_ITEM
Constant: node is a news item.
See Also:
getType()

NEWS_COMPONENT

public static final int NEWS_COMPONENT
Constant: node is a news component.
See Also:
getType()

NEWS_ITEM_REF

public static final int NEWS_ITEM_REF
Constant: node is a reference to a news item.
See Also:
getType()

CONTENT_ITEM

public static final int CONTENT_ITEM
Constant: node is a content item.
See Also:
getType()
Method Detail

getType

public int getType()
Get the type of the node in the NewsML content tree.

Use this method to determine the type of a primary node so that you can invoke the appropriate casting method. Normally, an application will use this method in a switch statement similar to the following (assuming that the do* methods belong to the application):

 switch (node.getType()) {
 case PrimaryNode.NEWSML:
   doNewsML(node.asNewsML());
   break;
 case PrimaryNode.NEWS_ITEM:
   doNewsItem(node.asNewsItem());
   break;
 case PrimaryNode.NEWS_COMPONENT:
   doNewsComponent(node.asNewsComponent());
   break;
 case PrimaryNode.NEWS_ITEM_REF:
   doNewsItemRef(node.asNewsItemRef());
   break;
 case PrimaryNode.CONTENT_ITEM:
   doContentItem(node.asContentItem());
   break;
 default:
   throw new Error("Internal error: unexpected primary node type.");
 }
 

This method is redundant with BaseNode.getXMLName() in the BaseNode interface, since the XML name can unambiguously distinguish the node type.

Returns:
A constant indicating the node's type.
See Also:
NEWSML, NEWS_ITEM, NEWS_COMPONENT, NEWS_ITEM_REF, CONTENT_ITEM

getParent

public PrimaryNode getParent()
Get the parent of the node in the NewsML content tree.
Returns:
The parent node, or null if this is the root.
See Also:
getChild(int)

getChildCount

public int getChildCount()
Return the number of children for this node.
Returns:
The number of children.

getChild

public PrimaryNode getChild(int index)
Return a child of the node by position.
Parameters:
index - The index of the child, zero-based, numbered sequentially.
Returns:
The node representing the specified child, or null if none is available at the index provided.
See Also:
getParent()

getChild

public PrimaryNode[] getChild()
Get an array of primary child nodes.
Returns:
A (possibly-empty) array of primary child nodes.

asNewsML

public NewsML asNewsML()
Cast this node to a NewsML node.
Returns:
A NewsML node, or null if this node is of the wrong type.
See Also:
getType(), NEWSML

asNewsItem

public NewsItem asNewsItem()
Cast this node to a NewsItem node.
Returns:
A NewsItem node, or null if this node is of the wrong type.
See Also:
getType(), NEWS_ITEM

asNewsComponent

public NewsComponent asNewsComponent()
Cast this node to a NewsComponent node.
Returns:
A NewsComponent node, or null if this node is of the wrong type.
See Also:
getType(), NEWS_COMPONENT

asNewsItemRef

public NewsItemRef asNewsItemRef()
Cast this node to a NewsItemRef node.
Returns:
A NewsItemRef node, or null if this node is of the wrong type.
See Also:
getType(), NEWS_ITEM_REF

asContentItem

public ContentItem asContentItem()
Cast this node to a ContentItem node.
Returns:
A ContentItem node, or null if this node is of the wrong type.
See Also:
getType(), CONTENT_ITEM

getNodePath

public PrimaryNode[] getNodePath()
Return the path of nodes from the root to this node. The current node will be included as the last element of the array.
Returns:
An array of nodes from the root to the current node.