View Javadoc
1   /**
2    * Copyright (C) 2014-2015 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 java.util.List;
20  import java.util.Map;
21  
22  import javax.annotation.Nonnull;
23  import javax.annotation.Nullable;
24  import javax.annotation.concurrent.Immutable;
25  import javax.xml.xpath.XPathExpression;
26  
27  import com.helger.commons.ValueEnforcer;
28  import com.helger.commons.collection.CollectionHelper;
29  import com.helger.commons.string.ToStringGenerator;
30  import com.helger.schematron.pure.model.PSAssertReport;
31  
32  /**
33   * This class represents a single XPath-bound assert- or report-element.
34   *
35   * @author Philip Helger
36   */
37  @Immutable
38  public class PSXPathBoundAssertReport
39  {
40    private final PSAssertReport m_aAssertReport;
41    private final String m_sTestExpression;
42    private final XPathExpression m_aBoundTestExpression;
43    private final List <PSXPathBoundElement> m_aBoundContent;
44    private final Map <String, PSXPathBoundDiagnostic> m_aBoundDiagnostics;
45  
46    public PSXPathBoundAssertReport (@Nonnull final PSAssertReport aAssertReport,
47                                     @Nonnull final String sTestExpression,
48                                     @Nonnull final XPathExpression aBoundTestExpression,
49                                     @Nonnull final List <PSXPathBoundElement> aBoundContent,
50                                     @Nonnull final Map <String, PSXPathBoundDiagnostic> aBoundDiagnostics)
51    {
52      ValueEnforcer.notNull (aAssertReport, "AssertReport");
53      ValueEnforcer.notNull (sTestExpression, "TestExpression");
54      ValueEnforcer.notNull (aBoundTestExpression, "BoundTestExpression");
55      ValueEnforcer.notNull (aBoundContent, "BoundContent");
56      ValueEnforcer.notNull (aBoundDiagnostics, "BoundDiagnostics");
57      m_aAssertReport = aAssertReport;
58      m_sTestExpression = sTestExpression;
59      m_aBoundTestExpression = aBoundTestExpression;
60      m_aBoundContent = aBoundContent;
61      m_aBoundDiagnostics = aBoundDiagnostics;
62    }
63  
64    /**
65     * @return The original assert/report element. Never <code>null</code>.
66     */
67    @Nonnull
68    public PSAssertReport getAssertReport ()
69    {
70      return m_aAssertReport;
71    }
72  
73    /**
74     * @return The source XPath expression that was compiled. Never
75     *         <code>null</code>.
76     */
77    @Nonnull
78    public String getTestExpression ()
79    {
80      return m_sTestExpression;
81    }
82  
83    /**
84     * @return The pre-compiled XPath expression. Never <code>null</code>.
85     */
86    @Nonnull
87    public XPathExpression getBoundTestExpression ()
88    {
89      return m_aBoundTestExpression;
90    }
91  
92    /**
93     * @return All contained bound elements. It has the same amount of elements as
94     *         the source assert/report.
95     */
96    @Nonnull
97    public List <PSXPathBoundElement> getAllBoundContentElements ()
98    {
99      return CollectionHelper.newList (m_aBoundContent);
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                                        .toString ();
124   }
125 }