View Javadoc
1   /**
2    * Copyright (C) 2014-2018 Philip Helger (www.helger.com)
3    * philip[at]helger[dot]com
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *         http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package com.helger.schematron.pure.bound.xpath;
18  
19  import javax.annotation.Nonnull;
20  import javax.annotation.Nullable;
21  import javax.annotation.concurrent.Immutable;
22  import javax.xml.xpath.XPathExpression;
23  
24  import com.helger.commons.ValueEnforcer;
25  import com.helger.commons.string.ToStringGenerator;
26  import com.helger.schematron.pure.model.IPSElement;
27  
28  /**
29   * This class represents a single XPath-bound text element that is contained
30   * inside an assert- or report-element.
31   *
32   * @author Philip Helger
33   */
34  @Immutable
35  public class PSXPathBoundElement
36  {
37    private final Object m_aElement;
38    private final String m_sExpression;
39    private final XPathExpression m_aBoundExpression;
40  
41    public PSXPathBoundElement (@Nonnull final String sElement)
42    {
43      this (sElement, null, null);
44    }
45  
46    public PSXPathBoundElement (@Nonnull final IPSElement aElement)
47    {
48      this (aElement, null, null);
49    }
50  
51    public PSXPathBoundElement (@Nonnull final Object aElement,
52                                @Nullable final String sExpression,
53                                @Nullable final XPathExpression aBoundExpression)
54    {
55      ValueEnforcer.notNull (aElement, "Element");
56      m_aElement = aElement;
57      m_sExpression = sExpression;
58      m_aBoundExpression = aBoundExpression;
59    }
60  
61    /**
62     * @return {@link String} or {@link IPSElement} objects. May not be
63     *         <code>null</code>.
64     */
65    @Nonnull
66    public Object getElement ()
67    {
68      return m_aElement;
69    }
70  
71    /**
72     * @return The source expression that was compiled to an
73     *         {@link XPathExpression}. It may differ from the XPath expression
74     *         contained in the element because of replaced variables from
75     *         &lt;let&gt; elements. May be <code>null</code> if
76     *         {@link #getExpression()} is <code>null</code>.
77     */
78    @Nullable
79    public String getExpression ()
80    {
81      return m_sExpression;
82    }
83  
84    /**
85     * @return The compiled {@link XPathExpression} - may be <code>null</code>.
86     */
87    @Nullable
88    public XPathExpression getBoundExpression ()
89    {
90      return m_aBoundExpression;
91    }
92  
93    @Override
94    public String toString ()
95    {
96      return new ToStringGenerator (this).append ("element", m_aElement)
97                                         .appendIfNotNull ("expression", m_sExpression)
98                                         .appendIfNotNull ("boundExpression", m_aBoundExpression)
99                                         .getToString ();
100   }
101 }