com.ihr.xbrl.om.formula

## Class XBRLFormula

- java.lang.Object
- - com.ihr.xbrl.om.XMLFragment
  - - com.ihr.xbrl.om.exLinks.XLinkElement
    - - com.ihr.xbrl.om.exLinks.XBRLPointerOfARelationship
      - - com.ihr.xbrl.om.exLinks.XBRLResource
        - - com.ihr.xbrl.om.formula.XBRLFormulaResource
          - - com.ihr.xbrl.om.formula.XBRLVariableSetResource
            - - com.ihr.xbrl.om.formula.XBRLFormula

- All Implemented Interfaces:
    HasAdditionalEqualityForReassignation, XBRLRelationshipPoint, HasFormulaProcessor, HasUncoveredAspectValueResolver, StaticCheck, XBRLVariablesHolder, XMLEvaluationContextProvider, Thinable, XBRLValidation, XBRLValueKey, XMLHasParent, java.lang.Cloneable, javax.xml.namespace.NamespaceContext

      public class XBRLFormula
      extends XBRLVariableSetResource
      implements XMLEvaluationContextProvider, StaticCheck

  The Class XBRLFormula.
  Author:
    Ignacio

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.ihr.xbrl.om.XBRLValidation

      `XBRLValidation.Direction`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static javax.xml.namespace.QName` | `decimals` The Constant decimals.
    `static net.sf.saxon.s9api.QName` | `dimensionExplicit` The Constant dimensionExplicit.
    `static net.sf.saxon.s9api.QName` | `dimensionTyped` The Constant dimensionTyped.
    `static net.sf.saxon.s9api.QName` | `entityIdentifier` The Constant entityIdentifier.
    `static javax.xml.namespace.QName` | `formula` The Constant formula.
    `static net.sf.saxon.s9api.QName` | `formulaConcept` The Constant formulaConcept.
    `static org.apache.log4j.Logger` | `log` The log.
    `static net.sf.saxon.s9api.QName` | `occEmpty` The Constant occEmpty.
    `static net.sf.saxon.s9api.QName` | `occFragments` The Constant occFragments.
    `static net.sf.saxon.s9api.QName` | `occXPath` The Constant occXPath.
    `static net.sf.saxon.s9api.QName` | `period` The Constant period.
    `static javax.xml.namespace.QName` | `precision` The Constant precision.
    `static javax.xml.namespace.QName` | `source` The Constant source.
    `static javax.xml.namespace.QName` | `uncovered` The Constant uncovered.
    `static net.sf.saxon.s9api.QName` | `unit` The Constant unit.
    `static javax.xml.namespace.QName` | `value` The Constant value.

    - ### Fields inherited from class com.ihr.xbrl.om.formula.XBRLVariableSetResource

      `aspectModel, implicitFiltering`

    - ### Fields inherited from class com.ihr.xbrl.om.exLinks.XBRLResource

      `nullResource`

    - ### Fields inherited from class com.ihr.xbrl.om.exLinks.XLinkElement

      `actuate, ACTUATE, ARC, arcrole, ARCROLE, ETITLE, EXTENDED, from, FROM, href, HREF, label, LABEL, LOCATOR, RESOURCE, role, ROLE, show, SHOW, SIMPLE, title, TITLE, to, TO, TYPE`

    - ### Fields inherited from class com.ihr.xbrl.om.XMLFragment

      `CONCEPT_LABEL, CONCEPT_QNAME, EASY_TO_READ, ELEMENT_LABEL, EMPTYRELATIONSHIPSITERATORINSTANCE, EMPTYXMLFRAGMENTITERATORINSTANCE, FACT_CONCEPT_DATATYPE, FACT_CONCEPT_LABEL, FACT_QNAME, HIDE_COMMON_ACCURACY, idQName, NO_POSITION, OrderComparator, OrderComparator2, PERIOD_TYPE, PERIOD_VALUE, SHORT_TEXT, SOURCE_DOCUMENT, XPATH, XPOINTER`

    - ### Fields inherited from interface com.ihr.xbrl.om.formula.XBRLVariablesHolder

      `MODEL_DIMENSIONAL, MODEL_NON_DIMENSIONAL`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XBRLFormula(XBRLFormulaProcessor proc, XBRLExtendedLink parent, net.sf.saxon.s9api.XdmNode resNode)` Creates a new formula from a node in an extended link.
    `XBRLFormula(XBRLFormulaProcessor proc, XBRLResource other)` Formulas are normally created by copying another existing resource.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `XBRLInstance` | `evaluateFormula(XBRLInstance doc, XBRLInstance instance)` Evaluates a formula and returns an instance document containing the formula output.
    `int` | `getAllAspectsIndicated()` Access to a bit map of flags for the aspects indicated on this formula.
    `XMLFragment` | `getEvaluationContext()` Gets the evaluation context.
    `java.lang.String` | `getExpression()` Access to the xpath expression inside this formula resource.
    `TraceVariablesBind` | `getTraceVariablesBind()` During the formula evaluation, this variable may be set to store a trace of variable bindings.
    `boolean` | `isTheSourceOf(XBRLFact fact)` This method returns true if this formula is the source of a fact generation.
    `void` | `setExecutionTarget(ExecutionTargetType type)` Set or changes the target execution for this formula.
    `void` | `staticCheck()` Resources that has static checking implements this interface.
    `void` | `staticCheckAspectRules()` Called during the compilation of the resource.

    - ### Methods inherited from class com.ihr.xbrl.om.formula.XBRLVariableSetResource

      `allDimensions, bindCycle, bindLastEvaluatedVariableValues, bindParameters, bindVariableValue, checkCyclicDependencies, compileFilters, compileFormulaExpression, declareVariables, getAspectModel, getBindableVariableNames, getFilters, getNumberOfVariables, getOptimizer, getUncoveredAspectsSet, getUncoveredAspectValue, getVariableResource, getVariableResourceUses, getVariableUse, getVariableValue, getVariableValue, getXFIImplicitFilterOptimizer, isCovered, isImplicitFilter`

    - ### Methods inherited from class com.ihr.xbrl.om.formula.XBRLFormulaResource

      `getProcessor`

    - ### Methods inherited from class com.ihr.xbrl.om.exLinks.XBRLResource

      `addChild, clear, equals, generateLocatorToNode, generateNode, getAttributes, getDTSBase, getFriendlyName, getFriendlyName, getParent, getResourceIdentifier, getRoleType, getType, getValidationReport, getValueKey, hashCode, invalidate, invalidate, isComplexType, isOnValidation, isSimpleType, setComplexType, setDTSBase, setId, setParent, setRole, setRoleType, setSimpleType, setValue, validate`

    - ### Methods inherited from class com.ihr.xbrl.om.exLinks.XLinkElement

      `getActuate, getArcrole, getFromTxt, getHRef, getLabel, getRole, getShow, getStaticLabel, getSType, getTitle, getToTxt, isRequiredAttribute, isValidAttribute, setActuate, setArcrole, setFrom, setHRef, setLabel, setShow, setSType, setTitle, setTo`

    - ### Methods inherited from class com.ihr.xbrl.om.XMLFragment

      `addAttribute, addFromRelationship, addNamespace, addNamespace, addToRelationship, addXMLChild, changeBase, checkBase, clone, clone, delAttribute, delAttribute, equalXdmValues, evaluateBoolean, evaluateList, evaluateNode, evaluateNumber, evaluateString, generateId, generateNodeNamespacesAndAttributes, generateNodeValue, generatePrefix, getAllAttributes, getAttribute, getAttributeBooleanValue, getAttributeQNameValue, getAttributes, getAttributeStringValue, getAttributeValue, getBase, getBase, getBaseURI, getBooleanValue, getChild, getContainer, getContainerDocumentURI, getDeclaredNamespaces, getDocument, getElements, getElementsHashCode, getFragment, getFromRelationships, getFromRelationships, getFromRelationships, getFromRelationships, getFromRelationships, getGenericLabelText, getId, getLang, getNamespaceURI, getNodeName, getNumberOfAttributes, getNumberOfElements, getNumberOfFromRelationships, getNumberOfToRelationships, getOrGenerateId, getPrefix, getPrefixes, getQNameValue, getRelationshipsBases, getRelationshipsChain, getRelationshipTypes, getStaticContext, getStaticNamespace, getStringValue, getToolTipText, getToRelationships, getToRelationships, getToRelationships, getToRelationships, getToRelationships, getValue, getXPathExecutable, getXPathNamespaceContext, getXPathToNode, getXPathToRoot, getXPointerElementScheme, getXPointerElementScheme, getXPointerShorthandScheme, getXPointerToNode, isDead, isNamespaceDefined, isXdmDocumentAttached, objEquals, objHashCode, qNameToString, removeAttribute, removeChild, removeChild, removeFromRelationship, removeToRelationship, removeXMLChild, resetElements, resetHash, resolve_equal2, resolveHRef, resolveHRef, s_equal2, s_equal2, s_equal2, setAttributes, setBase, setDocument, setDocumentAndReload, setElements, setLang, setNamespaceContext, setNamespaces, setNode, setNodeName, setParent, setRegenerateNodeIfnotFound, setValue, setVariablesDefined, size, thin, toString, valueEquals, xEqual`

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

      `getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface com.ihr.xbrl.om.formula.HasFormulaProcessor

      `getProcessor`

    - ### Methods inherited from interface com.ihr.xbrl.om.exLinks.XBRLRelationshipPoint

      `addFromRelationship, addToRelationship, getFromRelationships, getToRelationships, removeFromRelationship, removeToRelationship`

- - ### Field Detail

    - #### log

          public static org.apache.log4j.Logger log

      The log.

    - #### value

          public static final javax.xml.namespace.QName value

      The Constant value.

    - #### source

          public static final javax.xml.namespace.QName source

      The Constant source.

    - #### decimals

          public static final javax.xml.namespace.QName decimals

      The Constant decimals.

    - #### precision

          public static final javax.xml.namespace.QName precision

      The Constant precision.

    - #### formula

          public static final javax.xml.namespace.QName formula

      The Constant formula.

    - #### uncovered

          public static final javax.xml.namespace.QName uncovered

      The Constant uncovered.

    - #### formulaConcept

          public static final net.sf.saxon.s9api.QName formulaConcept

      The Constant formulaConcept.

    - #### entityIdentifier

          public static final net.sf.saxon.s9api.QName entityIdentifier

      The Constant entityIdentifier.

    - #### period

          public static final net.sf.saxon.s9api.QName period

      The Constant period.

    - #### unit

          public static final net.sf.saxon.s9api.QName unit

      The Constant unit.

    - #### occEmpty

          public static final net.sf.saxon.s9api.QName occEmpty

      The Constant occEmpty.

    - #### occFragments

          public static final net.sf.saxon.s9api.QName occFragments

      The Constant occFragments.

    - #### occXPath

          public static final net.sf.saxon.s9api.QName occXPath

      The Constant occXPath.

    - #### dimensionExplicit

          public static final net.sf.saxon.s9api.QName dimensionExplicit

      The Constant dimensionExplicit.

    - #### dimensionTyped

          public static final net.sf.saxon.s9api.QName dimensionTyped

      The Constant dimensionTyped.

  - ### Constructor Detail

    - #### XBRLFormula

          public XBRLFormula(XBRLFormulaProcessor proc,
                     XBRLExtendedLink parent,
                     net.sf.saxon.s9api.XdmNode resNode)
                      throws XFValidationException

      Creates a new formula from a node in an extended link.
      Parameters:
        `proc` - the proc
        `parent` - XBRLExtendedLink parent of this new formula
        `resNode` - XdmNode saxon node defined in saxon s9api
      Throws:
        `XFValidationException` - the XF validation exception

    - #### XBRLFormula

          public XBRLFormula(XBRLFormulaProcessor proc,
                     XBRLResource other)
                      throws XFValidationException

      Formulas are normally created by copying another existing resource.
      Parameters:
        `proc` - the proc
        `other` - XBRLResource
      Throws:
        `XFValidationException` - the XF validation exception

  - ### Method Detail

    - #### setExecutionTarget

          public void setExecutionTarget(ExecutionTargetType type)

      Set or changes the target execution for this formula. See the documentation of the ExecutionTargetType documentation. This method is used internally by the API.
      Parameters:
        `type` - the new execution target

    - #### staticCheck

          public void staticCheck()
                           throws XFValidationException

      Description copied from interface: `StaticCheck`
      Resources that has static checking implements this interface. During resource compilation time the static check is evaluated.

      In case of errors, the staticCheck method raises XFValidationException

      Specified by:
        `staticCheck` in interface `StaticCheck`
      Throws:
        `XFValidationException` - if static errors occurs

    - #### staticCheckAspectRules

          public void staticCheckAspectRules()
                                      throws XFValidationException

      Called during the compilation of the resource. This method implement the rules about checking the aspects for the formula and raise static errors if no aspect is found.

      This method updates the internal variable allAspectsIndicated

      Throws:
        `XFValidationException` - the XF validation exception
      See Also:
        2.1.2 Aspect rules

    - #### getExpression

          public java.lang.String getExpression()

      Access to the xpath expression inside this formula resource.
      Returns:
        the expression

    - #### getAllAspectsIndicated

          public int getAllAspectsIndicated()

      Access to a bit map of flags for the aspects indicated on this formula. Aspects should be used later for the implicit filters.
      Returns:
        the all aspects indicated

    - #### getTraceVariablesBind

          public TraceVariablesBind getTraceVariablesBind()

      During the formula evaluation, this variable may be set to store a trace of variable bindings. A new execution of this formula will reset this value
      Returns:
        the trace variables bind

    - #### evaluateFormula

          public XBRLInstance evaluateFormula(XBRLInstance doc,
                                     XBRLInstance instance)
                                       throws XFValidationException

      Evaluates a formula and returns an instance document containing the formula output.

      Current version of the formula specification indicates that the formula output is just a single fact. In the opinion of the author of this code, this is just one sign of bad quality specifications.

      Nothing would stop the formula authors to produce a sequence of facts as a result of a formula evaluation because the formula output can be easily enclosed inside a single instance document (containing one or a set of facts). This API has been designed this way in order to allow that possible feature in the future while provides the required functionality in the current document wording.

      Parameters:
        `doc` - the "target instance" as defined in the formula specification. This is the instance from which variable values will be obtained
        `instance` - instance document to add generated facts to. This method will write values to instance. can be null, in this case, a new instance document is created inside this function.
      Returns:
        the instance parameter.
      Throws:
        `XFValidationException` - if errors occurs during the formula execution
      See Also:
        3 The processing model for formulae

    - #### getEvaluationContext

          public XMLFragment getEvaluationContext()

      Description copied from interface: `XMLEvaluationContextProvider`
      Gets the evaluation context.
      Specified by:
        `getEvaluationContext` in interface `XMLEvaluationContextProvider`
      Returns:
        the evaluation context

    - #### isTheSourceOf

          public boolean isTheSourceOf(XBRLFact fact)

      This method returns true if this formula is the source of a fact generation. Note this method works only if the Execution Target is set for XBRL Consistency Checks
      Parameters:
        `fact` - the fact
      Returns:
        true or false