net.sourceforge.pmd

## Class RuleSetReferenceId

- java.lang.Object
- - net.sourceforge.pmd.RuleSetReferenceId

-     public class RuleSetReferenceId
      extends Object

  This class is used to parse a RuleSet reference value. Most commonly used for specifying a RuleSet to process, or in a Rule 'ref' attribute value in the RuleSet XML. The RuleSet reference can refer to either an external RuleSet or the current RuleSet when used as a Rule 'ref' attribute value. An individual Rule in the RuleSet can be indicated. For an external RuleSet, referring to the entire RuleSet, the format is ruleSetName, where the RuleSet name is either a resource file path to a RuleSet that ends with `'.xml'`.
, or a simple RuleSet name. A simple RuleSet name, is one which contains no path separators, and either contains a '-' or is entirely numeric release number. A simple name of the form `[language]-[name]` is short for the full RuleSet name `rulesets/[language]/[name].xml`. A numeric release simple name of the form `[release]` is short for the full PMD Release RuleSet name `rulesets/releases/[release].xml`. For an external RuleSet, referring to a single Rule, the format is ruleSetName/ruleName, where the RuleSet name is as described above. A Rule with the ruleName should exist in this external RuleSet. For the current RuleSet, the format is ruleName, where the Rule name is not RuleSet name (i.e. contains no path separators, '-' or '.xml' in it, and is not all numeric). A Rule with the ruleName should exist in the current RuleSet.

Examples
String | RuleSet file name | Rule
--- | --- | ---
rulesets/java/basic.xml | rulesets/java/basic.xml | all
java-basic | rulesets/java/basic.xml | all
50 | rulesets/releases/50.xml | all
rulesets/java/basic.xml/EmptyCatchBlock | rulesets/java/basic.xml | EmptyCatchBlock
EmptyCatchBlock | null | EmptyCatchBlock

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RuleSetReferenceId(String id)` Construct a RuleSetReferenceId for the given single ID string.
    `RuleSetReferenceId(String id, RuleSetReferenceId externalRuleSetReferenceId)` Construct a RuleSetReferenceId for the given single ID string.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `InputStream` | `getInputStream(ClassLoader classLoader)` Try to load the RuleSet resource with the specified ClassLoader.
    `String` | `getRuleName()` Get the Rule name.
    `String` | `getRuleSetFileName()` Get the RuleSet file name.
    `boolean` | `isAllRules()` Is this a reference to all Rules in a RuleSet, or a single Rule?
    `boolean` | `isExternal()` Is this an external RuleSet reference?
    `static List<RuleSetReferenceId>` | `parse(String referenceString)` Parse a String comma separated list of RuleSet reference IDs into a List of RuleReferenceId instances.
    `String` | `toString()` Return the String form of this Rule reference.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### RuleSetReferenceId

          public RuleSetReferenceId(String id)

      Construct a RuleSetReferenceId for the given single ID string.
      Parameters:
        `id` - The id string.
      Throws:
        `IllegalArgumentException` - If the ID contains a comma character.

    - #### RuleSetReferenceId

          public RuleSetReferenceId(String id,
                            RuleSetReferenceId externalRuleSetReferenceId)

      Construct a RuleSetReferenceId for the given single ID string. If an external RuleSetReferenceId is given, the ID must refer to a non-external Rule. The external RuleSetReferenceId will be responsible for producing the InputStream containing the Rule.
      Parameters:
        `id` - The id string.
        `externalRuleSetReferenceId` - A RuleSetReferenceId to associate with this new instance.
      Throws:
        `IllegalArgumentException` - If the ID contains a comma character.
        `IllegalArgumentException` - If external RuleSetReferenceId is not external.
        `IllegalArgumentException` - If the ID is not Rule reference when there is an external RuleSetReferenceId.

  - ### Method Detail

    - #### parse

          public static List<RuleSetReferenceId> parse(String referenceString)

      Parse a String comma separated list of RuleSet reference IDs into a List of RuleReferenceId instances.
      Parameters:
        `referenceString` - A comma separated list of RuleSet reference IDs.
      Returns:
        The corresponding List of RuleSetReferenceId instances.

    - #### isExternal

          public boolean isExternal()

      Is this an external RuleSet reference?
      Returns:
        `true` if this is an external reference, `false` otherwise.

    - #### isAllRules

          public boolean isAllRules()

      Is this a reference to all Rules in a RuleSet, or a single Rule?
      Returns:
        `true` if this is a reference to all Rules, `false` otherwise.

    - #### getRuleSetFileName

          public String getRuleSetFileName()

      Get the RuleSet file name.
      Returns:
        The RuleSet file name if this is an external reference, `null` otherwise.

    - #### getRuleName

          public String getRuleName()

      Get the Rule name.
      Returns:
        The Rule name. The Rule name.

    - #### getInputStream

          public InputStream getInputStream(ClassLoader classLoader)
                                     throws RuleSetNotFoundException

      Try to load the RuleSet resource with the specified ClassLoader. Multiple attempts to get independent InputStream instances may be made, so subclasses must ensure they support this behavior. Delegates to an external RuleSetReferenceId if there is one associated with this instance.
      Parameters:
        `classLoader` - The ClassLoader to use.
      Returns:
        An InputStream to that resource.
      Throws:
        `RuleSetNotFoundException` - if unable to find a resource.

    - #### toString

          public String toString()

      Return the String form of this Rule reference.
      Overrides:
        `toString` in class `Object`
      Returns:
        Return the String form of this Rule reference, which is ruleSetFileName for all Rule external references, ruleSetFileName/ruleName, for a single Rule external references, or ruleName otherwise.

Copyright © 2002-2013 InfoEther. All Rights Reserved.