View Javadoc
1   /**
2    * Copyright (C) 2014-2016 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;
18  
19  import javax.annotation.Nonnull;
20  import javax.annotation.Nullable;
21  
22  import org.oclc.purl.dsdl.svrl.SchematronOutputType;
23  import org.w3c.dom.Node;
24  
25  import com.helger.commons.annotation.ReturnsMutableCopy;
26  import com.helger.commons.collection.ext.ICommonsList;
27  import com.helger.commons.state.EValidity;
28  import com.helger.schematron.CSchematron;
29  import com.helger.schematron.pure.binding.IPSQueryBinding;
30  import com.helger.schematron.pure.model.PSPattern;
31  import com.helger.schematron.pure.model.PSPhase;
32  import com.helger.schematron.pure.model.PSSchema;
33  import com.helger.schematron.pure.validation.IPSValidationHandler;
34  import com.helger.schematron.pure.validation.SchematronValidationException;
35  import com.helger.xml.namespace.MapBasedNamespaceContext;
36  
37  /**
38   * Base interface for a bound schema. A bound schema is a {@link PSSchema} with
39   * a specific
40   *
41   * @author Philip Helger
42   */
43  public interface IPSBoundSchema
44  {
45    /**
46     * @return The query binding that was used to create this bound schema.
47     */
48    @Nonnull
49    IPSQueryBinding getQueryBinding ();
50  
51    /**
52     * @return The original schema used to bind. Never <code>null</code>.
53     */
54    @Nonnull
55    PSSchema getOriginalSchema ();
56  
57    /**
58     * @return The namespace context as defined by the namespaces in the original
59     *         schema. Never <code>null</code>.
60     */
61    @Nonnull
62    MapBasedNamespaceContext getNamespaceContext ();
63  
64    /**
65     * @return Get the phase ID used. If none was specified, the schema
66     *         defaultPhase is used. If this is not present, than all patterns are
67     *         used and ID of the phase is {@link CSchematron#PHASE_ALL}.
68     */
69    @Nonnull
70    String getPhaseID ();
71  
72    /**
73     * @return The phase object to be evaluated. May be <code>null</code> if no
74     *         specific phase is to be validated!
75     */
76    @Nullable
77    PSPhase getPhase ();
78  
79    /**
80     * @return <code>true</code> if a special phase was specified,
81     *         <code>false</code> if not.
82     */
83    boolean isPhaseSpecified ();
84  
85    /**
86     * @return A list of all patterns to be validated. If a phase was selected,
87     *         only the patterns matching the selected phase are contained. Never
88     *         <code>null</code>.
89     */
90    @Nonnull
91    @ReturnsMutableCopy
92    ICommonsList <PSPattern> getAllRelevantPatterns ();
93  
94    /**
95     * Get the validation context to be used. As rules can be stated as "element"
96     * they are not necessarily present on root level. For XPath this may e.g. be
97     * resolved by prepending "//" so that all elements are resolved correctly.
98     *
99     * @param sRuleContext
100    *        The original rule context. May not be <code>null</code>.
101    * @return The real validation context to use.
102    */
103   @Nonnull
104   String getValidationContext (@Nonnull String sRuleContext);
105 
106   /**
107    * The generic validation method. It validates the passed XML node to this
108    * bound schema.
109    *
110    * @param aNode
111    *        The node to be validated. May not be <code>null</code>.
112    * @param aHandler
113    *        The validation handler that receives the callback informations. May
114    *        not be <code>null</code>.
115    * @throws SchematronValidationException
116    *         In case a validation exception occurs
117    */
118   void validate (@Nonnull Node aNode, @Nonnull IPSValidationHandler aHandler) throws SchematronValidationException;
119 
120   /**
121    * Special validation that breaks on the first error. This is a specialized
122    * call of {@link #validate(Node, IPSValidationHandler)}.
123    *
124    * @param aNode
125    *        The XML node to be validated. May not be <code>null</code>.
126    * @return {@link EValidity#VALID} if the document is valid,
127    *         {@link EValidity#INVALID} if it is invalid.
128    * @throws SchematronValidationException
129    *         In case a validation exception occurs
130    */
131   @Nonnull
132   EValidity validatePartially (@Nonnull Node aNode) throws SchematronValidationException;
133 
134   /**
135    * Special validation that creates an SVRL document. This is a specialized
136    * call of {@link #validate(Node, IPSValidationHandler)}.
137    *
138    * @param aNode
139    *        The XML node to be validated. May not be <code>null</code>.
140    * @return The SVRL domain object.
141    * @throws SchematronValidationException
142    *         In case a validation exception occurs
143    */
144   @Nonnull
145   SchematronOutputType validateComplete (@Nonnull Node aNode) throws SchematronValidationException;
146 }