Skip to content

Commit

Permalink
Added support for function namespaces.
Browse files Browse the repository at this point in the history
Some Javadoc improvements.
Refactored code generation, moving code generation methods into a dedicated class, DefaultMetaschemaClassFactory.java.
  • Loading branch information
david-waltermire committed Aug 3, 2023
1 parent ec8320f commit c3d6207
Show file tree
Hide file tree
Showing 82 changed files with 2,471 additions and 1,764 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Provides a complete, abstract implementation of a generalized feature.
* Feature implementations can extend this class the implement configuration
* sets for a given purpose.
*
* @param <V>
* the feature value type
*/
public abstract class AbstractConfigurationFeature<V> implements IConfigurationFeature<V> {
@NonNull
private final Class<V> valueClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Provides immutable access to configuration state.
* Provides a basic configuration management implementation that allows mutable
* access to configuration state.
*
* @param <T>
* the type of managed features
*/
@SuppressWarnings({ "PMD.ReplaceVectorWithList", "PMD.DoNotUseThreads" })
public class DefaultConfiguration<T extends IConfigurationFeature<?>>
implements IMutableConfiguration<T> {
@NonNull
Expand All @@ -49,7 +49,6 @@ public class DefaultConfiguration<T extends IConfigurationFeature<?>>
* Create a new configuration.
*
*/
@SuppressWarnings("PMD.CloseResource")
public DefaultConfiguration() {
this.featureValues = new HashMap<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,41 @@
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* The base feature interface for getting the configuration of processors and parsers in this
* library. This provides an immutable view of the current configuration.
* The base interface for getting the configuration of processors and parsers in
* this library. This provides an immutable view of the current configuration.
*
* @param <T>
* the type of the feature set
*/
@SuppressWarnings({ "PMD.DoNotUseThreads", "PMD.ReplaceVectorWithList" })
public interface IConfiguration<T extends IConfigurationFeature<?>> {
/**
* Determines if a specific serialization/deserialization feature is enabled.
* Determines if a specific feature is enabled.
*
* @param feature
* the feature to check for
* @return {@code true} if the feature is enabled, or {@code false} otherwise
* @throws UnsupportedOperationException
* if the feature is not a boolean valued feature
* @see IConfigurationFeature#getValueClass()
*/
boolean isFeatureEnabled(@NonNull T feature);

/**
* Get the configuration value of the provided {@code feature}.
*
* @param <V>
* the value type
* @param feature
* the requested feature
* @return the value of the feature
*/
@NonNull
<V> V get(@NonNull T feature);

/**
* Get the mapping of feature to feature value.
* Get the mapping of each feature mapped to its value.
*
* @return the mapping.
* @return the mapping
*/
@NonNull
Map<T, Object> getFeatureValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@

import edu.umd.cs.findbugs.annotations.NonNull;

@SuppressWarnings({ "PMD.DoNotUseThreads", "PMD.ReplaceVectorWithList" })
/**
* This interface provides methods for retrieving and updating the configuration
* of processors and parsers in this library. This provides a mutable view of
* the current configuration.
*
* @param <T>
* the type of the feature set
*/
public interface IMutableConfiguration<T extends IConfigurationFeature<?>>
extends IConfiguration<T> {
/**
Expand All @@ -37,6 +44,9 @@ public interface IMutableConfiguration<T extends IConfigurationFeature<?>>
* @param feature
* the feature to turn on
* @return the updated configuration
* @throws UnsupportedOperationException
* if the feature is not a boolean valued feature
* @see IConfigurationFeature#getValueClass()
*/
@NonNull
default IMutableConfiguration<T> enableFeature(@NonNull T feature) {
Expand All @@ -49,6 +59,9 @@ default IMutableConfiguration<T> enableFeature(@NonNull T feature) {
* @param feature
* the feature to turn off
* @return the updated configuration
* @throws UnsupportedOperationException
* if the feature is not a boolean valued feature
* @see IConfigurationFeature#getValueClass()
*/
@NonNull
default IMutableConfiguration<T> disableFeature(@NonNull T feature) {
Expand All @@ -65,6 +78,19 @@ default IMutableConfiguration<T> disableFeature(@NonNull T feature) {
@NonNull
IMutableConfiguration<T> applyConfiguration(@NonNull IConfiguration<T> other);

/**
* Set the value of the provided {@code feature} to the provided value.
*
* @param feature
* the feature to set
* @param value
* the value to set
* @return the updated configuration
* @throws UnsupportedOperationException
* if the provided feature value is not assignment compatible with the
* features value type
* @see IConfigurationFeature#getValueClass()
*/
@NonNull
IMutableConfiguration<T> set(@NonNull T feature, @NonNull Object value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/

/**
* Provides support for generalized configuration based on a set of
* {@link gov.nist.secauto.metaschema.core.configuration.IConfigurationFeature}
* values.
*/

package gov.nist.secauto.metaschema.core.configuration;
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,22 @@ protected IDocumentLoader getProxiedDocumentLoader() {
public class ContextEntityResolver implements EntityResolver {

/**
* Provides an {@link InputSource} for the provided {@code systemId} after attempting to resolve
* this system identifier.
* Provides an {@link InputSource} for the provided {@code systemId} after
* attempting to resolve this system identifier.
* <p>
* This implementation of an {@link EntityResolver} will perform the following operations in order:
* This implementation of an {@link EntityResolver} will perform the following
* operations in order:
* <ol>
* <li>Resolves the {@code systemId} against the base URI provided by the
* {@link StaticContext#getBaseUri()} method, if this method returns a non-{@code null} result, to
* get a localized resource identifier.</li>
* {@link StaticContext#getBaseUri()} method, if this method returns a
* non-{@code null} result, to get a localized resource identifier.</li>
* <li>It will then delegate to the EntityResolver provided by the
* {@link IDocumentLoader#getEntityResolver()} method, if the result is not-{@code null}, to get the
* {@link InputSource}.</li>
* <li>If no InputSource is provided by the previous step, then an InputSource will be created from
* the URI resolved in the first step, if possible.
* <li>If an InputSource is still not provided, then an InputSource will be created from the
* provided {@code systemId}.
* {@link IDocumentLoader#getEntityResolver()} method, if the result is
* not-{@code null}, to get the {@link InputSource}.</li>
* <li>If no InputSource is provided by the previous step, then an InputSource
* will be created from the URI resolved in the first step, if possible.
* <li>If an InputSource is still not provided, then an InputSource will be
* created from the provided {@code systemId}.
* </ol>
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Portions of this software was developed by employees of the National Institute
* of Standards and Technology (NIST), an agency of the Federal Government and is
* being made available as a public service. Pursuant to title 17 United States
* Code Section 105, works of NIST employees are not subject to copyright
* protection in the United States. This software may be subject to foreign
* copyright. Permission in the United States and in foreign countries, to the
* extent that NIST may hold copyright, to use, copy, modify, create derivative
* works, and distribute this software and its documentation without fee is hereby
* granted on a non-exclusive basis, provided that this notice and disclaimer
* of warranty appears in all copies.
*
* THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
* EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
* THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
* INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
* SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
* SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
* INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
* OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
* CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
* PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/

package gov.nist.secauto.metaschema.core.metapath;

import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import java.net.URI;

import javax.xml.XMLConstants;

import edu.umd.cs.findbugs.annotations.NonNull;

public final class MetapathConstants {
@NonNull
public static final URI NS_METAPATH = ObjectUtils.requireNonNull(
URI.create("http://csrc.nist.gov/ns/metaschema/metapath"));
@NonNull
public static final URI NS_XML_SCHEMA = ObjectUtils.requireNonNull(
URI.create(XMLConstants.W3C_XML_SCHEMA_NS_URI));
@NonNull
public static final URI NS_XPATH_FUNCTIONS = ObjectUtils.requireNonNull(
URI.create("http://www.w3.org/2005/xpath-functions"));
@NonNull
public static final URI NS_XPATH_FUNCTIONS_MATH = ObjectUtils.requireNonNull(
URI.create("http://www.w3.org/2005/xpath-functions/math"));

@NonNull
public static final String PREFIX_METAPATH = "mp";
@NonNull
public static final String PREFIX_XML_SCHEMA = "xs";
@NonNull
public static final String PREFIX_XPATH_FUNCTIONS = "mp";
@NonNull
public static final String PREFIX_XPATH_FUNCTIONS_MATH = "math";

private MetapathConstants() {
// disable construction
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,17 @@ public String toString() {
}

/**
* Evaluate this Metapath expression without a specific focus. The required result type will be
* determined by the {@code resultType} argument.
* Evaluate this Metapath expression without a specific focus. The required
* result type will be determined by the {@code resultType} argument.
*
* @param <T>
* the expected result type
* @param resultType
* the type of result to produce
* @return the converted result
* @throws TypeMetapathException
* if the provided sequence is incompatible with the requested result type
* if the provided sequence is incompatible with the requested result
* type
* @throws MetapathException
* if an error occurred during evaluation
* @see #toResultType(ISequence, ResultType)
Expand All @@ -182,8 +183,9 @@ public <T> T evaluateAs(@NonNull ResultType resultType) {
}

/**
* Evaluate this Metapath expression using the provided {@code focus} as the initial evaluation
* context. The required result type will be determined by the {@code resultType} argument.
* Evaluate this Metapath expression using the provided {@code focus} as the
* initial evaluation context. The required result type will be determined by
* the {@code resultType} argument.
*
* @param <T>
* the expected result type
Expand All @@ -193,7 +195,8 @@ public <T> T evaluateAs(@NonNull ResultType resultType) {
* the type of result to produce
* @return the converted result
* @throws TypeMetapathException
* if the provided sequence is incompatible with the requested result type
* if the provided sequence is incompatible with the requested result
* type
* @throws MetapathException
* if an error occurred during evaluation
* @see #toResultType(ISequence, ResultType)
Expand All @@ -207,8 +210,9 @@ public <T> T evaluateAs(
}

/**
* Evaluate this Metapath expression using the provided {@code focus} as the initial evaluation
* context. The specific result type will be determined by the {@code resultType} argument.
* Evaluate this Metapath expression using the provided {@code focus} as the
* initial evaluation context. The specific result type will be determined by
* the {@code resultType} argument.
* <p>
* This variant allow for reuse of a provided {@code dynamicContext}.
*
Expand All @@ -222,7 +226,8 @@ public <T> T evaluateAs(
* the dynamic context to use for evaluation
* @return the converted result
* @throws TypeMetapathException
* if the provided sequence is incompatible with the requested result type
* if the provided sequence is incompatible with the requested result
* type
* @throws MetapathException
* if an error occurred during evaluation
* @see #toResultType(ISequence, ResultType)
Expand All @@ -239,8 +244,8 @@ public <T> T evaluateAs(
/**
* Converts the provided {@code sequence} to the requested {@code resultType}.
* <p>
* The {@code resultType} determines the returned result, which is derived from the evaluation
* result sequence, as follows:
* The {@code resultType} determines the returned result, which is derived from
* the evaluation result sequence, as follows:
* <ul>
* <li>BOOLEAN - the effective boolean result is produced using
* {@link FnBoolean#fnBoolean(ISequence)}.</li>
Expand All @@ -259,7 +264,8 @@ public <T> T evaluateAs(
* the type of result to produce
* @return the converted result
* @throws TypeMetapathException
* if the provided sequence is incompatible with the requested result type
* if the provided sequence is incompatible with the requested result
* type
*/
@SuppressWarnings("PMD.NullAssignment") // for readability
@Nullable
Expand Down Expand Up @@ -296,7 +302,8 @@ protected <T> T toResultType(@NonNull ISequence<?> sequence, @NonNull ResultType
*
* @param <T>
* the type of items contained in the resulting sequence
* @return a sequence of Metapath items representing the result of the evaluation
* @return a sequence of Metapath items representing the result of the
* evaluation
* @throws MetapathException
* if an error occurred during evaluation
*/
Expand All @@ -306,27 +313,31 @@ public <T extends IItem> ISequence<T> evaluate() {
}

/**
* Evaluate this Metapath expression using the provided {@code focus} as the initial evaluation
* context.
* Evaluate this Metapath expression using the provided {@code focus} as the
* initial evaluation context.
*
* @param <T>
* the type of items contained in the resulting sequence
* @param focus
* the outer focus of the expression
* @return a sequence of Metapath items representing the result of the evaluation
* @return a sequence of Metapath items representing the result of the
* evaluation
* @throws MetapathException
* if an error occurred during evaluation
*/
@SuppressWarnings("unchecked")
@NonNull
public <T extends IItem> ISequence<T> evaluate(
@Nullable IItem focus) {
return (ISequence<T>) evaluate(focus, new StaticContext().newDynamicContext());
return (ISequence<T>) evaluate(
focus,
StaticContext.builder()
.build().newDynamicContext());
}

/**
* Evaluate this Metapath expression using the provided {@code focus} as the initial evaluation
* context.
* Evaluate this Metapath expression using the provided {@code focus} as the
* initial evaluation context.
* <p>
* This variant allow for reuse of a provided {@code dynamicContext}.
*
Expand All @@ -336,7 +347,8 @@ public <T extends IItem> ISequence<T> evaluate(
* the outer focus of the expression
* @param dynamicContext
* the dynamic context to use for evaluation
* @return a sequence of Metapath items representing the result of the evaluation
* @return a sequence of Metapath items representing the result of the
* evaluation
* @throws MetapathException
* if an error occurred during evaluation
*/
Expand Down
Loading

0 comments on commit c3d6207

Please sign in to comment.