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