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