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