-
Notifications
You must be signed in to change notification settings - Fork 5
Metapath expression evaluator subcommand #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
david-waltermire
merged 2 commits into
metaschema-framework:develop
from
david-waltermire:feature/metapath-expression-command-impl
Sep 10, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/DefaultItemWriter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: none | ||
| * SPDX-License-Identifier: CC0-1.0 | ||
| */ | ||
|
|
||
| package gov.nist.secauto.metaschema.core.metapath.item; | ||
|
|
||
| import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; | ||
| import gov.nist.secauto.metaschema.core.metapath.ISequence; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; | ||
|
|
||
| import java.io.PrintWriter; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
|
||
| /** | ||
| * Produces a textual representation of a Metapath sequence. | ||
| */ | ||
| public class DefaultItemWriter implements IItemWriter { | ||
|
|
||
| @NonNull | ||
| private final PrintWriter writer; | ||
| @NonNull | ||
| private final Visitor visitor = new Visitor(); | ||
|
|
||
| /** | ||
| * Construct a new item writer. | ||
| * | ||
| * @param writer | ||
| * the writer to append text to | ||
| */ | ||
| public DefaultItemWriter(@NonNull PrintWriter writer) { | ||
| this.writer = writer; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeSequence(ISequence<?> sequence) { | ||
| boolean wrap = sequence.size() != 1; | ||
| if (wrap) { | ||
| writer.append('('); | ||
| } | ||
| boolean first = true; | ||
| for (IItem item : sequence) { | ||
|
|
||
| if (first) { | ||
| first = false; | ||
| } else { | ||
| writer.append(','); | ||
| } | ||
|
|
||
| item.accept(visitor); | ||
| } | ||
|
|
||
| if (wrap) { | ||
| writer.append(')'); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void writeArray(IArrayItem<?> array) { | ||
| writer.append('['); | ||
| boolean first = true; | ||
| for (ICollectionValue value : array) { | ||
| assert value != null; | ||
|
|
||
| if (first) { | ||
| first = false; | ||
| } else { | ||
| writer.append(','); | ||
| } | ||
|
|
||
| writeCollectionValue(value); | ||
| } | ||
| writer.append(']'); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeMap(IMapItem<?> map) { | ||
| writer.append("map {"); | ||
| boolean first = true; | ||
| for (ICollectionValue value : map.values()) { | ||
| assert value != null; | ||
|
|
||
| if (first) { | ||
| first = false; | ||
| } else { | ||
| writer.append(','); | ||
| } | ||
|
|
||
| writeCollectionValue(value); | ||
| } | ||
| writer.append('}'); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeNode(INodeItem node) { | ||
| writer.append(node.getBaseUri().toString()); | ||
| writer.append('#'); | ||
| writer.append(node.getMetapath()); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeAtomicValue(IAnyAtomicItem node) { | ||
| writer.append(node.asString()); | ||
| } | ||
|
|
||
| /** | ||
| * Write the provided collection value. | ||
| * | ||
| * @param value | ||
| * the value to write | ||
| */ | ||
| protected void writeCollectionValue(@NonNull ICollectionValue value) { | ||
| if (value instanceof IItem) { | ||
| ((IItem) value).accept(visitor); | ||
| } else if (value instanceof ISequence) { | ||
| writeSequence((ISequence<?>) value); | ||
| } | ||
| } | ||
|
|
||
| private final class Visitor implements IItemVisitor { | ||
|
|
||
| @Override | ||
| public void visit(IArrayItem<?> array) { | ||
| writeArray(array); | ||
| } | ||
|
|
||
| @Override | ||
| public void visit(IMapItem<?> map) { | ||
| writeMap(map); | ||
| } | ||
|
|
||
| @Override | ||
| public void visit(INodeItem node) { | ||
| writeNode(node); | ||
| } | ||
|
|
||
| @Override | ||
| public void visit(IAnyAtomicItem node) { | ||
| writeAtomicValue(node); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemVisitor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: none | ||
| * SPDX-License-Identifier: CC0-1.0 | ||
| */ | ||
|
|
||
| package gov.nist.secauto.metaschema.core.metapath.item; | ||
|
|
||
| import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
|
||
| public interface IItemVisitor { | ||
| /** | ||
| * Visit the array item instance. | ||
| * | ||
| * @param array | ||
| * the instance to visit | ||
| */ | ||
| void visit(@NonNull IArrayItem<?> array); | ||
|
|
||
| /** | ||
| * Visit the map item instance. | ||
| * | ||
| * @param map | ||
| * the instance to visit | ||
| */ | ||
| void visit(@NonNull IMapItem<?> map); | ||
|
|
||
| /** | ||
| * Visit the node item instance. | ||
| * | ||
| * @param node | ||
| * the instance to visit | ||
| */ | ||
| void visit(@NonNull INodeItem node); | ||
|
|
||
| /** | ||
| * Visit the atomic item instance. | ||
| * | ||
| * @param item | ||
| * the instance to visit | ||
| */ | ||
| void visit(@NonNull IAnyAtomicItem item); | ||
| } |
56 changes: 56 additions & 0 deletions
56
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemWriter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: none | ||
| * SPDX-License-Identifier: CC0-1.0 | ||
| */ | ||
|
|
||
| package gov.nist.secauto.metaschema.core.metapath.item; | ||
|
|
||
| import gov.nist.secauto.metaschema.core.metapath.ISequence; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; | ||
| import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
|
||
| public interface IItemWriter { | ||
| /** | ||
| * Write the provided sequence instance. | ||
| * | ||
| * @param sequence | ||
| * the instance to write | ||
| */ | ||
| void writeSequence(@NonNull ISequence<?> sequence); | ||
|
|
||
| /** | ||
| * Write the provided array item instance. | ||
| * | ||
| * @param array | ||
| * the instance to write | ||
| */ | ||
| void writeArray(@NonNull IArrayItem<?> array); | ||
|
|
||
| /** | ||
| * Write the provided map item instance. | ||
| * | ||
| * @param map | ||
| * the instance to write | ||
| */ | ||
| void writeMap(@NonNull IMapItem<?> map); | ||
|
|
||
| /** | ||
| * Write the provided node item instance. | ||
| * | ||
| * @param node | ||
| * the instance to write | ||
| */ | ||
| void writeNode(@NonNull INodeItem node); | ||
|
|
||
| /** | ||
| * Write the provided atomic item instance. | ||
| * | ||
| * @param item | ||
| * the instance to write | ||
| */ | ||
| void writeAtomicValue(@NonNull IAnyAtomicItem item); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.