2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: CheckPath.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.4 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 21:00:02 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.remote.protocol.parser; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.util.Iterator; |
2 |
26 Feb 07 |
jari |
15 |
import java.util.LinkedList; |
2 |
26 Feb 07 |
jari |
16 |
import java.util.ListIterator; |
2 |
26 Feb 07 |
jari |
17 |
|
2 |
26 Feb 07 |
jari |
18 |
import org.xml.sax.SAXException; |
2 |
26 Feb 07 |
jari |
19 |
|
2 |
26 Feb 07 |
jari |
20 |
class CheckPath { |
2 |
26 Feb 07 |
jari |
21 |
|
2 |
26 Feb 07 |
jari |
22 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>CheckPath</code> with soecified linked list. |
2 |
26 Feb 07 |
jari |
24 |
*/ |
2 |
26 Feb 07 |
jari |
25 |
public CheckPath(LinkedList stack) { |
2 |
26 Feb 07 |
jari |
26 |
m_stack = stack; |
2 |
26 Feb 07 |
jari |
27 |
} |
2 |
26 Feb 07 |
jari |
28 |
|
2 |
26 Feb 07 |
jari |
29 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes elements path from top of the linked list. |
2 |
26 Feb 07 |
jari |
* @throws SAXException if path is uncorrect. |
2 |
26 Feb 07 |
jari |
32 |
*/ |
2 |
26 Feb 07 |
jari |
33 |
public void checkFromTopThrow( String[] elements ) throws SAXException { |
2 |
26 Feb 07 |
jari |
34 |
if (!checkFromTop( elements )) |
2 |
26 Feb 07 |
jari |
35 |
throw new SAXException("Invalid document structure: " + m_stack.getLast() ); |
2 |
26 Feb 07 |
jari |
36 |
} |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes elements path from bottom of the linked list. |
2 |
26 Feb 07 |
jari |
* @throws SAXException if path is uncorrect. |
2 |
26 Feb 07 |
jari |
41 |
*/ |
2 |
26 Feb 07 |
jari |
42 |
public void checkFromBottomThrow( String[] elements ) throws SAXException { |
2 |
26 Feb 07 |
jari |
43 |
if (!checkFromBottom( elements )) |
2 |
26 Feb 07 |
jari |
44 |
throw new SAXException("Invalid document structure: " + m_stack.getLast()); |
2 |
26 Feb 07 |
jari |
45 |
} |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
47 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes elements path from top of the linked list. |
2 |
26 Feb 07 |
jari |
* @return true if specified path is correct. |
2 |
26 Feb 07 |
jari |
50 |
*/ |
2 |
26 Feb 07 |
jari |
51 |
public boolean checkFromTop( String[] elements ) { |
2 |
26 Feb 07 |
jari |
52 |
Iterator iter = m_stack.iterator(); |
2 |
26 Feb 07 |
jari |
53 |
int i = 0; |
2 |
26 Feb 07 |
jari |
54 |
int size = elements.length; |
2 |
26 Feb 07 |
jari |
55 |
while (i < size && iter.hasNext()) { |
2 |
26 Feb 07 |
jari |
56 |
String el = (String)iter.next(); |
2 |
26 Feb 07 |
jari |
57 |
if (!el.equals(elements[i])) return false; |
2 |
26 Feb 07 |
jari |
58 |
i++; |
2 |
26 Feb 07 |
jari |
59 |
} |
2 |
26 Feb 07 |
jari |
60 |
if (!iter.hasNext() && i < size) |
2 |
26 Feb 07 |
jari |
61 |
return false; |
2 |
26 Feb 07 |
jari |
62 |
else |
2 |
26 Feb 07 |
jari |
63 |
return true; |
2 |
26 Feb 07 |
jari |
64 |
} |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes elements path from bottom of the linked list. |
2 |
26 Feb 07 |
jari |
* @return true if specified path is correct. |
2 |
26 Feb 07 |
jari |
69 |
*/ |
2 |
26 Feb 07 |
jari |
70 |
public boolean checkFromBottom( String[] elements ) { |
2 |
26 Feb 07 |
jari |
71 |
ListIterator iter = m_stack.listIterator( m_stack.size() ); |
2 |
26 Feb 07 |
jari |
72 |
int size = elements.length; |
2 |
26 Feb 07 |
jari |
73 |
int i = 0; |
2 |
26 Feb 07 |
jari |
74 |
if (elements.length == 0) return false; |
2 |
26 Feb 07 |
jari |
75 |
|
2 |
26 Feb 07 |
jari |
76 |
while (i < size && iter.hasPrevious()) { |
2 |
26 Feb 07 |
jari |
77 |
String el = (String)iter.previous(); |
2 |
26 Feb 07 |
jari |
78 |
if (!el.equals(elements[i])) return false; |
2 |
26 Feb 07 |
jari |
79 |
i++; |
2 |
26 Feb 07 |
jari |
80 |
} |
2 |
26 Feb 07 |
jari |
81 |
if (!iter.hasPrevious() && i < size) |
2 |
26 Feb 07 |
jari |
82 |
return false; |
2 |
26 Feb 07 |
jari |
83 |
else |
2 |
26 Feb 07 |
jari |
84 |
return true; |
2 |
26 Feb 07 |
jari |
85 |
} |
2 |
26 Feb 07 |
jari |
86 |
|
2 |
26 Feb 07 |
jari |
87 |
private LinkedList m_stack; |
2 |
26 Feb 07 |
jari |
88 |
} |
2 |
26 Feb 07 |
jari |
89 |
|