use of com.helger.schematron.pure.model.PSNS in project ph-schematron by phax.
the class PSPreprocessor method getForcedPreprocessedSchema.
/**
* Convert the passed schema to a pre-processed schema independent if it is
* already minimal or not.
*
* @param aSchema
* The schema to be made minimal. May not be <code>null</code>
* @return A minimal copy of the schema. May be <code>null</code> if the
* original schema is not yet minimal and {@link #isKeepEmptySchema()}
* is set to <code>false</code>.
* @throws SchematronPreprocessException
* In case a preprocessing error occurs
*/
@Nullable
public PSSchema getForcedPreprocessedSchema(@Nonnull final PSSchema aSchema) throws SchematronPreprocessException {
ValueEnforcer.notNull(aSchema, "Schema");
final PreprocessorLookup aLookup = new PreprocessorLookup(aSchema);
final PreprocessorIDPool aIDPool = new PreprocessorIDPool();
final PSSchema ret = new PSSchema(aSchema.getResource());
ret.setID(aIDPool.getUniqueID(aSchema.getID()));
ret.setRich(aSchema.getRichClone());
ret.setSchemaVersion(aSchema.getSchemaVersion());
ret.setDefaultPhase(aSchema.getDefaultPhase());
ret.setQueryBinding(aSchema.getQueryBinding());
if (m_bKeepTitles && aSchema.hasTitle())
ret.setTitle(aSchema.getTitle().getClone());
if (aSchema.hasAnyInclude())
throw new SchematronPreprocessException("Cannot preprocess <schema> with an <include>");
for (final PSNS aNS : aSchema.getAllNSs()) ret.addNS(aNS.getClone());
// start ps are skipped
for (final PSLet aLet : aSchema.getAllLets()) ret.addLet(aLet.getClone());
for (final PSPhase aPhase : aSchema.getAllPhases()) ret.addPhase(_getPreprocessedPhase(aPhase, aIDPool));
for (final PSPattern aPattern : aSchema.getAllPatterns()) {
final PSPattern aMinifiedPattern = _getPreprocessedPattern(aPattern, aLookup, aIDPool);
if (aMinifiedPattern != null) {
// Pattern without rules?
if (aMinifiedPattern.getRuleCount() > 0 || m_bKeepEmptyPatterns)
ret.addPattern(aMinifiedPattern);
}
}
// Schema without patterns?
if (aSchema.getPatternCount() == 0 && !m_bKeepEmptySchema)
return null;
// end ps are skipped
if (m_bKeepDiagnostics && aSchema.hasDiagnostics())
ret.setDiagnostics(_getPreprocessedDiagnostics(aSchema.getDiagnostics()));
ret.addForeignElements(aSchema.getAllForeignElements());
ret.addForeignAttributes(aSchema.getAllForeignAttributes());
return ret;
}
Aggregations