Clover coverage report - Code Coverage for hivemind release 1.0-beta-1
Coverage timestamp: Sat Jul 3 2004 09:41:37 EDT
file stats: LOC: 481   Methods: 12
NCLOC: 381   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
SimpleDataLanguageParser.java 92.9% 84.9% 91.7% 87.3%
coverage coverage
 1   
 /* Generated By: SimpleDataLanguageParser.jj,v 1.3 2004/06/25 20&JavaCC: Do not edit this line. SimpleDataLanguageParser.java */
 2   
 //  Copyright 2004 The Apache Software Foundation
 3   
 //
 4   
 // Licensed under the Apache License, Version 2.0 (the "License");
 5   
 // you may not use this file except in compliance with the License.
 6   
 // You may obtain a copy of the License at
 7   
 //
 8   
 //     http://www.apache.org/licenses/LICENSE-2.0
 9   
 //
 10   
 // Unless required by applicable law or agreed to in writing, software
 11   
 // distributed under the License is distributed on an "AS IS" BASIS,
 12   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13   
 // See the License for the specific language governing permissions and
 14   
 // limitations under the License.
 15   
 
 16   
 ///CLOVER:OFF
 17   
 package org.apache.hivemind.sdl.parser;
 18   
 
 19   
 import org.xml.sax.*;
 20   
 import org.xml.sax.helpers.*;
 21   
 
 22   
 public class SimpleDataLanguageParser implements SimpleDataLanguageParserConstants {
 23   
         private ContentHandler _handler;
 24   
         private SDLLocator _locator = new SDLLocator();
 25   
         private boolean _firstElement = true;
 26   
 
 27   
 ///CLOVER:ON        
 28  0
         private void handleException(SAXException ex)
 29   
         throws ParseException
 30   
         {
 31  0
                 throw new SystemParseException(ex);
 32   
         }
 33   
 
 34   
         /**
 35   
      * Returns the locator used by this parser instance; which is needed to generate
 36   
      * SAXParseExceptions in SDLResourceParser.
 37   
      */
 38   
 
 39  110
         public Locator getLocator()
 40   
         {
 41  110
                 return _locator;
 42   
         }
 43   
 
 44  40872
         private void updateLocator()
 45   
         {
 46  40872
           _locator.update(token.beginLine, token.beginColumn);
 47   
         }
 48   
 
 49  109
     private void fireStartDocument() throws ParseException
 50   
     {
 51  109
         try { _handler.startDocument(); }
 52  0
                 catch (SAXException ex) { handleException(ex); }
 53   
         }
 54   
 
 55  108
     private void fireEndDocument() throws ParseException
 56   
     {
 57  108
                 try { _handler.endDocument(); }
 58  0
                 catch (SAXException ex) { handleException(ex); }
 59   
         }
 60   
 
 61  20436
         private void fireStartElement(String elementName, Attributes attributes) throws ParseException
 62   
         {
 63   
                 // No namespace, no qualified name
 64   
 
 65  20436
                 try { _handler.startElement("", elementName, null, attributes); }
 66  0
                 catch (SAXException ex) { handleException(ex); }
 67   
         }
 68   
 
 69  20435
         private void fireEndElement(String elementName) throws ParseException
 70   
         {
 71   
                 // No namespace, no qualified name
 72   
 
 73  20435
                 try { _handler.endElement("", elementName, elementName); }
 74  0
                 catch (SAXException ex) { handleException(ex); }
 75   
         }
 76   
 
 77  7974
     private void fireCharacters(String string) throws ParseException
 78   
     {
 79  7974
       try { _handler.characters(string.toCharArray(), 0, string.length()); }
 80  0
       catch (SAXException ex) { handleException(ex); }
 81   
     }
 82   
 
 83  85
     private void fireCharactersForExtendedLiteral(String string) throws ParseException
 84   
     {
 85  85
       try
 86   
       {
 87  85
         _handler.characters(string.toCharArray(), 2, string.length() - 4);
 88   
       }
 89  0
       catch (SAXException ex) { handleException(ex); }
 90   
     }
 91   
 
 92  28449
         private void addAttribute(AttributesImpl attributes, String name, String value)
 93   
         {
 94  28449
                 attributes.addAttribute("", name, name, "CDATA", value);
 95   
         }
 96   
 
 97  8160
         private String unquote(String input)
 98   
         {
 99  8160
                 StringBuffer buffer = new StringBuffer(input.length());
 100   
 
 101  8160
                 char[] chars = input.toCharArray();
 102   
 
 103  8160
                 int state = 0;
 104   
 
 105  8160
                 for (int i = 1; i < chars.length - 1; i++)
 106   
                 {
 107  496255
                   char ch = chars[i];
 108   
 
 109  496255
                   switch (state)
 110   
                   {
 111   
                     case 0:
 112   
 
 113  496249
                         if (ch == '\\')
 114   
                         {
 115  6
                           state = 1;
 116  6
                           continue;
 117   
                         }
 118   
 
 119  496243
                         buffer.append(ch);
 120  496243
                         continue;
 121   
 
 122   
                         case 1:
 123   
 
 124  6
                                 state = 0;
 125   
 
 126  2
                                 if (ch == '\\' || ch == '"') { buffer.append(ch); continue; }
 127   
 
 128  1
                                 if (ch == 'n') { buffer.append('\n'); continue; }
 129   
 
 130  1
                                 if (ch == 't') { buffer.append('\t'); continue; }
 131   
 
 132  1
                                 if (ch == 'r') { buffer.append('\r'); continue; }
 133   
 
 134  1
                                 buffer.append('\\');
 135  1
                                 buffer.append(ch);
 136   
 
 137   
                         default:
 138   
                   }
 139   
                 }
 140   
 
 141   
                 // state == 1 means a slash just before the end of the string.
 142   
                 // Is this the right thing to do?
 143   
 
 144  0
                 if (state == 1) buffer.append('\\');
 145   
 
 146  8160
                 return buffer.toString();
 147   
         }
 148   
 
 149   
         // Removes the "<<" and ">>" from an extended literal string.
 150   
 
 151  3
         private String defang(String input)
 152   
         {
 153  3
                 int length = input.length();
 154   
 
 155  3
                 return input.substring(2, length - 2);
 156   
 
 157   
 // The remainder of this class is generated by JavaCC.
 158   
 ///CLOVER:OFF        
 159   
         }
 160   
 
 161   
 /**
 162   
  * Parses an SDL document from a stream provided in the constructor. An instance
 163   
  * of SimpleDataLanguageParser should be used once and then discarded ... it will
 164   
  * be left in an unknown state after parsing a stream (especially if an error
 165   
  * occurs).
 166   
  *
 167   
  */
 168   
   final public void parse(ContentHandler handler) throws ParseException {
 169   
   _handler = handler;
 170   
                 // setDocumentLocator() is invoked once, before any other method
 171   
                 // is invoked.
 172   
 
 173   
                 _handler.setDocumentLocator(_locator);
 174   
     element();
 175   
                     fireEndDocument();
 176   
     jj_consume_token(0);
 177   
   }
 178   
 
 179   
   final public void element() throws ParseException {
 180   
   String elementName;
 181   
   AttributesImpl attributes = new AttributesImpl();
 182   
     jj_consume_token(SIMPLE_ID);
 183   
                 updateLocator();
 184   
                 elementName = token.image;
 185   
 
 186   
                 if (_firstElement)
 187   
                 {
 188   
                         fireStartDocument();
 189   
                         _firstElement = false;
 190   
                 }
 191   
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 192   
     case OPAREN:
 193   
       element_attributes(attributes);
 194   
       break;
 195   
     default:
 196   
       jj_la1[0] = jj_gen;
 197   
       ;
 198   
     }
 199   
                                                           fireStartElement(elementName, attributes);
 200   
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 201   
     case OBRACE:
 202   
       element_body();
 203   
       break;
 204   
     default:
 205   
       jj_la1[1] = jj_gen;
 206   
       ;
 207   
     }
 208   
                                           updateLocator(); fireEndElement(elementName);
 209   
   }
 210   
 
 211   
   final public void element_attributes(AttributesImpl attributes) throws ParseException {
 212   
     jj_consume_token(OPAREN);
 213   
     label_1:
 214   
     while (true) {
 215   
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 216   
       case SIMPLE_ID:
 217   
         ;
 218   
         break;
 219   
       default:
 220   
         jj_la1[2] = jj_gen;
 221   
         break label_1;
 222   
       }
 223   
       attribute(attributes);
 224   
     }
 225   
     jj_consume_token(CPAREN);
 226   
   }
 227   
 
 228   
   final public void attribute(AttributesImpl attributes) throws ParseException {
 229   
   String attributeName;
 230   
     jj_consume_token(SIMPLE_ID);
 231   
                           attributeName = token.image;
 232   
     jj_consume_token(EQ);
 233   
     attribute_value(attributeName, attributes);
 234   
   }
 235   
 
 236   
   final public void attribute_value(String attributeName, AttributesImpl attributes) throws ParseException {
 237   
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 238   
     case NUMERIC_LITERAL:
 239   
     case SIMPLE_ID:
 240   
     case COMPLEX_ID:
 241   
     case SYMBOL:
 242   
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 243   
       case NUMERIC_LITERAL:
 244   
         jj_consume_token(NUMERIC_LITERAL);
 245   
         break;
 246   
       case SIMPLE_ID:
 247   
         jj_consume_token(SIMPLE_ID);
 248   
         break;
 249   
       case COMPLEX_ID:
 250   
         jj_consume_token(COMPLEX_ID);
 251   
         break;
 252   
       case SYMBOL:
 253   
         jj_consume_token(SYMBOL);
 254   
         break;
 255   
       default:
 256   
         jj_la1[3] = jj_gen;
 257   
         jj_consume_token(-1);
 258   
         throw new ParseException();
 259   
       }
 260   
                                                                 addAttribute(attributes, attributeName, token.image);
 261   
       break;
 262   
     case QUOTED_LITERAL:
 263   
       jj_consume_token(QUOTED_LITERAL);
 264   
                       addAttribute(attributes, attributeName, unquote(token.image));
 265   
       break;
 266   
     case EXTENDED_LITERAL:
 267   
       jj_consume_token(EXTENDED_LITERAL);
 268   
                        addAttribute(attributes, attributeName, defang(token.image));
 269   
       break;
 270   
     default:
 271   
       jj_la1[4] = jj_gen;
 272   
       jj_consume_token(-1);
 273   
       throw new ParseException();
 274   
     }
 275   
   }
 276   
 
 277   
   final public void element_body() throws ParseException {
 278   
     jj_consume_token(OBRACE);
 279   
     label_2:
 280   
     while (true) {
 281   
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 282   
       case NUMERIC_LITERAL:
 283   
       case SIMPLE_ID:
 284   
       case COMPLEX_ID:
 285   
       case QUOTED_LITERAL:
 286   
       case EXTENDED_LITERAL:
 287   
       case SYMBOL:
 288   
         ;
 289   
         break;
 290   
       default:
 291   
         jj_la1[5] = jj_gen;
 292   
         break label_2;
 293   
       }
 294   
       body_content();
 295   
     }
 296   
     jj_consume_token(CBRACE);
 297   
   }
 298   
 
 299   
   final public void body_content() throws ParseException {
 300   
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 301   
     case SIMPLE_ID:
 302   
       element();
 303   
       break;
 304   
     case QUOTED_LITERAL:
 305   
       jj_consume_token(QUOTED_LITERAL);
 306   
                        fireCharacters(unquote(token.image));
 307   
       break;
 308   
     case NUMERIC_LITERAL:
 309   
     case COMPLEX_ID:
 310   
     case SYMBOL:
 311   
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 312   
       case COMPLEX_ID:
 313   
         jj_consume_token(COMPLEX_ID);
 314   
         break;
 315   
       case NUMERIC_LITERAL:
 316   
         jj_consume_token(NUMERIC_LITERAL);
 317   
         break;
 318   
       case SYMBOL:
 319   
         jj_consume_token(SYMBOL);
 320   
         break;
 321   
       default:
 322   
         jj_la1[6] = jj_gen;
 323   
         jj_consume_token(-1);
 324   
         throw new ParseException();
 325   
       }
 326   
                                                     fireCharacters(token.image);
 327   
       break;
 328   
     case EXTENDED_LITERAL:
 329   
       jj_consume_token(EXTENDED_LITERAL);
 330   
                        fireCharactersForExtendedLiteral(token.image);
 331   
       break;
 332   
     default:
 333   
       jj_la1[7] = jj_gen;
 334   
       jj_consume_token(-1);
 335   
       throw new ParseException();
 336   
     }
 337   
   }
 338   
 
 339   
   public SimpleDataLanguageParserTokenManager token_source;
 340   
   SimpleCharStream jj_input_stream;
 341   
   public Token token, jj_nt;
 342   
   private int jj_ntk;
 343   
   private int jj_gen;
 344   
   final private int[] jj_la1 = new int[8];
 345   
   final private int[] jj_la1_0 = {0x2000,0x8000,0x40,0x4e0,0x7e0,0x7e0,0x4a0,0x7e0,};
 346   
 
 347   
   public SimpleDataLanguageParser(java.io.InputStream stream) {
 348   
     jj_input_stream = new SimpleCharStream(stream, 1, 1);
 349   
     token_source = new SimpleDataLanguageParserTokenManager(jj_input_stream);
 350   
     token = new Token();
 351   
     jj_ntk = -1;
 352   
     jj_gen = 0;
 353   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 354   
   }
 355   
 
 356   
   public void ReInit(java.io.InputStream stream) {
 357   
     jj_input_stream.ReInit(stream, 1, 1);
 358   
     token_source.ReInit(jj_input_stream);
 359   
     token = new Token();
 360   
     jj_ntk = -1;
 361   
     jj_gen = 0;
 362   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 363   
   }
 364   
 
 365   
   public SimpleDataLanguageParser(java.io.Reader stream) {
 366   
     jj_input_stream = new SimpleCharStream(stream, 1, 1);
 367   
     token_source = new SimpleDataLanguageParserTokenManager(jj_input_stream);
 368   
     token = new Token();
 369   
     jj_ntk = -1;
 370   
     jj_gen = 0;
 371   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 372   
   }
 373   
 
 374   
   public void ReInit(java.io.Reader stream) {
 375   
     jj_input_stream.ReInit(stream, 1, 1);
 376   
     token_source.ReInit(jj_input_stream);
 377   
     token = new Token();
 378   
     jj_ntk = -1;
 379   
     jj_gen = 0;
 380   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 381   
   }
 382   
 
 383   
   public SimpleDataLanguageParser(SimpleDataLanguageParserTokenManager tm) {
 384   
     token_source = tm;
 385   
     token = new Token();
 386   
     jj_ntk = -1;
 387   
     jj_gen = 0;
 388   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 389   
   }
 390   
 
 391   
   public void ReInit(SimpleDataLanguageParserTokenManager tm) {
 392   
     token_source = tm;
 393   
     token = new Token();
 394   
     jj_ntk = -1;
 395   
     jj_gen = 0;
 396   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 397   
   }
 398   
 
 399   
   final private Token jj_consume_token(int kind) throws ParseException {
 400   
     Token oldToken;
 401   
     if ((oldToken = token).next != null) token = token.next;
 402   
     else token = token.next = token_source.getNextToken();
 403   
     jj_ntk = -1;
 404   
     if (token.kind == kind) {
 405   
       jj_gen++;
 406   
       return token;
 407   
     }
 408   
     token = oldToken;
 409   
     jj_kind = kind;
 410   
     throw generateParseException();
 411   
   }
 412   
 
 413   
   final public Token getNextToken() {
 414   
     if (token.next != null) token = token.next;
 415   
     else token = token.next = token_source.getNextToken();
 416   
     jj_ntk = -1;
 417   
     jj_gen++;
 418   
     return token;
 419   
   }
 420   
 
 421   
   final public Token getToken(int index) {
 422   
     Token t = token;
 423   
     for (int i = 0; i < index; i++) {
 424   
       if (t.next != null) t = t.next;
 425   
       else t = t.next = token_source.getNextToken();
 426   
     }
 427   
     return t;
 428   
   }
 429   
 
 430   
   final private int jj_ntk() {
 431   
     if ((jj_nt=token.next) == null)
 432   
       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
 433   
     else
 434   
       return (jj_ntk = jj_nt.kind);
 435   
   }
 436   
 
 437   
   private java.util.Vector jj_expentries = new java.util.Vector();
 438   
   private int[] jj_expentry;
 439   
   private int jj_kind = -1;
 440   
 
 441   
   final public ParseException generateParseException() {
 442   
     jj_expentries.removeAllElements();
 443   
     boolean[] la1tokens = new boolean[27];
 444   
     for (int i = 0; i < 27; i++) {
 445   
       la1tokens[i] = false;
 446   
     }
 447   
     if (jj_kind >= 0) {
 448   
       la1tokens[jj_kind] = true;
 449   
       jj_kind = -1;
 450   
     }
 451   
     for (int i = 0; i < 8; i++) {
 452   
       if (jj_la1[i] == jj_gen) {
 453   
         for (int j = 0; j < 32; j++) {
 454   
           if ((jj_la1_0[i] & (1<<j)) != 0) {
 455   
             la1tokens[j] = true;
 456   
           }
 457   
         }
 458   
       }
 459   
     }
 460   
     for (int i = 0; i < 27; i++) {
 461   
       if (la1tokens[i]) {
 462   
         jj_expentry = new int[1];
 463   
         jj_expentry[0] = i;
 464   
         jj_expentries.addElement(jj_expentry);
 465   
       }
 466   
     }
 467   
     int[][] exptokseq = new int[jj_expentries.size()][];
 468   
     for (int i = 0; i < jj_expentries.size(); i++) {
 469   
       exptokseq[i] = (int[])jj_expentries.elementAt(i);
 470   
     }
 471   
     return new ParseException(token, exptokseq, tokenImage);
 472   
   }
 473   
 
 474   
   final public void enable_tracing() {
 475   
   }
 476   
 
 477   
   final public void disable_tracing() {
 478   
   }
 479   
 
 480   
 }
 481