Clover coverage report - Code Coverage for hivemind release 1.1-alpha-1
Coverage timestamp: Tue Jan 18 2005 07:55:08 EST
file stats: LOC: 1,398   Methods: 63
NCLOC: 899   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
DescriptorParser.java 89.7% 95.6% 98.4% 94.8%
coverage coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.parse;
 16   
 
 17   
 import java.io.BufferedInputStream;
 18   
 import java.io.IOException;
 19   
 import java.io.InputStream;
 20   
 import java.util.Enumeration;
 21   
 import java.util.HashMap;
 22   
 import java.util.Iterator;
 23   
 import java.util.Map;
 24   
 import java.util.Properties;
 25   
 
 26   
 import org.apache.commons.logging.Log;
 27   
 import org.apache.commons.logging.LogFactory;
 28   
 import org.apache.hivemind.ApplicationRuntimeException;
 29   
 import org.apache.hivemind.Attribute;
 30   
 import org.apache.hivemind.ClassResolver;
 31   
 import org.apache.hivemind.ErrorHandler;
 32   
 import org.apache.hivemind.Occurances;
 33   
 import org.apache.hivemind.Resource;
 34   
 import org.apache.hivemind.impl.AttributeImpl;
 35   
 import org.apache.hivemind.impl.ElementImpl;
 36   
 import org.apache.hivemind.internal.Visibility;
 37   
 import org.apache.hivemind.schema.ElementModel;
 38   
 import org.apache.hivemind.schema.Rule;
 39   
 import org.apache.hivemind.schema.impl.AttributeModelImpl;
 40   
 import org.apache.hivemind.schema.impl.ElementModelImpl;
 41   
 import org.apache.hivemind.schema.impl.SchemaImpl;
 42   
 import org.apache.hivemind.schema.rules.CreateObjectRule;
 43   
 import org.apache.hivemind.schema.rules.InvokeParentRule;
 44   
 import org.apache.hivemind.schema.rules.PushAttributeRule;
 45   
 import org.apache.hivemind.schema.rules.ReadAttributeRule;
 46   
 import org.apache.hivemind.schema.rules.ReadContentRule;
 47   
 import org.apache.hivemind.schema.rules.SetModuleRule;
 48   
 import org.apache.hivemind.schema.rules.SetParentRule;
 49   
 import org.apache.hivemind.schema.rules.SetPropertyRule;
 50   
 import org.apache.oro.text.regex.MalformedPatternException;
 51   
 import org.apache.oro.text.regex.Pattern;
 52   
 import org.apache.oro.text.regex.Perl5Compiler;
 53   
 import org.apache.oro.text.regex.Perl5Matcher;
 54   
 import org.xml.sax.Attributes;
 55   
 
 56   
 /**
 57   
  * Used to parse HiveMind module deployment descriptors.
 58   
  * <p>
 59   
  * TODO: The parser ignores element content except inside &lt;contribution&gt; and
 60   
  * &lt;invoke-factory&gt; ... it probably should forbid non-whitespace content.
 61   
  * 
 62   
  * @author Howard Lewis Ship
 63   
  */
 64   
 public final class DescriptorParser extends AbstractParser
 65   
 {
 66   
     private static final String DEFAULT_SERVICE_MODEL = "singleton";
 67   
 
 68   
     private static final Log LOG = LogFactory.getLog(DescriptorParser.class);
 69   
 
 70   
     /**
 71   
      * States used while parsing the document. Most states correspond to a particular XML element in
 72   
      * the document. STATE_START is the initial state, before the &lt;module&gt; element is reached.
 73   
      */
 74   
     private static final int STATE_START = 0;
 75   
 
 76   
     private static final int STATE_MODULE = 1;
 77   
 
 78   
     // private static final int STATE_DESCRIPTION = 2;
 79   
     private static final int STATE_CONFIGURATION_POINT = 3;
 80   
 
 81   
     private static final int STATE_CONTRIBUTION = 4;
 82   
 
 83   
     private static final int STATE_SERVICE_POINT = 5;
 84   
 
 85   
     private static final int STATE_CREATE_INSTANCE = 6;
 86   
 
 87   
     private static final int STATE_IMPLEMENTATION = 8;
 88   
 
 89   
     /**
 90   
      * Used for both &lt;schema&;gt; within a &lt;extension-point&gt;, and for
 91   
      * &lt;parameters-schema&gt; within a &lt;service&gt;.
 92   
      */
 93   
     private static final int STATE_SCHEMA = 9;
 94   
 
 95   
     private static final int STATE_ELEMENT = 10;
 96   
 
 97   
     private static final int STATE_RULES = 11;
 98   
 
 99   
     /**
 100   
      * Used with &lt;invoke-factory&gt; and &lt;interceptor&gt; to collect parameters that will be
 101   
      * passed to the implementation or interceptor factory service.
 102   
      */
 103   
     private static final int STATE_COLLECT_SERVICE_PARAMETERS = 12;
 104   
 
 105   
     /**
 106   
      * Used with the &lt;conversion&gt; element (an alternative to using &lt;rules&gt;. Finds
 107   
      * &lt;map&gt; elements.
 108   
      */
 109   
     private static final int STATE_CONVERSION = 13;
 110   
 
 111   
     /**
 112   
      * Represents building Element hierarchy as a light-wieght DOM.
 113   
      */
 114   
 
 115   
     private static final int STATE_LWDOM = 100;
 116   
 
 117   
     /**
 118   
      * Special state for elements that are not allowed to contain any other elements.
 119   
      */
 120   
 
 121   
     private static final int STATE_NO_CONTENT = 300;
 122   
 
 123   
     private static final String SIMPLE_ID = "[a-zA-Z0-9_]+";
 124   
 
 125   
     /**
 126   
      * Format for configuration point ids, service point ids and schema ids. Consists of an optional
 127   
      * leading underscore, followed by alphanumerics and underscores. Normal naming convention is to
 128   
      * use a single CamelCase word, like a Java class name.
 129   
      */
 130   
     public static final String ID_PATTERN = "^" + SIMPLE_ID + "$";
 131   
 
 132   
     /**
 133   
      * Module ids are a sequence of simple ids seperated by periods. In practice, they look like
 134   
      * Java package names.
 135   
      */
 136   
     public static final String MODULE_ID_PATTERN = "^" + SIMPLE_ID + "(\\." + SIMPLE_ID + ")*$";
 137   
 
 138   
     public static final String VERSION_PATTERN = "[0-9]+(\\.[0-9]+){2}$";
 139   
 
 140   
     /**
 141   
      * Temporary storage of the current {@link Attributes}.
 142   
      */
 143   
     private Map _attributes = new HashMap();
 144   
 
 145   
     /**
 146   
      * Built from DescriptorParser.properties. Key is element name, value is an instance of
 147   
      * {@link ElementParseInfo}.
 148   
      */
 149   
 
 150   
     private Map _elementParseInfo = new HashMap();
 151   
 
 152   
     private ModuleDescriptor _moduleDescriptor;
 153   
 
 154   
     private ErrorHandler _errorHandler;
 155   
 
 156   
     private ClassResolver _resolver;
 157   
 
 158   
     private Perl5Compiler _compiler;
 159   
 
 160   
     private Perl5Matcher _matcher;
 161   
 
 162   
     private Map _compiledPatterns;
 163   
 
 164   
     /**
 165   
      * Map of Rule keyed on class name, used with &lt;custom&gt; rules.
 166   
      */
 167   
     private final Map _ruleMap = new HashMap();
 168   
 
 169   
     private final Map OCCURS_MAP = new HashMap();
 170   
 
 171   
     {
 172  228
         OCCURS_MAP.put("0..1", Occurances.OPTIONAL);
 173  228
         OCCURS_MAP.put("1", Occurances.REQUIRED);
 174  228
         OCCURS_MAP.put("1..n", Occurances.ONE_PLUS);
 175  228
         OCCURS_MAP.put("0..n", Occurances.UNBOUNDED);
 176  228
         OCCURS_MAP.put("none", Occurances.NONE);
 177   
     }
 178   
 
 179   
     private final Map VISIBILITY_MAP = new HashMap();
 180   
 
 181   
     {
 182  228
         VISIBILITY_MAP.put("public", Visibility.PUBLIC);
 183  228
         VISIBILITY_MAP.put("private", Visibility.PRIVATE);
 184   
     }
 185   
 
 186  228
     public DescriptorParser(ErrorHandler errorHandler)
 187   
     {
 188  228
         _errorHandler = errorHandler;
 189   
 
 190  228
         initializeFromPropertiesFile();
 191   
     }
 192   
 
 193  34448
     public void begin(String elementName, Map attributes)
 194   
     {
 195  34448
         _attributes = attributes;
 196   
 
 197  34448
         switch (getState())
 198   
         {
 199   
             case STATE_START:
 200   
 
 201  241
                 beginStart(elementName);
 202  241
                 break;
 203   
 
 204   
             case STATE_MODULE:
 205   
 
 206  3559
                 beginModule(elementName);
 207  3559
                 break;
 208   
 
 209   
             case STATE_CONFIGURATION_POINT:
 210   
 
 211  638
                 beginConfigurationPoint(elementName);
 212  638
                 break;
 213   
 
 214   
             case STATE_CONTRIBUTION:
 215   
 
 216  2452
                 beginContribution(elementName);
 217  2452
                 break;
 218   
 
 219   
             case STATE_LWDOM:
 220   
 
 221  913
                 beginLWDom(elementName);
 222  913
                 break;
 223   
 
 224   
             case STATE_SERVICE_POINT:
 225   
 
 226  1857
                 beginServicePoint(elementName);
 227  1857
                 break;
 228   
 
 229   
             case STATE_IMPLEMENTATION:
 230   
 
 231  18
                 beginImplementation(elementName);
 232  18
                 break;
 233   
 
 234   
             case STATE_SCHEMA:
 235   
 
 236  1156
                 beginSchema(elementName);
 237  1155
                 break;
 238   
 
 239   
             case STATE_ELEMENT:
 240   
 
 241  9821
                 beginElement(elementName);
 242  9820
                 break;
 243   
 
 244   
             case STATE_RULES:
 245   
 
 246  12138
                 beginRules(elementName);
 247  12137
                 break;
 248   
 
 249   
             case STATE_COLLECT_SERVICE_PARAMETERS:
 250   
 
 251  909
                 beginCollectServiceParameters(elementName);
 252  909
                 break;
 253   
 
 254   
             case STATE_CONVERSION:
 255   
 
 256  746
                 beginConversion(elementName);
 257  746
                 break;
 258   
 
 259   
             default:
 260   
 
 261  0
                 unexpectedElement(elementName);
 262  0
                 break;
 263   
         }
 264   
     }
 265   
 
 266   
     /**
 267   
      * Very similar to {@link #beginContribution(String)}, in that it creates an
 268   
      * {@link ElementImpl}, adds it as a parameter to the
 269   
      * {@link AbstractServiceInvocationDescriptor}, then enters STATE_LWDOM to fill in its
 270   
      * attributes and content.
 271   
      */
 272   
 
 273  909
     private void beginCollectServiceParameters(String elementName)
 274   
     {
 275  909
         ElementImpl element = buildLWDomElement(elementName);
 276   
 
 277  909
         AbstractServiceInvocationDescriptor sid = (AbstractServiceInvocationDescriptor) peekObject();
 278   
 
 279  909
         sid.addParameter(element);
 280   
 
 281  909
         push(elementName, element, STATE_LWDOM, false);
 282   
     }
 283   
 
 284   
     /**
 285   
      * Invoked when a new element starts within STATE_CONFIGURATION_POINT.
 286   
      */
 287  638
     private void beginConfigurationPoint(String elementName)
 288   
     {
 289  638
         if (elementName.equals("schema"))
 290   
         {
 291  638
             enterEmbeddedConfigurationPointSchema(elementName);
 292  638
             return;
 293   
         }
 294   
 
 295  0
         unexpectedElement(elementName);
 296   
     }
 297   
 
 298  2452
     private void beginContribution(String elementName)
 299   
     {
 300   
         // This is where things get tricky, the point where we outgrew Jakarta Digester.
 301   
 
 302  2452
         ElementImpl element = buildLWDomElement(elementName);
 303   
 
 304  2452
         ContributionDescriptor ed = (ContributionDescriptor) peekObject();
 305  2452
         ed.addElement(element);
 306   
 
 307  2452
         push(elementName, element, STATE_LWDOM, false);
 308   
     }
 309   
 
 310  746
     private void beginConversion(String elementName)
 311   
     {
 312  746
         if (elementName.equals("map"))
 313   
         {
 314  746
             ConversionDescriptor cd = (ConversionDescriptor) peekObject();
 315   
 
 316  746
             AttributeMappingDescriptor amd = new AttributeMappingDescriptor();
 317   
 
 318  746
             push(elementName, amd, STATE_NO_CONTENT);
 319   
 
 320  746
             checkAttributes();
 321   
 
 322  746
             amd.setAttributeName(getAttribute("attribute"));
 323  746
             amd.setPropertyName(getAttribute("property"));
 324   
 
 325  746
             cd.addAttributeMapping(amd);
 326   
 
 327  746
             return;
 328   
         }
 329   
 
 330  0
         unexpectedElement(elementName);
 331   
     }
 332   
 
 333  9821
     private void beginElement(String elementName)
 334   
     {
 335  9821
         if (elementName.equals("attribute"))
 336   
         {
 337  4245
             enterAttribute(elementName);
 338  4245
             return;
 339   
         }
 340   
 
 341  5576
         if (elementName.equals("conversion"))
 342   
         {
 343  437
             enterConversion(elementName);
 344  437
             return;
 345   
         }
 346   
 
 347  5139
         if (elementName.equals("rules"))
 348   
         {
 349  2922
             enterRules(elementName);
 350  2922
             return;
 351   
         }
 352   
 
 353   
         // <element> is recursive ... possible, but tricky, if using Digester.
 354   
 
 355  2217
         if (elementName.equals("element"))
 356   
         {
 357  2216
             ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 358   
 
 359  2216
             elementModel.addElementModel(enterElement(elementName));
 360  2216
             return;
 361   
         }
 362   
 
 363  1
         unexpectedElement(elementName);
 364   
     }
 365   
 
 366  1767
     private void beginImplementation(String elementName)
 367   
     {
 368   
 
 369  1767
         if (elementName.equals("create-instance"))
 370   
         {
 371  793
             enterCreateInstance(elementName);
 372  793
             return;
 373   
         }
 374   
 
 375  974
         if (elementName.equals("invoke-factory"))
 376   
         {
 377  908
             enterInvokeFactory(elementName);
 378  908
             return;
 379   
         }
 380   
 
 381  66
         if (elementName.equals("interceptor"))
 382   
         {
 383  66
             enterInterceptor(elementName);
 384  66
             return;
 385   
         }
 386   
 
 387  0
         unexpectedElement(elementName);
 388   
     }
 389   
 
 390  913
     private void beginLWDom(String elementName)
 391   
     {
 392  913
         ElementImpl element = buildLWDomElement(elementName);
 393   
 
 394  913
         ElementImpl parent = (ElementImpl) peekObject();
 395  913
         parent.addElement(element);
 396   
 
 397  913
         push(elementName, element, STATE_LWDOM, false);
 398   
     }
 399   
 
 400   
     /**
 401   
      * Invoked when a new element occurs while in STATE_MODULE.
 402   
      */
 403  3559
     private void beginModule(String elementName)
 404   
     {
 405  3559
         if (elementName.equals("configuration-point"))
 406   
         {
 407  916
             enterConfigurationPoint(elementName);
 408   
 
 409  916
             return;
 410   
         }
 411   
 
 412  2643
         if (elementName.equals("contribution"))
 413   
         {
 414  608
             enterContribution(elementName);
 415  608
             return;
 416   
         }
 417   
 
 418  2035
         if (elementName.equals("service-point"))
 419   
         {
 420  1716
             enterServicePoint(elementName);
 421   
 
 422  1716
             return;
 423   
         }
 424   
 
 425  319
         if (elementName.equals("implementation"))
 426   
         {
 427  16
             enterImplementation(elementName);
 428   
 
 429  16
             return;
 430   
         }
 431   
 
 432  303
         if (elementName.equals("schema"))
 433   
         {
 434  290
             enterSchema(elementName);
 435  290
             return;
 436   
         }
 437   
 
 438  13
         if (elementName.equals("sub-module"))
 439   
         {
 440  3
             enterSubModule(elementName);
 441   
 
 442  3
             return;
 443   
         }
 444   
 
 445  10
         if (elementName.equals("dependency"))
 446   
         {
 447  10
             enterDependency(elementName);
 448   
 
 449  10
             return;
 450   
         }
 451   
 
 452  0
         unexpectedElement(elementName);
 453   
     }
 454   
 
 455  12138
     private void beginRules(String elementName)
 456   
     {
 457   
 
 458  12138
         if (elementName.equals("create-object"))
 459   
         {
 460  3228
             enterCreateObject(elementName);
 461  3228
             return;
 462   
         }
 463   
 
 464  8910
         if (elementName.equals("invoke-parent"))
 465   
         {
 466  3542
             enterInvokeParent(elementName);
 467  3542
             return;
 468   
         }
 469   
 
 470  5368
         if (elementName.equals("read-attribute"))
 471   
         {
 472  2520
             enterReadAttribute(elementName);
 473  2520
             return;
 474   
         }
 475   
 
 476  2848
         if (elementName.equals("read-content"))
 477   
         {
 478  867
             enterReadContent(elementName);
 479  867
             return;
 480   
         }
 481   
 
 482  1981
         if (elementName.equals("set-module"))
 483   
         {
 484  10
             enterSetModule(elementName);
 485  10
             return;
 486   
         }
 487   
 
 488  1971
         if (elementName.equals("set-property"))
 489   
         {
 490  1641
             enterSetProperty(elementName);
 491  1641
             return;
 492   
         }
 493   
 
 494  330
         if (elementName.equals("push-attribute"))
 495   
         {
 496  316
             enterPushAttribute(elementName);
 497  316
             return;
 498   
         }
 499   
 
 500  14
         if (elementName.equals("set-parent"))
 501   
         {
 502  12
             enterSetParent(elementName);
 503  12
             return;
 504   
         }
 505   
 
 506  2
         if (elementName.equals("custom"))
 507   
         {
 508  2
             enterCustom(elementName);
 509   
 
 510  1
             return;
 511   
         }
 512   
 
 513  0
         unexpectedElement(elementName);
 514   
     }
 515   
 
 516  1156
     private void beginSchema(String elementName)
 517   
     {
 518  1156
         if (elementName.equals("element"))
 519   
         {
 520  1156
             SchemaImpl schema = (SchemaImpl) peekObject();
 521   
 
 522  1156
             schema.addElementModel(enterElement(elementName));
 523  1155
             return;
 524   
         }
 525   
 
 526  0
         unexpectedElement(elementName);
 527   
     }
 528   
 
 529  1857
     private void beginServicePoint(String elementName)
 530   
     {
 531  1857
         if (elementName.equals("parameters-schema"))
 532   
         {
 533  108
             enterParametersSchema(elementName);
 534  108
             return;
 535   
         }
 536   
 
 537   
         // <service-point> allows an super-set of <implementation>.
 538   
 
 539  1749
         beginImplementation(elementName);
 540   
     }
 541   
 
 542   
     /**
 543   
      * begin outermost element, expect "module".
 544   
      */
 545  241
     private void beginStart(String elementName)
 546   
     {
 547  241
         if (!elementName.equals("module"))
 548  0
             throw new ApplicationRuntimeException(ParseMessages.notModule(
 549   
                     elementName,
 550   
                     getLocation()), getLocation(), null);
 551   
 
 552  241
         ModuleDescriptor md = new ModuleDescriptor(_resolver, _errorHandler);
 553   
 
 554  241
         push(elementName, md, STATE_MODULE);
 555   
 
 556  241
         checkAttributes();
 557   
 
 558  241
         md.setModuleId(getValidatedAttribute("id", MODULE_ID_PATTERN, "module-id-format"));
 559  241
         md.setVersion(getValidatedAttribute("version", VERSION_PATTERN, "version-format"));
 560   
 
 561   
         // And, this is what we ultimately return from the parse.
 562   
 
 563  241
         _moduleDescriptor = md;
 564   
     }
 565   
 
 566  30173
     protected void push(String elementName, Object object, int state)
 567   
     {
 568  30173
         if (object instanceof AnnotationHolder)
 569  15072
             super.push(elementName, object, state, false);
 570   
         else
 571  15101
             super.push(elementName, object, state, true);
 572   
     }
 573   
 
 574  4274
     private ElementImpl buildLWDomElement(String elementName)
 575   
     {
 576  4274
         ElementImpl result = new ElementImpl();
 577  4274
         result.setElementName(elementName);
 578   
 
 579  4274
         Iterator i = _attributes.entrySet().iterator();
 580  4274
         while (i.hasNext())
 581   
         {
 582  7334
             Map.Entry entry = (Map.Entry) i.next();
 583   
 
 584  7334
             String name = (String) entry.getKey();
 585  7334
             String value = (String) entry.getValue();
 586   
 
 587  7334
             Attribute a = new AttributeImpl(name, value);
 588   
 
 589  7334
             result.addAttribute(a);
 590   
         }
 591   
 
 592  4274
         return result;
 593   
     }
 594   
 
 595  26613
     private void checkAttributes()
 596   
     {
 597  26613
         checkAttributes(peekElementName());
 598   
     }
 599   
 
 600   
     /**
 601   
      * Checks that only known attributes are specified. Checks that all required attribute are
 602   
      * specified.
 603   
      */
 604  27251
     private void checkAttributes(String elementName)
 605   
     {
 606  27251
         Iterator i = _attributes.keySet().iterator();
 607   
 
 608  27251
         ElementParseInfo epi = (ElementParseInfo) _elementParseInfo.get(elementName);
 609   
 
 610   
         // A few elements have no attributes at all.
 611   
 
 612  27251
         if (epi == null)
 613   
         {
 614  221
             epi = new ElementParseInfo();
 615  221
             _elementParseInfo.put(elementName, epi);
 616   
         }
 617   
 
 618   
         // First, check that each attribute is in the set of expected attributes.
 619   
 
 620  27251
         while (i.hasNext())
 621   
         {
 622  41075
             String name = (String) i.next();
 623   
 
 624  41075
             if (!epi.isKnown(name))
 625  1
                 _errorHandler.error(
 626   
                         LOG,
 627   
                         ParseMessages.unknownAttribute(name, getElementPath()),
 628   
                         getLocation(),
 629   
                         null);
 630   
         }
 631   
 
 632   
         // Now check that all required attributes have been specified.
 633   
 
 634  27251
         i = epi.getRequiredNames();
 635  27251
         while (i.hasNext())
 636   
         {
 637  32461
             String name = (String) i.next();
 638   
 
 639  32461
             if (!_attributes.containsKey(name))
 640  1
                 throw new ApplicationRuntimeException(ParseMessages.requiredAttribute(
 641   
                         name,
 642   
                         getElementPath(),
 643   
                         getLocation()));
 644   
         }
 645   
 
 646   
     }
 647   
 
 648  34436
     public void end(String elementName)
 649   
     {
 650  34436
         switch (getState())
 651   
         {
 652   
             case STATE_LWDOM:
 653   
 
 654  4274
                 endLWDom();
 655  4274
                 break;
 656   
 
 657   
             case STATE_CONVERSION:
 658   
 
 659  437
                 endConversion();
 660  437
                 break;
 661   
 
 662   
             case STATE_SCHEMA:
 663   
 
 664  1033
                 endSchema();
 665  1033
                 break;
 666   
 
 667   
             default:
 668   
 
 669  28692
                 String content = peekContent();
 670   
 
 671  28692
                 if (content != null && (peekObject() instanceof AnnotationHolder))
 672  13714
                     ((AnnotationHolder) peekObject()).setAnnotation(content);
 673   
 
 674  28692
                 break;
 675   
         }
 676   
 
 677   
         // Pop the top item off the stack.
 678   
 
 679  34436
         pop();
 680   
     }
 681   
 
 682  1033
     private void endSchema()
 683   
     {
 684  1033
         SchemaImpl schema = (SchemaImpl) peekObject();
 685   
 
 686  1033
         try
 687   
         {
 688  1033
             schema.validateKeyAttributes();
 689   
         }
 690   
         catch (ApplicationRuntimeException e)
 691   
         {
 692  1
             _errorHandler.error(LOG, ParseMessages.invalidElementKeyAttribute(schema.getId(), e), e
 693   
                     .getLocation(), e);
 694   
         }
 695   
     }
 696   
 
 697  437
     private void endConversion()
 698   
     {
 699  437
         ConversionDescriptor cd = (ConversionDescriptor) peekObject();
 700   
 
 701  437
         cd.addRulesForModel();
 702   
     }
 703   
 
 704  4274
     private void endLWDom()
 705   
     {
 706  4274
         ElementImpl element = (ElementImpl) peekObject();
 707  4274
         element.setContent(peekContent());
 708   
     }
 709   
 
 710  4245
     private void enterAttribute(String elementName)
 711   
     {
 712  4245
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 713   
 
 714  4245
         AttributeModelImpl attributeModel = new AttributeModelImpl();
 715   
 
 716  4245
         push(elementName, attributeModel, STATE_NO_CONTENT);
 717   
 
 718  4245
         checkAttributes();
 719   
 
 720  4245
         attributeModel.setName(getAttribute("name"));
 721  4245
         attributeModel.setRequired(getBooleanAttribute("required", false));
 722  4245
         attributeModel.setUnique(getBooleanAttribute("unique", false));
 723  4245
         attributeModel.setTranslator(getAttribute("translator", "smart"));
 724   
 
 725  4245
         elementModel.addAttributeModel(attributeModel);
 726   
     }
 727   
 
 728  916
     private void enterConfigurationPoint(String elementName)
 729   
     {
 730  916
         ModuleDescriptor md = (ModuleDescriptor) peekObject();
 731   
 
 732  916
         ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
 733   
 
 734  916
         push(elementName, cpd, STATE_CONFIGURATION_POINT);
 735   
 
 736  916
         checkAttributes();
 737   
 
 738  916
         cpd.setId(getValidatedAttribute("id", ID_PATTERN, "id-format"));
 739   
 
 740  916
         Occurances count = (Occurances) getEnumAttribute("occurs", OCCURS_MAP);
 741   
 
 742  916
         if (count != null)
 743  24
             cpd.setCount(count);
 744   
 
 745  916
         Visibility visibility = (Visibility) getEnumAttribute("visibility", VISIBILITY_MAP);
 746   
 
 747  916
         if (visibility != null)
 748  2
             cpd.setVisibility(visibility);
 749   
 
 750  916
         cpd.setContributionsSchemaId(getAttribute("schema-id"));
 751   
 
 752  916
         md.addConfigurationPoint(cpd);
 753   
     }
 754   
 
 755  608
     private void enterContribution(String elementName)
 756   
     {
 757  608
         ModuleDescriptor md = (ModuleDescriptor) peekObject();
 758   
 
 759  608
         ContributionDescriptor cd = new ContributionDescriptor();
 760   
 
 761  608
         push(elementName, cd, STATE_CONTRIBUTION);
 762   
 
 763  608
         checkAttributes();
 764   
 
 765  608
         cd.setConfigurationId(getAttribute("configuration-id"));
 766  608
         cd.setConditionalExpression(getAttribute("if"));
 767   
 
 768  608
         md.addContribution(cd);
 769   
     }
 770   
 
 771  437
     private void enterConversion(String elementName)
 772   
     {
 773  437
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 774   
 
 775  437
         ConversionDescriptor cd = new ConversionDescriptor(_errorHandler, elementModel);
 776   
 
 777  437
         push(elementName, cd, STATE_CONVERSION);
 778   
 
 779  437
         checkAttributes();
 780   
 
 781  437
         cd.setClassName(getAttribute("class"));
 782   
 
 783  437
         String methodName = getAttribute("parent-method");
 784   
 
 785  437
         if (methodName != null)
 786  1
             cd.setParentMethodName(methodName);
 787   
 
 788  437
         elementModel.addRule(cd);
 789   
     }
 790   
 
 791  793
     private void enterCreateInstance(String elementName)
 792   
     {
 793  793
         AbstractServiceDescriptor sd = (AbstractServiceDescriptor) peekObject();
 794  793
         CreateInstanceDescriptor cid = new CreateInstanceDescriptor();
 795   
 
 796  793
         push(elementName, cid, STATE_CREATE_INSTANCE);
 797   
 
 798  793
         checkAttributes();
 799   
 
 800  793
         cid.setInstanceClassName(getAttribute("class"));
 801   
 
 802  793
         String model = getAttribute("model", DEFAULT_SERVICE_MODEL);
 803   
 
 804  793
         cid.setServiceModel(model);
 805   
 
 806  793
         sd.setInstanceBuilder(cid);
 807   
 
 808   
     }
 809   
 
 810  3228
     private void enterCreateObject(String elementName)
 811   
     {
 812  3228
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 813  3228
         CreateObjectRule rule = new CreateObjectRule();
 814  3228
         push(elementName, rule, STATE_NO_CONTENT);
 815   
 
 816  3228
         checkAttributes();
 817   
 
 818  3228
         rule.setClassName(getAttribute("class"));
 819   
 
 820  3228
         elementModel.addRule(rule);
 821   
     }
 822   
 
 823  2
     private void enterCustom(String elementName)
 824   
     {
 825  2
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 826   
 
 827   
         // Don't know what it is going to be, yet.
 828   
 
 829  2
         push(elementName, null, STATE_NO_CONTENT);
 830   
 
 831  2
         checkAttributes();
 832   
 
 833  2
         String ruleClassName = getAttribute("class");
 834   
 
 835  2
         Rule rule = getCustomRule(ruleClassName);
 836   
 
 837  1
         elementModel.addRule(rule);
 838   
     }
 839   
 
 840   
     /**
 841   
      * Pushes STATE_ELEMENT onto the stack and creates and returns the {@link ElementModelImpl}it
 842   
      * creates.
 843   
      */
 844  3372
     private ElementModel enterElement(String elementName)
 845   
     {
 846  3372
         ElementModelImpl result = new ElementModelImpl();
 847   
 
 848  3372
         push(elementName, result, STATE_ELEMENT);
 849   
 
 850  3372
         checkAttributes();
 851   
 
 852  3371
         result.setElementName(getAttribute("name"));
 853  3371
         result.setKeyAttribute(getAttribute("key-attribute"));
 854  3371
         result.setContentTranslator(getAttribute("content-translator"));
 855   
 
 856  3371
         return result;
 857   
     }
 858   
 
 859  638
     private void enterEmbeddedConfigurationPointSchema(String elementName)
 860   
     {
 861  638
         ConfigurationPointDescriptor cpd = (ConfigurationPointDescriptor) peekObject();
 862   
 
 863  638
         SchemaImpl schema = new SchemaImpl();
 864   
 
 865  638
         push(elementName, schema, STATE_SCHEMA);
 866   
 
 867  638
         if (cpd.getContributionsSchemaId() != null)
 868   
         {
 869  2
             cpd.setContributionsSchemaId(null);
 870  2
             cpd.setContributionsSchema(schema);
 871  2
             _errorHandler.error(LOG, ParseMessages.multipleContributionsSchemas(cpd.getId(), schema
 872   
                     .getLocation()), schema.getLocation(), null);
 873   
         }
 874   
         else
 875  636
             cpd.setContributionsSchema(schema);
 876   
 
 877  638
         checkAttributes("schema{embedded}");
 878   
     }
 879   
 
 880  108
     private void enterParametersSchema(String elementName)
 881   
     {
 882  108
         ServicePointDescriptor spd = (ServicePointDescriptor) peekObject();
 883  108
         SchemaImpl schema = new SchemaImpl();
 884   
 
 885  108
         push(elementName, schema, STATE_SCHEMA);
 886   
 
 887  108
         checkAttributes();
 888   
 
 889  108
         if (spd.getParametersSchemaId() != null)
 890   
         {
 891  2
             spd.setParametersSchemaId(null);
 892  2
             spd.setParametersSchema(schema);
 893  2
             _errorHandler.error(LOG, ParseMessages.multipleParametersSchemas(spd.getId(), schema
 894   
                     .getLocation()), schema.getLocation(), null);
 895   
         }
 896   
         else
 897  106
             spd.setParametersSchema(schema);
 898   
     }
 899   
 
 900  16
     private void enterImplementation(String elementName)
 901   
     {
 902  16
         ModuleDescriptor md = (ModuleDescriptor) peekObject();
 903   
 
 904  16
         ImplementationDescriptor id = new ImplementationDescriptor();
 905   
 
 906  16
         push(elementName, id, STATE_IMPLEMENTATION);
 907   
 
 908  16
         checkAttributes();
 909   
 
 910  16
         id.setServiceId(getAttribute("service-id"));
 911  16
         id.setConditionalExpression(getAttribute("if"));
 912   
 
 913  16
         md.addImplementation(id);
 914   
     }
 915   
 
 916  66
     private void enterInterceptor(String elementName)
 917   
     {
 918  66
         AbstractServiceDescriptor sd = (AbstractServiceDescriptor) peekObject();
 919  66
         InterceptorDescriptor id = new InterceptorDescriptor();
 920   
 
 921  66
         push(elementName, id, STATE_COLLECT_SERVICE_PARAMETERS);
 922   
 
 923  66
         checkAttributes();
 924   
 
 925  66
         id.setFactoryServiceId(getAttribute("service-id"));
 926   
 
 927  66
         id.setBefore(getAttribute("before"));
 928  66
         id.setAfter(getAttribute("after"));
 929   
 
 930  66
         sd.addInterceptor(id);
 931   
 
 932   
     }
 933   
 
 934  908
     private void enterInvokeFactory(String elementName)
 935   
     {
 936  908
         AbstractServiceDescriptor sd = (AbstractServiceDescriptor) peekObject();
 937  908
         InvokeFactoryDescriptor ifd = new InvokeFactoryDescriptor();
 938   
 
 939  908
         push(elementName, ifd, STATE_COLLECT_SERVICE_PARAMETERS);
 940   
 
 941  908
         checkAttributes();
 942   
 
 943  908
         ifd.setFactoryServiceId(getAttribute("service-id", "hivemind.BuilderFactory"));
 944   
 
 945  908
         String model = getAttribute("model", DEFAULT_SERVICE_MODEL);
 946   
 
 947  908
         ifd.setServiceModel(model);
 948   
 
 949   
         // TODO: Check if instanceBuilder already set
 950   
 
 951  908
         sd.setInstanceBuilder(ifd);
 952   
 
 953   
     }
 954   
 
 955  3542
     private void enterInvokeParent(String elementName)
 956   
     {
 957  3542
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 958  3542
         InvokeParentRule rule = new InvokeParentRule();
 959   
 
 960  3542
         push(elementName, rule, STATE_NO_CONTENT);
 961   
 
 962  3542
         checkAttributes();
 963   
 
 964  3542
         rule.setMethodName(getAttribute("method"));
 965   
 
 966  3542
         if (_attributes.containsKey("depth"))
 967  2826
             rule.setDepth(getIntAttribute("depth"));
 968   
 
 969  3542
         elementModel.addRule(rule);
 970   
     }
 971   
 
 972  2520
     private void enterReadAttribute(String elementName)
 973   
     {
 974  2520
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 975  2520
         ReadAttributeRule rule = new ReadAttributeRule();
 976   
 
 977  2520
         push(elementName, rule, STATE_NO_CONTENT);
 978   
 
 979  2520
         checkAttributes();
 980   
 
 981  2520
         rule.setPropertyName(getAttribute("property"));
 982  2520
         rule.setAttributeName(getAttribute("attribute"));
 983  2520
         rule.setSkipIfNull(getBooleanAttribute("skip-if-null", true));
 984  2520
         rule.setTranslator(getAttribute("translator"));
 985   
 
 986  2520
         elementModel.addRule(rule);
 987   
     }
 988   
 
 989  867
     private void enterReadContent(String elementName)
 990   
     {
 991  867
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 992  867
         ReadContentRule rule = new ReadContentRule();
 993   
 
 994  867
         push(elementName, rule, STATE_NO_CONTENT);
 995   
 
 996  867
         checkAttributes();
 997   
 
 998  867
         rule.setPropertyName(getAttribute("property"));
 999   
 
 1000  867
         elementModel.addRule(rule);
 1001   
     }
 1002   
 
 1003  2922
     private void enterRules(String elementName)
 1004   
     {
 1005  2922
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 1006   
 
 1007  2922
         push(elementName, elementModel, STATE_RULES);
 1008   
 
 1009   
     }
 1010   
 
 1011  290
     private void enterSchema(String elementName)
 1012   
     {
 1013  290
         SchemaImpl schema = new SchemaImpl();
 1014   
 
 1015  290
         schema.setModuleId(_moduleDescriptor.getModuleId());
 1016   
 
 1017  290
         push(elementName, schema, STATE_SCHEMA);
 1018   
 
 1019  290
         checkAttributes();
 1020   
 
 1021  290
         String id = getValidatedAttribute("id", ID_PATTERN, "id-format");
 1022   
 
 1023  290
         schema.setId(id);
 1024   
 
 1025  290
         Visibility visibility = (Visibility) getEnumAttribute("visibility", VISIBILITY_MAP);
 1026   
 
 1027  290
         if (visibility != null)
 1028  1
             schema.setVisibility(visibility);
 1029   
 
 1030  290
         _moduleDescriptor.addSchema(schema);
 1031   
     }
 1032   
 
 1033  1716
     private void enterServicePoint(String elementName)
 1034   
     {
 1035  1716
         ModuleDescriptor md = (ModuleDescriptor) peekObject();
 1036   
 
 1037  1716
         ServicePointDescriptor spd = new ServicePointDescriptor();
 1038   
 
 1039  1716
         push(elementName, spd, STATE_SERVICE_POINT);
 1040   
 
 1041  1716
         checkAttributes();
 1042   
 
 1043  1716
         spd.setId(getValidatedAttribute("id", ID_PATTERN, "id-format"));
 1044  1716
         spd.setInterfaceClassName(getAttribute("interface"));
 1045   
 
 1046  1716
         spd.setParametersSchemaId(getAttribute("parameters-schema-id"));
 1047   
 
 1048  1716
         Occurances count = (Occurances) getEnumAttribute("parameters-occurs", OCCURS_MAP);
 1049   
 
 1050  1716
         if (count != null)
 1051  0
             spd.setParametersCount(count);
 1052   
 
 1053  1716
         Visibility visibility = (Visibility) getEnumAttribute("visibility", VISIBILITY_MAP);
 1054   
 
 1055  1716
         if (visibility != null)
 1056  716
             spd.setVisibility(visibility);
 1057   
 
 1058  1716
         md.addServicePoint(spd);
 1059   
     }
 1060   
 
 1061  10
     private void enterSetModule(String elementName)
 1062   
     {
 1063  10
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 1064  10
         SetModuleRule rule = new SetModuleRule();
 1065   
 
 1066  10
         push(elementName, rule, STATE_NO_CONTENT);
 1067   
 
 1068  10
         checkAttributes();
 1069   
 
 1070  10
         rule.setPropertyName(getAttribute("property"));
 1071   
 
 1072  10
         elementModel.addRule(rule);
 1073   
     }
 1074   
 
 1075  12
     private void enterSetParent(String elementName)
 1076   
     {
 1077  12
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 1078  12
         SetParentRule rule = new SetParentRule();
 1079   
 
 1080  12
         push(elementName, rule, STATE_NO_CONTENT);
 1081   
 
 1082  12
         checkAttributes();
 1083   
 
 1084  12
         rule.setPropertyName(getAttribute("property"));
 1085   
 
 1086  12
         elementModel.addRule(rule);
 1087   
     }
 1088   
 
 1089  1641
     private void enterSetProperty(String elementName)
 1090   
     {
 1091  1641
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 1092   
 
 1093  1641
         SetPropertyRule rule = new SetPropertyRule();
 1094   
 
 1095  1641
         push(elementName, rule, STATE_NO_CONTENT);
 1096   
 
 1097  1641
         checkAttributes();
 1098   
 
 1099  1641
         rule.setPropertyName(getAttribute("property"));
 1100  1641
         rule.setValue(getAttribute("value"));
 1101   
 
 1102  1641
         elementModel.addRule(rule);
 1103   
     }
 1104   
 
 1105  316
     private void enterPushAttribute(String elementName)
 1106   
     {
 1107  316
         ElementModelImpl elementModel = (ElementModelImpl) peekObject();
 1108   
 
 1109  316
         PushAttributeRule rule = new PushAttributeRule();
 1110   
 
 1111  316
         push(elementName, rule, STATE_NO_CONTENT);
 1112   
 
 1113  316
         checkAttributes();
 1114   
 
 1115  316
         rule.setAttributeName(getAttribute("attribute"));
 1116   
 
 1117  316
         elementModel.addRule(rule);
 1118   
     }
 1119   
 
 1120  3
     private void enterSubModule(String elementName)
 1121   
     {
 1122  3
         ModuleDescriptor md = (ModuleDescriptor) peekObject();
 1123   
 
 1124  3
         SubModuleDescriptor smd = new SubModuleDescriptor();
 1125   
 
 1126  3
         push(elementName, smd, STATE_NO_CONTENT);
 1127   
 
 1128  3
         checkAttributes();
 1129   
 
 1130  3
         Resource descriptor = getResource().getRelativeResource(getAttribute("descriptor"));
 1131   
 
 1132  3
         smd.setDescriptor(descriptor);
 1133   
 
 1134  3
         md.addSubModule(smd);
 1135   
     }
 1136   
 
 1137  10
     private void enterDependency(String elementName)
 1138   
     {
 1139  10
         ModuleDescriptor md = (ModuleDescriptor) peekObject();
 1140   
 
 1141  10
         DependencyDescriptor dd = new DependencyDescriptor();
 1142   
 
 1143  10
         push(elementName, dd, STATE_NO_CONTENT);
 1144   
 
 1145  10
         checkAttributes();
 1146   
 
 1147  10
         dd.setModuleId(getAttribute("module-id"));
 1148  10
         dd.setVersion(getAttribute("version"));
 1149   
 
 1150  10
         md.addDependency(dd);
 1151   
     }
 1152   
 
 1153  64947
     private String getAttribute(String name)
 1154   
     {
 1155  64947
         return (String) _attributes.get(name);
 1156   
     }
 1157   
 
 1158  6854
     private String getAttribute(String name, String defaultValue)
 1159   
     {
 1160  6854
         String result = (String) _attributes.get(name);
 1161   
 
 1162  6854
         if (result == null)
 1163  5291
             result = defaultValue;
 1164   
 
 1165  6854
         return result;
 1166   
     }
 1167   
 
 1168  3404
     private String getValidatedAttribute(String name, String pattern, String formatKey)
 1169   
     {
 1170  3404
         String result = getAttribute(name);
 1171   
 
 1172  3404
         if (!validateFormat(result, pattern))
 1173  3
             _errorHandler.error(LOG, ParseMessages.invalidAttributeFormat(
 1174   
                     name,
 1175   
                     result,
 1176   
                     getElementPath(),
 1177   
                     formatKey), getLocation(), null);
 1178   
 
 1179  3404
         return result;
 1180   
     }
 1181   
 
 1182  3404
     private boolean validateFormat(String input, String pattern)
 1183   
     {
 1184  3404
         if (_compiler == null)
 1185   
         {
 1186  228
             _compiler = new Perl5Compiler();
 1187  228
             _matcher = new Perl5Matcher();
 1188  228
             _compiledPatterns = new HashMap();
 1189   
         }
 1190   
 
 1191  3404
         Pattern compiled = (Pattern) _compiledPatterns.get(pattern);
 1192  3404
         if (compiled == null)
 1193   
         {
 1194   
 
 1195  677
             try
 1196   
             {
 1197  677
                 compiled = _compiler.compile(pattern);
 1198   
             }
 1199   
             catch (MalformedPatternException ex)
 1200   
             {
 1201  0
                 throw new ApplicationRuntimeException(ex);
 1202   
             }
 1203   
 
 1204  677
             _compiledPatterns.put(pattern, compiled);
 1205   
         }
 1206   
 
 1207  3404
         return _matcher.matches(input, compiled);
 1208   
     }
 1209   
 
 1210  11010
     private boolean getBooleanAttribute(String name, boolean defaultValue)
 1211   
     {
 1212  11010
         String value = getAttribute(name);
 1213   
 
 1214  11010
         if (value == null)
 1215  8087
             return defaultValue;
 1216   
 
 1217  2923
         if (value.equals("true"))
 1218  2499
             return true;
 1219   
 
 1220  424
         if (value.equals("false"))
 1221  424
             return false;
 1222   
 
 1223  0
         _errorHandler.error(
 1224   
                 LOG,
 1225   
                 ParseMessages.booleanAttribute(value, name, getElementPath()),
 1226   
                 getLocation(),
 1227   
                 null);
 1228   
 
 1229  0
         return defaultValue;
 1230   
     }
 1231   
 
 1232  2
     private Rule getCustomRule(String ruleClassName)
 1233   
     {
 1234  2
         Rule result = (Rule) _ruleMap.get(ruleClassName);
 1235   
 
 1236  2
         if (result == null)
 1237   
         {
 1238  2
             result = instantiateRule(ruleClassName);
 1239   
 
 1240  1
             _ruleMap.put(ruleClassName, result);
 1241   
         }
 1242   
 
 1243  1
         return result;
 1244   
     }
 1245   
 
 1246   
     /**
 1247   
      * Gets the value for the attribute and uses the Map to translate it to an object value. Returns
 1248   
      * the object value if succesfully translated. Returns null if unsuccesful. If a value is
 1249   
      * provided that isn't a key of the map, and error is logged and null is returned.
 1250   
      */
 1251  5554
     private Object getEnumAttribute(String name, Map translations)
 1252   
     {
 1253  5554
         String value = getAttribute(name);
 1254   
 
 1255  5554
         if (value == null)
 1256  4811
             return null;
 1257   
 
 1258  743
         Object result = translations.get(value);
 1259   
 
 1260  743
         if (result == null)
 1261  0
             _errorHandler.error(LOG, ParseMessages.invalidAttributeValue(
 1262   
                     value,
 1263   
                     name,
 1264   
                     getElementPath()), getLocation(), null);
 1265   
 
 1266  743
         return result;
 1267   
     }
 1268   
 
 1269  2826
     private int getIntAttribute(String name)
 1270   
     {
 1271  2826
         String value = getAttribute(name);
 1272   
 
 1273  2826
         try
 1274   
         {
 1275  2826
             return Integer.parseInt(value);
 1276   
         }
 1277   
         catch (NumberFormatException ex)
 1278   
         {
 1279  0
             _errorHandler.error(LOG, ParseMessages.invalidNumericValue(
 1280   
                     value,
 1281   
                     name,
 1282   
                     getElementPath()), getLocation(), ex);
 1283   
 
 1284  0
             return 0;
 1285   
         }
 1286   
     }
 1287   
 
 1288  228
     private void initializeFromProperties(Properties p)
 1289   
     {
 1290  228
         Enumeration e = p.propertyNames();
 1291   
 
 1292  228
         while (e.hasMoreElements())
 1293   
         {
 1294  11856
             String key = (String) e.nextElement();
 1295  11856
             String value = p.getProperty(key);
 1296   
 
 1297  11856
             initializeFromProperty(key, value);
 1298   
         }
 1299   
     }
 1300   
 
 1301   
     /**
 1302   
      * Invoked from the constructor to read the properties file that defines certain aspects of the
 1303   
      * operation of the parser.
 1304   
      */
 1305  228
     private void initializeFromPropertiesFile()
 1306   
     {
 1307  228
         Properties p = new Properties();
 1308   
 
 1309  228
         try
 1310   
         {
 1311   
 
 1312  228
             InputStream propertiesIn = getClass()
 1313   
                     .getResourceAsStream("DescriptorParser.properties");
 1314  228
             InputStream bufferedIn = new BufferedInputStream(propertiesIn);
 1315   
 
 1316  228
             p.load(bufferedIn);
 1317   
 
 1318  228
             bufferedIn.close();
 1319   
         }
 1320   
         catch (IOException ex)
 1321   
         {
 1322  0
             _errorHandler.error(LOG, ParseMessages.unableToInitialize(ex), null, ex);
 1323   
         }
 1324   
 
 1325  228
         initializeFromProperties(p);
 1326   
     }
 1327   
 
 1328  11856
     private void initializeFromProperty(String key, String value)
 1329   
     {
 1330  11856
         if (key.startsWith("required."))
 1331   
         {
 1332  11856
             initializeRequired(key, value);
 1333  11856
             return;
 1334   
         }
 1335   
 
 1336   
     }
 1337   
 
 1338  11856
     private void initializeRequired(String key, String value)
 1339   
     {
 1340  11856
         boolean required = value.equals("true");
 1341   
 
 1342  11856
         int lastdotx = key.lastIndexOf('.');
 1343   
 
 1344  11856
         String elementName = key.substring(9, lastdotx);
 1345  11856
         String attributeName = key.substring(lastdotx + 1);
 1346   
 
 1347  11856
         ElementParseInfo epi = (ElementParseInfo) _elementParseInfo.get(elementName);
 1348   
 
 1349  11856
         if (epi == null)
 1350   
         {
 1351  5472
             epi = new ElementParseInfo();
 1352  5472
             _elementParseInfo.put(elementName, epi);
 1353   
         }
 1354   
 
 1355  11856
         epi.addAttribute(attributeName, required);
 1356   
     }
 1357   
 
 1358  2
     private Rule instantiateRule(String ruleClassName)
 1359   
     {
 1360  2
         try
 1361   
         {
 1362  2
             Class ruleClass = _resolver.findClass(ruleClassName);
 1363   
 
 1364  1
             return (Rule) ruleClass.newInstance();
 1365   
         }
 1366   
         catch (Exception ex)
 1367   
         {
 1368  1
             throw new ApplicationRuntimeException(ParseMessages.badRuleClass(
 1369   
                     ruleClassName,
 1370   
                     getLocation(),
 1371   
                     ex), getLocation(), ex);
 1372   
         }
 1373   
     }
 1374   
 
 1375   
     /** @since 1.1 */
 1376  241
     public void initialize(Resource resource, ClassResolver resolver)
 1377   
     {
 1378  241
         initializeParser(resource, STATE_START);
 1379   
 
 1380  241
         _resolver = resolver;
 1381   
     }
 1382   
 
 1383   
     /** @since 1.1 */
 1384  238
     public ModuleDescriptor getModuleDescriptor()
 1385   
     {
 1386  238
         return _moduleDescriptor;
 1387   
     }
 1388   
 
 1389   
     /** @since 1.1 */
 1390  0
     public void reset()
 1391   
     {
 1392  0
         super.resetParser();
 1393   
 
 1394  0
         _moduleDescriptor = null;
 1395  0
         _attributes.clear();
 1396  0
         _resolver = null;
 1397   
     }
 1398   
 }