Java Doc for Parser.java in  » Science » Cougaar12_4 » org » cougaar » core » adaptivity » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.core.adaptivity 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.cougaar.core.adaptivity.Parser

Parser
public class Parser (Code)
Parser for plays to be stored in a Playbook. The grammar is straightforward with the exception of ranges and range lists.

Basic Syntax

Each play consists of an if clause (predicate) and one or more constraint phrases. These are all separated by colons and terminated with a semi-colon. For example:

<if clause>:<constraint>:...<constraint>;

The <if clause> is an expression involving Condition s and constants that must evaluate to true or false. A constraint consists of an OperatingMode following by a ConstraintOperator and a range list and signifies that the OperatingMode will be constrained so as to satisfy the relation specified by the operator to the range list. For example:

 FooPlugin.MODE < 5;
 FooPlugin.MODE in {1 to 7};
 FooPlugin.SPEED = "FAST";

Note that both relational and range operators (==, not it, etc.) as well as assignment may be used. Assignment explicitly specifies the allowed values. Relational and range operators implicitly specify the allowed values by specifying the test that any such value must satisfy. The operators =, ==, and in are all equivalent as are != and not in. The other relational operators are usually used with single valued range lists (constants).

Comments

Comments are ignored by the parser. Both slash-slash and slash-star comments are recognized. The former beging with two adjacent slashes and terminate at the end of line. The latter terminate with a star-slash sequence.

Numeric Constants

Numeric constants are interpreted as floating point numbers (doubles). When necessary, numbers will be automatically cast to integers or longs. A consequence of this is that plays may not use the full precision offered by longs (64 bits) and are restricted to the 56 bits of precision in a double.

Ranges

A range is written as two numbers separated by the keyword "to" or "thru". The former excludes the end point and the latter includes the end point. A point range (a range having exactly one value) may be written as a single number; 7 is equivalent to 7 thru 7. 7 to 7, on the other hand, is an empty range; it allows no values.

Range Lists

A range list is a sequence of ranges enclosed in braces. The elements of a range list may be separated by commas, but they are not required; white space is sufficient. A range list consisting of exactly one range my omit the braces. Consequently, a numeric constant is also a range list. Range lists frequently have elements that are point ranges and express list of descrete values rather than a continuum. Range lists may appear only as the right-hand operand of relational operators (see below). Numeric constants may appear in arithmetic expressions. to the written value. In general the context makes it clear which should be used, but for example:

 Foo < {11 to 20, 25 thru 30, 1 to 3};

is true if Foo is less than 1 (the minimum of the ranges). This characteristic is an artifact of the parser and probably insignificant to the playbook writer.

As implied above, a range list consists of one or more ranges enclosed in braces. The comma between the ranges is optional (white space is sufficient). The braces are also optional if the list has a single range. Each range consists of either one number or string or two numbers or strings separated by either "to" or "thru". "To" signifies a range that does not include the end point whereas "thru" signifies a range that does include the end point. If the number is floating point, only the exact value given by the end point is excluded. The next smaller value that can be represented is always included. This characteristic can be used to insure there are no gaps in the coverage of a series of predicates. For example:

 x in {1 to 3, 5 to 10}:...;
 x in {3 to 5}:...;
 x >= 10:...;

insures that exactly one of the predicates is true for any value of x from 1 to infinity. There is no value of x that can fall into a crack in the vicinity of 3 or 5 or 10 nor is there any value of x in those same regions that can cause two predicates to fire.

Numbers are parsed as doubles and coerced to other numeric typs as needed. This means that long values cannot be written with their entire range. (Doubles can exactly represent only 56 bits of precision.)

Strings

Strings are used as constants (range limits), Condition names and OperatingMode names. The interpretation depends on context (see below). Strings do not need to be quoted unless they contain characters (such as spaces) that have syntactic meaning to the parser. In particular, strings need not be quoted when they contain . (period) and [] (brackets). All other punctuation and special characters should be quoted.

String constants can be used in range lists and arithmetic expressions using the + operator. Strings cannot be used in other arithmetic expressions. String comparisons are usually confined to equality and inequality tests, but the other operators have a defined meaning (alphabetic comparison using the default collation sequence). String ranges are rare, but if used, have a slightly different meaning when "to" ranges are specified because the highest value included in a "to" range would be infinitely long. For example, the last string in the range "bar" to "foo" would be "fon\uffff\uffff\uffff\uffff...". It is hard to conceive of a use for a "to" range involving strings, so the infinite string is truncated after the first "\uffff".

Strings that name Conditions can be used in arithmetic expressions if the named Condition has a numeric value. If the named Condition has a String value, then only the + operator is allowed.

If Clause Operators

Arithmetic Operators (+, -, *, /)

These have their standard meanings. The parser treats these with standard precedence so parentheses are needed in the usual places. When in doubt, parenthesize. There is no modulus operator (%).

Relational Operators (< <= == != >= >)

Relational operators compare two quantities and yield a boolean (true or false) result. Relational operators are not commutative; the interpretation of the left hand operand is different from the right hand operand. Strings in the left hand operand always name Conditions in if clauses or OperatingModes in constraints. Strings in the right hand operand are always values (or range limits). So, for example, in the play:

 FOO == HIGH: HIGH = FOO;

The first FOO is the name of a Condition, the second FOO is a value to be stored in the OperatingMode named HIGH when the Condition named FOO has a value equal to HIGH. For clarity, it is a good practice to quote strings used as values and not quote strings that denote Conditions and Operating Modes.

Comparison of strings uses the default collation sequence for characters.

Range Operators (in and not in)

Range operators test for inclusion in (or exclusion from) a range list. The meaning is straightforward:

 x in {1 thru 7, 10}

is true iff x has a value between 1 and 7 inclusive or has the value 10. A range list is just a shorthand for a combination of less than and greater than terms, but is easier to write and process.

Boolean Constants

The boolean constants true and false may be used in an if clause. This is useful when developing a playbook before the details are worked out or to deactivate certain plays.

Constraints

Constraints specify an allowed list of ranges to which an OperatingMode can be set. The constraints from all the plays (including those manufactured from policies) are combined (intersected) to form the final constraint. Often this final constraint is a single value, but when it has multiple values, the minimum of the first range in the list is used. The constraint can be viewed either as an expression that must be true or as an assignment of a range list to the OperatingMode. For example:

 Opmode1 = 3
 Opmode1 in {3 thru 3}
 Opmode1 == 3

are all equivalent. The first assigns the single valued range {3 thru 3} to Opmode1. The second requires that Opmode1 have the value 3 so that is in the range 3 thru 3. The third requires that Opmode1 be exactly equal to 3.

All forms of constraints are rewritten as an assignment of a range list to the OperatingMode. For example:

 Opmode < 3

is rewritten as:

 Opmode = {<negative infinity> to 3}

The process of intersecting the constraints from several plays may not be clear. For example, if the if clauses of two places yielded these two constraints:

 opmode in {56, 128, 256, 1024}
 opmode >= 128

The combined constraint would be:

 opmode in {128, 256, 1024}

Another example:

 opmode in 1 thru 10
 opmode in 5 to 20

The combined result would be: opmode in 5 thru 10

For a value to be included in the combined range list, it must be included by the range lists of all the selected plays. It is a playbook-writing error to allow plays to be simultaneously active for which the combined range list is empty. For example:

 opmode in {56, 128, 256}
 opmode < 56

would be an error. Such errors are not detected until they occur. When they do occur, they are logged and the later constraint is ignored.

OperatingModeConditions

OperatingModeConditions are intermediate variables the act as OperatingModes in some plays and Conditions in later plays. This allows certain plays such as those that result from policies received from other agents to set the value of an agent-wide OperatingMode that is then translated into component-specific OperatingModes by using the agent-wide mode as a Condition in other plays. For example, assume the following plays resulting from inter-agent operating mode policies:

 Threatcon > 3: DefensePosture = 2;
 Threatcon <= 3: DefensePosture = 1;

and the following plays from the local playbook:

 DefensePosture < 2: FooPlugin.keyLength = 56: AdaptivePlugin.fidelity = high;
 DefensePosture >= 2: FooPlugin.keylength = 128: AdaptivePlugin.fidelity = medium;

The allows the outside agent to be unaware of the details of the makeup of the agent by expressing its policy in terms of a "DefensePosture" concept. However, the local playbook is developed with an awareness of the agent makeup so it can contain plays to set the operating modes of its plugins based on this DefensePosture value.

OperatingModePolicy

An OperatingModePolicy has the same syntax as a Play except that it is prefixed with a name.



Field Summary
 ConstrainingClausecc
    
 booleanpushedBack
    
 StreamTokenizerst
    

Constructor Summary
public  Parser(Reader s, LoggingService logger)
     Construct from a Reader.

Method Summary
public  ConstrainingClauseparseConstrainingClause()
     Parses and returns the next ConstrainingClause.
public  ConstraintPhrase[]parseConstraints()
     Parse a series of constraints from the Reader up through a semicolon.
public  OperatingModePolicy[]parseOperatingModePolicies()
     Parses an entire file of OperatingModePolicies and returns them as an array.
public  OperatingModePolicyparseOperatingModePolicy()
     Parses an OperatingModePolicy.
public  PlayparsePlay()
     Parses a single, complete Play from the input.
public  Play[]parsePlays()
     Parses an entire file of Plays and returns them as an array.

Field Detail
cc
ConstrainingClause cc(Code)



pushedBack
boolean pushedBack(Code)



st
StreamTokenizer st(Code)




Constructor Detail
Parser
public Parser(Reader s, LoggingService logger)(Code)
Construct from a Reader.
Parameters:
  s - the Reader to read from
Parameters:
  logger - a LoggingService onto which error and debuginformation will be written.




Method Detail
parseConstrainingClause
public ConstrainingClause parseConstrainingClause() throws IOException(Code)
Parses and returns the next ConstrainingClause. The terminator (colon) is not consumed. the parsed constraining clause.
throws:
  IOException - if an error occurs reading from the input.



parseConstraints
public ConstraintPhrase[] parseConstraints() throws IOException(Code)
Parse a series of constraints from the Reader up through a semicolon. The terminating semicolon is consumed. an array of ConstraintPhrases parsed from the input.
throws:
  IOException - if an error occurs reading from the input.



parseOperatingModePolicies
public OperatingModePolicy[] parseOperatingModePolicies() throws IOException(Code)
Parses an entire file of OperatingModePolicies and returns them as an array. an array of OperatingModePolicies from the file.
throws:
  IOException - if an error occurs reading from the input.



parseOperatingModePolicy
public OperatingModePolicy parseOperatingModePolicy() throws IOException(Code)
Parses an OperatingModePolicy. Syntactically, an OperatingModePolicy is identical with a play except it is prefixed with a name token. The name token must be a string (quoted as necessary). an OperatingModePolicy
throws:
  IOException - if an error occurs reading from the input.



parsePlay
public Play parsePlay() throws IOException(Code)
Parses a single, complete Play from the input. The terminating semicolon is consumed. the parsed Play.
throws:
  IOException - if an error occurs reading from the input.



parsePlays
public Play[] parsePlays() throws IOException(Code)
Parses an entire file of Plays and returns them as an array. an array of plays from the file.
throws:
  IOException - if an error occurs reading from the input.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.