Class ExampleLabel

java.lang.Object
  |
  +--ExampleLabel

class ExampleLabel
extends java.lang.Object

Shows examples of using the PDSLabel package.


Constructor Summary
(package private) ExampleLabel()
           
 
Method Summary
static void Basic(java.lang.String[] args)
          Parse a label and print it to the screen.
static void Delete(java.lang.String[] args)
          Parse a label, remove an object and print the results to the screen.
static void Extract(java.lang.String[] args)
          Parse a label, find an object, extract the object into a new label and print it to the screen.
static void LoadWrite(java.lang.String[] args)
          Parse a label and write it to another file.
static void main(java.lang.String[] args)
           
static void Object(java.lang.String[] args)
          Parse a label, locate an object and print the object to the screen.
static void PadFile(java.lang.String[] args)
          Pad a file so that every line in the file has the same number of characters.
static void Pointer(java.lang.String[] args)
          Parse a label and print all elements that are pointers to the screen.
static void PointerInObject(java.lang.String[] args)
          Parse a label, find an object, find pointers with the object and print each pointer to the screen.
static void PointerList(java.lang.String[] args)
          Parse a label, find all the pointers to files and print the list of files to the screen.
static void PointerValue(java.lang.String[] args)
          Parse a label, find a pointer, print the pointer and the element that follows the pointer.
static void Structure(java.lang.String[] args)
          Parse a label, find a pointer element, parse the file it references and print it to the screen.
static void StructureReplace(java.lang.String[] args)
          Parse a label and replace a pointer with the contents of the file it references, then print the label to the screen.
static void Value(java.lang.String[] args)
          Parse a label, find an element, then extract and print the value of the element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExampleLabel

ExampleLabel()
Method Detail

main

public static void main(java.lang.String[] args)

Basic

public static void Basic(java.lang.String[] args)
Parse a label and print it to the screen.
Source code:
PDSLabel label = new PDSLabel(); label.parse(file); // Parse label file label.print(); // Print label
To Run:
java example basic {label}
where {label} is the name of the label file to parse.

Since:
1.0

Object

public static void Object(java.lang.String[] args)
Parse a label, locate an object and print the object to the screen. This example looks for an object with the given name and then prints the elements in the object to the screen.
Source code:

 PDSLabel	label	= new PDSLabel();
 PDSItem		object;
 
 label.parse(file);				// Parse label file
 object = label.findObject(name);	// Find object 
 label.print(System.out, 4, 20, object);			// Print object
 
To Run:
java Example Object {label} {name}
where {label} is the name of the label file to parse. and {name} is the name of the object to find.

Since:
1.0

Pointer

public static void Pointer(java.lang.String[] args)
Parse a label and print all elements that are pointers to the screen. This example parses a label and searches for all elements which are pointers and prints each one to the screen. This demonstrates using regular expressions in a find in order to locate elements which have a particular syntax.
Source code:

 PDSLabel	label	= new PDSLabel();
 PDSItem		item	= new PDSItem();
 
 label.parse(file);					// Parse label file
 item.empty();							// Clear item
 while(true) {
         item = label.findNextElement("^*", item);	// Find next pointer
         if(!item.valid()) break;				// If none - exit loop
         label.print(System.out, 4, 20, item);				// Print item
 }
 
To Run:
java Example Pointer {label}
where {label} is the name of the label file to parse.

Since:
1.0

PointerInObject

public static void PointerInObject(java.lang.String[] args)
Parse a label, find an object, find pointers with the object and print each pointer to the screen. This example parses a label and searches for the TABLE object. Then the elements of the table object are scanned for pointers. The defnition for each pointer is printed on the screen.
Source code:

 PDSLabel	label	= new PDSLabel();
 PDSItem		item	= new PDSItem();
 
 label.parse(file);					// Parse label file
 object = label.findObject("TABLE");	// Find TABLE object
 item = label.findElement("^*", object);	// Find first pointer in TABLE object
 label.print(System.out, 4, 20, item);				// Print element
 
To Run:
java Example PointerInObject {label}
where {label} is the name of the label file to parse.

Since:
1.0

PointerValue

public static void PointerValue(java.lang.String[] args)
Parse a label, find a pointer, print the pointer and the element that follows the pointer. This example parses a label and searches for an element that is a pointers (begins with "^"). The element is printed and the element following it is also printed. This example demonstrates how to use regular expressions in a find operation and how to walk through a label.
Source code:

 PDSLabel	label	= new PDSLabel();
 PDSItem		item	= new PDSItem();
 
 label.parse(file);				// Parse label file
 item.empty();						// Clear item
 item = label.findNextElement("^*", item);	// Find first pointer
 System.out.print("next element after: "); 
 label.print(System.out, 4, 20, item);				// Print item found
 item = label.nextElement(item);			// Step to next item
 label.print(System.out, 4, 20, item);				// Print item found
 
To Run:
java Example05 {label}
where {label} is the name of the label file to parse.

Since:
1.0

Structure

public static void Structure(java.lang.String[] args)
Parse a label, find a pointer element, parse the file it references and print it to the screen. This example parses a label file and searches for a "^STRUCTURE" element. The value of the element is considered a file name and that file is parsed. The results are printed to the screen.
Source code:

 PDSLabel	label = new PDSLabel();
 PDSLabel	partial = new PDSLabel();
 PDSItem		item;
 PDSElement	element;
 PDSValue	value;
 
 label.parse(file);								// Parse label file
 item = label.findElement("^STRUCTURE");			// Find pointer to STRUCTURE
 if(item.valid()) {								// If found
         element = label.getElement(item);			// Get element associated with item
         value = (PDSValue) element.mValue.get(0);	// Get value
         partial.parse(label.path() + value.mValue);	// Parse file
         partial.print();							// Print out label ^STRUCTURE points to
 } else {
         System.out.println("Element not found!");
 }
 
To Run:
java Example Structure {label}
where {label} is the name of the label file to parse.

Since:
1.0

StructureReplace

public static void StructureReplace(java.lang.String[] args)
Parse a label and replace a pointer with the contents of the file it references, then print the label to the screen. This example parses a label and searches for the "^STRUCTURE" element. The value of the element is considered the name of the file. The file is parsed and inserted into the original label in place of the "^STRUCTURE" element. The resulting label is printed to the screen.
Source code:

 PDSLabel	label = new PDSLabel();
 PDSLabel	partial = new PDSLabel();
 PDSItem		item;
 PDSElement	element;
 PDSValue	value;
 
 label.parse(file);								// Parse label file
 item = label.findElement("^STRUCTURE");			// Find pointer to STRUCTURE
 if(item.valid()) {								// If found
         element = label.getElement(item);			// Get element associated with item
         value = (PDSValue) element.mValue.get(0);	// Get value
         partial.parse(label.path() + value.mValue);	// Parse file
         partial.print(System.out, 4, 20);						// Print out label ^STRUCTURE points to
 } else {
         System.out.println("Element not found!");
 }
 
 if(item.valid()) {
         label.replace(item, partial);		// Replace ^STRUCTURE item with parsed file content
         label.print(System.out, 4, 20);					// Print the whole label
 }
 
To Run:
java Example StructureReplace {label}
where {label} is the name of the label file to parse.

Since:
1.0

Value

public static void Value(java.lang.String[] args)
Parse a label, find an element, then extract and print the value of the element. This example show the two methods that can be used to find an element in a label and print the value of the element. Both methods search for the element with the given keyword. The first method is find the element, then obtain the instance of value object associated with it and print each item in the value object. The second method is to indirectly access the each item in the value associated with an element through the element level functions.
Source code:

 PDSLabel	label	= new PDSLabel();
 PDSLabel	partial	= new PDSLabel();
 PDSItem		item	= new PDSItem();
 PDSElement	element;
 PDSValue	value;
 
 System.out.println("== Extract an element - value item method ===========");
 label.parse(file);										// Parse label file
 item.empty();												// Clear item
 item = label.findNextElement(name, item);		// Find item
 if(item.valid()) {											// If found
         element = label.getElement(item);						// Get element associated with item
         if(element != null) {
                 int		n;
                 System.out.println("Keyword: " + element.mKeyword);	// Print keyword
                 n = element.mValue.size();							// Determine number of values
                 System.out.println("N Value: " + n);				// Print count
                 for(int i = 0; i < n; i++) {			
                         value = (PDSValue) element.mValue.get(i);		// Get value item
                         System.out.print("Value: " + value.mValue);		// Get value of item
                         System.out.println("\tUnits: " + value.mUnits);	// Get units of item
                 }
         }
         label.print(System.out, 4, 20, item);								// Print formated element
 } else {	// not found
         System.out.println("Unable to find item: " + name);
 }
 
 System.out.println("== Extract an element - indirect method ===========");
 item.empty();												// Clear item
 item = label.findNextElement(name, item);		// Find item
 if(item.valid()) {											// If found
         element = label.getElement(item);						// Get element associated with item
         if(element != null) {
                 int		n;
                 System.out.println("Keyword: " + element.mKeyword);	// Print keyword
                 n = element.valueSize();							// Determine number of values
                 System.out.println("N Value: " + n);				// Print count
                 for(int i = 0; i < n; i++) {
                         System.out.print("Value: " + element.value(i));	// Get value for item
                         System.out.println("\tUnits: " + element.units(i));	// Get units for item
                 }
         }
         label.print(System.out, 4, 20, item);								// Print formatted element
 } else {	// not found
         System.out.println("Unable to find item: " + name);
 }
 
To Run:
java Example Value {label} {name}
where {label} is the name of the label file to parse. and {name} is the keyword of the elmenent to find.

Since:
1.0

Delete

public static void Delete(java.lang.String[] args)
Parse a label, remove an object and print the results to the screen. This example parses a label, locates the object with the given name and, if found, deletes the object from the label. The resulting label is printed to the screen.
Source code:

 PDSLabel	label = new PDSLabel();
 PDSItem		object;
 
 label.parse(file);				// Parse label file
 object = label.findObject(name);	// Find object
 if(object.valid()) label.remove(object);
 label.print();
 
To Run:
java Example Delete {label} {name}
where {label} is the name of the label file to parse. and {name} is the name of the object to delete.

Since:
1.0

Extract

public static void Extract(java.lang.String[] args)
Parse a label, find an object, extract the object into a new label and print it to the screen. This example parses a label and looks for an object with the given name. If the object is found, then a copy is made and the copy is printed to the screen. This demonstrates how pieces of a label may be extract and used.
Source code:

 PDSLabel	label = new PDSLabel();
 PDSLabel	partial;
 PDSItem		object;
 
 label.parse(file);					// Parse label file
 object = label.findObject(name);		// Find object
 if(object.valid()) {
         partial = label.extract(object);	// Extract object into new label
         partial.print();					// Print new label
 }
 
To Run:
java Example Extract {label} {name}
where {label} is the name of the label file to parse. and {name} is the name of the object to extract.

Since:
1.0

PointerList

public static void PointerList(java.lang.String[] args)
Parse a label, find all the pointers to files and print the list of files to the screen. This example parses a file, then finds all the pointers to files using a utility function. The returned list of files is printed to the screen.
Source code:

 PDSLabel	label = new PDSLabel();
 ArrayList	list;
 
 label.parse(file);					// Parse label file
 list = label.filePointers();
 for(int i = 0; i < list.size(); i++) {
         System.out.println("File: " + (String) list.get(i));
 }
 
To Run:
java Example PointerList {label}
where {label} is the name of the label file to parse.

Since:
1.0

LoadWrite

public static void LoadWrite(java.lang.String[] args)
Parse a label and write it to another file. This example opens a label file, parses it, then writes the label to another file. This is useful when loading a template label, then writing the label to another file or location.
Source code:

 PDSLabel	label = new PDSLabel();
 
 System.out.println("== Load label and write to a file ============");
 label.parse(file);					// Parse label file
 label.print(output);
 
To Run:
java Example LoadWrite {label} {output}
where {label} is the name of the label file to parse and {output} is the name of the file to write the label.

Since:
1.0

PadFile

public static void PadFile(java.lang.String[] args)
Pad a file so that every line in the file has the same number of characters. The passed file is modified.
Source code:

 PDSUtil	util = new PDSUtil();
 
 System.out.println("== Pad file ============");
 util.padFile(file);					// Pad file
 
To Run:
java Example PadFile {label} {width}
where {label} is the name of the label file to parse and {output} is the name of the file to write the label.

Since:
1.0