Clover coverage report - Code Coverage for hivemind release 1.0-beta-2
Coverage timestamp: Sun Aug 1 2004 14:03:45 EDT
file stats: LOC: 485   Methods: 12
NCLOC: 385   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.4 2004/07/16 23&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  121
         public Locator getLocator()
 40   
         {
 41  121
                 return _locator;
 42   
         }
 43   
 
 44  50076
         private void updateLocator()
 45   
         {
 46  50076
           _locator.update(token.beginLine, token.beginColumn);
 47   
         }
 48   
 
 49  120
     private void fireStartDocument() throws ParseException
 50   
     {
 51  120
         try { _handler.startDocument(); }
 52  0
                 catch (SAXException ex) { handleException(ex); }
 53   
         }
 54   
 
 55  119
     private void fireEndDocument() throws ParseException
 56   
     {
 57  119
                 try { _handler.endDocument(); }
 58  0
                 catch (SAXException ex) { handleException(ex); }
 59   
         }
 60   
 
 61  25038
         private void fireStartElement(String elementName, Attributes attributes) throws ParseException
 62   
         {
 63   
                 // No namespace, no qualified name
 64   
 
 65  25038
                 try { _handler.startElement("", elementName, null, attributes); }
 66  0
                 catch (SAXException ex) { handleException(ex); }
 67   
         }
 68   
 
 69  25037
         private void fireEndElement(String elementName) throws ParseException
 70   
         {
 71   
                 // No namespace, no qualified name
 72   
 
 73  25037
                 try { _handler.endElement("", elementName, elementName); }
 74  0
                 catch (SAXException ex) { handleException(ex); }
 75   
         }
 76   
 
 77  9880
     private void fireCharacters(String string) throws ParseException
 78   
     {
 79  9880
       try { _handler.characters(string.toCharArray(), 0, string.length()); }
 80  0
       catch (SAXException ex) { handleException(ex); }
 81   
     }
 82   
 
 83  90
     private void fireCharactersForExtendedLiteral(String string) throws ParseException
 84   
     {
 85  90
       try
 86   
       {
 87  90
         _handler.characters(string.toCharArray(), 2, string.length() - 4);
 88   
       }
 89  0
       catch (SAXException ex) { handleException(ex); }
 90   
     }
 91   
 
 92  35483
         private void addAttribute(AttributesImpl attributes, String name, String value)
 93   
         {
 94  35483
                 attributes.addAttribute("", name, name, "CDATA", value);
 95   
         }
 96   
 
 97  10164
         private String unquote(String input)
 98   
         {
 99  10164
                 StringBuffer buffer = new StringBuffer(input.length());
 100   
 
 101  10164
                 char[] chars = input.toCharArray();
 102   
 
 103  10164
                 int state = 0;
 104   
 
 105  10164
                 for (int i = 1; i < chars.length - 1; i++)
 106   
                 {
 107  625822
                   char ch = chars[i];
 108   
 
 109  625822
                   switch (state)
 110   
                   {
 111   
                     case 0:
 112   
 
 113  625816
                         if (ch == '\\')
 114   
                         {
 115  6
                           state = 1;
 116  6
                           continue;
 117   
                         }
 118   
 
 119  625810
                         buffer.append(ch);
 120  625810
                         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  10164
                 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 SEGMENTED_ID:
 242   
     case SYMBOL:
 243   
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 244   
       case NUMERIC_LITERAL:
 245   
         jj_consume_token(NUMERIC_LITERAL);
 246   
         break;
 247   
       case SIMPLE_ID:
 248   
         jj_consume_token(SIMPLE_ID);
 249   
         break;
 250   
       case COMPLEX_ID:
 251   
         jj_consume_token(COMPLEX_ID);
 252   
         break;
 253   
       case SEGMENTED_ID:
 254   
         jj_consume_token(SEGMENTED_ID);
 255   
         break;
 256   
       case SYMBOL:
 257   
         jj_consume_token(SYMBOL);
 258   
         break;
 259   
       default:
 260   
         jj_la1[3] = jj_gen;
 261   
         jj_consume_token(-1);
 262   
         throw new ParseException();
 263   
       }
 264   
                                                                                   addAttribute(attributes, attributeName, token.image);
 265   
       break;
 266   
     case QUOTED_LITERAL:
 267   
       jj_consume_token(QUOTED_LITERAL);
 268   
                       addAttribute(attributes, attributeName, unquote(token.image));
 269   
       break;
 270   
     case EXTENDED_LITERAL:
 271   
       jj_consume_token(EXTENDED_LITERAL);
 272   
                        addAttribute(attributes, attributeName, defang(token.image));
 273   
       break;
 274   
     default:
 275   
       jj_la1[4] = jj_gen;
 276   
       jj_consume_token(-1);
 277   
       throw new ParseException();
 278   
     }
 279   
   }
 280   
 
 281   
   final public void element_body() throws ParseException {
 282   
     jj_consume_token(OBRACE);
 283   
     label_2:
 284   
     while (true) {
 285   
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 286   
       case NUMERIC_LITERAL:
 287   
       case SIMPLE_ID:
 288   
       case COMPLEX_ID:
 289   
       case QUOTED_LITERAL:
 290   
       case EXTENDED_LITERAL:
 291   
       case SYMBOL:
 292   
         ;
 293   
         break;
 294   
       default:
 295   
         jj_la1[5] = jj_gen;
 296   
         break label_2;
 297   
       }
 298   
       body_content();
 299   
     }
 300   
     jj_consume_token(CBRACE);
 301   
   }
 302   
 
 303   
   final public void body_content() throws ParseException {
 304   
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 305   
     case SIMPLE_ID:
 306   
       element();
 307   
       break;
 308   
     case QUOTED_LITERAL:
 309   
       jj_consume_token(QUOTED_LITERAL);
 310   
                        fireCharacters(unquote(token.image));
 311   
       break;
 312   
     case NUMERIC_LITERAL:
 313   
     case COMPLEX_ID:
 314   
     case SYMBOL:
 315   
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
 316   
       case COMPLEX_ID:
 317   
         jj_consume_token(COMPLEX_ID);
 318   
         break;
 319   
       case NUMERIC_LITERAL:
 320   
         jj_consume_token(NUMERIC_LITERAL);
 321   
         break;
 322   
       case SYMBOL:
 323   
         jj_consume_token(SYMBOL);
 324   
         break;
 325   
       default:
 326   
         jj_la1[6] = jj_gen;
 327   
         jj_consume_token(-1);
 328   
         throw new ParseException();
 329   
       }
 330   
                                                     fireCharacters(token.image);
 331   
       break;
 332   
     case EXTENDED_LITERAL:
 333   
       jj_consume_token(EXTENDED_LITERAL);
 334   
                        fireCharactersForExtendedLiteral(token.image);
 335   
       break;
 336   
     default:
 337   
       jj_la1[7] = jj_gen;
 338   
       jj_consume_token(-1);
 339   
       throw new ParseException();
 340   
     }
 341   
   }
 342   
 
 343   
   public SimpleDataLanguageParserTokenManager token_source;
 344   
   SimpleCharStream jj_input_stream;
 345   
   public Token token, jj_nt;
 346   
   private int jj_ntk;
 347   
   private int jj_gen;
 348   
   final private int[] jj_la1 = new int[8];
 349   
   final private int[] jj_la1_0 = {0x4000,0x10000,0x40,0x9e0,0xfe0,0xee0,0x8a0,0xee0,};
 350   
 
 351   
   public SimpleDataLanguageParser(java.io.InputStream stream) {
 352   
     jj_input_stream = new SimpleCharStream(stream, 1, 1);
 353   
     token_source = new SimpleDataLanguageParserTokenManager(jj_input_stream);
 354   
     token = new Token();
 355   
     jj_ntk = -1;
 356   
     jj_gen = 0;
 357   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 358   
   }
 359   
 
 360   
   public void ReInit(java.io.InputStream stream) {
 361   
     jj_input_stream.ReInit(stream, 1, 1);
 362   
     token_source.ReInit(jj_input_stream);
 363   
     token = new Token();
 364   
     jj_ntk = -1;
 365   
     jj_gen = 0;
 366   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 367   
   }
 368   
 
 369   
   public SimpleDataLanguageParser(java.io.Reader stream) {
 370   
     jj_input_stream = new SimpleCharStream(stream, 1, 1);
 371   
     token_source = new SimpleDataLanguageParserTokenManager(jj_input_stream);
 372   
     token = new Token();
 373   
     jj_ntk = -1;
 374   
     jj_gen = 0;
 375   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 376   
   }
 377   
 
 378   
   public void ReInit(java.io.Reader stream) {
 379   
     jj_input_stream.ReInit(stream, 1, 1);
 380   
     token_source.ReInit(jj_input_stream);
 381   
     token = new Token();
 382   
     jj_ntk = -1;
 383   
     jj_gen = 0;
 384   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 385   
   }
 386   
 
 387   
   public SimpleDataLanguageParser(SimpleDataLanguageParserTokenManager tm) {
 388   
     token_source = tm;
 389   
     token = new Token();
 390   
     jj_ntk = -1;
 391   
     jj_gen = 0;
 392   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 393   
   }
 394   
 
 395   
   public void ReInit(SimpleDataLanguageParserTokenManager tm) {
 396   
     token_source = tm;
 397   
     token = new Token();
 398   
     jj_ntk = -1;
 399   
     jj_gen = 0;
 400   
     for (int i = 0; i < 8; i++) jj_la1[i] = -1;
 401   
   }
 402   
 
 403   
   final private Token jj_consume_token(int kind) throws ParseException {
 404   
     Token oldToken;
 405   
     if ((oldToken = token).next != null) token = token.next;
 406   
     else token = token.next = token_source.getNextToken();
 407   
     jj_ntk = -1;
 408   
     if (token.kind == kind) {
 409   
       jj_gen++;
 410   
       return token;
 411   
     }
 412   
     token = oldToken;
 413   
     jj_kind = kind;
 414   
     throw generateParseException();
 415   
   }
 416   
 
 417   
   final public Token getNextToken() {
 418   
     if (token.next != null) token = token.next;
 419   
     else token = token.next = token_source.getNextToken();
 420   
     jj_ntk = -1;
 421   
     jj_gen++;
 422   
     return token;
 423   
   }
 424   
 
 425   
   final public Token getToken(int index) {
 426   
     Token t = token;
 427   
     for (int i = 0; i < index; i++) {
 428   
       if (t.next != null) t = t.next;
 429   
       else t = t.next = token_source.getNextToken();
 430   
     }
 431   
     return t;
 432   
   }
 433   
 
 434   
   final private int jj_ntk() {
 435   
     if ((jj_nt=token.next) == null)
 436   
       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
 437   
     else
 438   
       return (jj_ntk = jj_nt.kind);
 439   
   }
 440   
 
 441   
   private java.util.Vector jj_expentries = new java.util.Vector();
 442   
   private int[] jj_expentry;
 443   
   private int jj_kind = -1;
 444   
 
 445   
   final public ParseException generateParseException() {
 446   
     jj_expentries.removeAllElements();
 447   
     boolean[] la1tokens = new boolean[29];
 448   
     for (int i = 0; i < 29; i++) {
 449   
       la1tokens[i] = false;
 450   
     }
 451   
     if (jj_kind >= 0) {
 452   
       la1tokens[jj_kind] = true;
 453   
       jj_kind = -1;
 454   
     }
 455   
     for (int i = 0; i < 8; i++) {
 456   
       if (jj_la1[i] == jj_gen) {
 457   
         for (int j = 0; j < 32; j++) {
 458   
           if ((jj_la1_0[i] & (1<<j)) != 0) {
 459   
             la1tokens[j] = true;
 460   
           }
 461   
         }
 462   
       }
 463   
     }
 464   
     for (int i = 0; i < 29; i++) {
 465   
       if (la1tokens[i]) {
 466   
         jj_expentry = new int[1];
 467   
         jj_expentry[0] = i;
 468   
         jj_expentries.addElement(jj_expentry);
 469   
       }
 470   
     }
 471   
     int[][] exptokseq = new int[jj_expentries.size()][];
 472   
     for (int i = 0; i < jj_expentries.size(); i++) {
 473   
       exptokseq[i] = (int[])jj_expentries.elementAt(i);
 474   
     }
 475   
     return new ParseException(token, exptokseq, tokenImage);
 476   
   }
 477   
 
 478   
   final public void enable_tracing() {
 479   
   }
 480   
 
 481   
   final public void disable_tracing() {
 482   
   }
 483   
 
 484   
 }
 485