View Javadoc
1   /**
2    * Copyright (C) 2014-2017 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.collection.ext.ICommonsList;
26  import com.helger.commons.collection.ext.ICommonsMap;
27  import com.helger.commons.string.ToStringGenerator;
28  import com.helger.schematron.pure.model.PSAssertReport;
29  
30  /**
31   * This class represents a single XPath-bound assert- or report-element.
32   *
33   * @author Philip Helger
34   */
35  @Immutable
36  public class PSXPathBoundAssertReport
37  {
38    private final PSAssertReport m_aAssertReport;
39    private final String m_sTestExpression;
40    private final XPathExpression m_aBoundTestExpression;
41    private final ICommonsList <PSXPathBoundElement> m_aBoundContent;
42    private final ICommonsMap <String, PSXPathBoundDiagnostic> m_aBoundDiagnostics;
43  
44    public PSXPathBoundAssertReport (@Nonnull final PSAssertReport aAssertReport,
45                                     @Nonnull final String sTestExpression,
46                                     @Nonnull final XPathExpression aBoundTestExpression,
47                                     @Nonnull final ICommonsList <PSXPathBoundElement> aBoundContent,
48                                     @Nonnull final ICommonsMap <String, PSXPathBoundDiagnostic> aBoundDiagnostics)
49    {
50      ValueEnforcer.notNull (aAssertReport, "AssertReport");
51      ValueEnforcer.notNull (sTestExpression, "TestExpression");
52      ValueEnforcer.notNull (aBoundTestExpression, "BoundTestExpression");
53      ValueEnforcer.notNull (aBoundContent, "BoundContent");
54      ValueEnforcer.notNull (aBoundDiagnostics, "BoundDiagnostics");
55      m_aAssertReport = aAssertReport;
56      m_sTestExpression = sTestExpression;
57      m_aBoundTestExpression = aBoundTestExpression;
58      m_aBoundContent = aBoundContent;
59      m_aBoundDiagnostics = aBoundDiagnostics;
60    }
61  
62    /**
63     * @return The original assert/report element. Never <code>null</code>.
64     */
65    @Nonnull
66    public PSAssertReport getAssertReport ()
67    {
68      return m_aAssertReport;
69    }
70  
71    /**
72     * @return The source XPath expression that was compiled. Never
73     *         <code>null</code>.
74     */
75    @Nonnull
76    public String getTestExpression ()
77    {
78      return m_sTestExpression;
79    }
80  
81    /**
82     * @return The pre-compiled XPath expression. Never <code>null</code>.
83     */
84    @Nonnull
85    public XPathExpression getBoundTestExpression ()
86    {
87      return m_aBoundTestExpression;
88    }
89  
90    /**
91     * @return All contained bound elements. It has the same amount of elements as
92     *         the source assert/report.
93     */
94    @Nonnull
95    public ICommonsList <PSXPathBoundElement> getAllBoundContentElements ()
96    {
97      return m_aBoundContent.getClone ();
98    }
99  
100   /**
101    * Get the bound diagnostic matching the passed ID
102    *
103    * @param sID
104    *        The ID to be resolved. May be <code>null</code>.
105    * @return <code>null</code> if the passed ID could not be resolved.
106    */
107   @Nullable
108   public PSXPathBoundDiagnostic getBoundDiagnosticOfID (@Nullable final String sID)
109   {
110     return m_aBoundDiagnostics.get (sID);
111   }
112 
113   @Override
114   public String toString ()
115   {
116     return new ToStringGenerator (this).append ("assertReport", m_aAssertReport)
117                                        .append ("testExpression", m_sTestExpression)
118                                        .append ("boundTestExpression", m_aBoundTestExpression)
119                                        .append ("boundContent", m_aBoundContent)
120                                        .append ("boundDiagnostics", m_aBoundDiagnostics)
121                                        .getToString ();
122   }
123 }