-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed a schema generation bug causing an existing test to fail due to…
… improper handling of JSON keys. Added basic support for arbitrary Metapath command execution, building on #96. Metapath execution allows for evaluating expressions without a module or instance. Resolves usnistgov/metaschema-java#241.
- Loading branch information
1 parent
9861e41
commit 4637af0
Showing
24 changed files
with
698 additions
and
218 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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.