forked from metaschema-framework/metaschema-java
-
Notifications
You must be signed in to change notification settings - Fork 0
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. Resolves usnistgov/metaschema-java#241. Builds on metaschema-framework#96.
- Loading branch information
1 parent
5472808
commit 6995204
Showing
23 changed files
with
568 additions
and
215 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
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,107 @@ | ||
/* | ||
* 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; | ||
|
||
public class DefaultItemWriter implements IItemWriter { | ||
|
||
@NonNull | ||
private final PrintWriter writer; | ||
@NonNull | ||
private final Visitor visitor = new Visitor(); | ||
|
||
public DefaultItemWriter(@NonNull PrintWriter writer) { | ||
this.writer = writer; | ||
} | ||
|
||
@Override | ||
public void writeSequence(ISequence<?> sequence) { | ||
boolean wrap = sequence.size() > 1; | ||
if (wrap) { | ||
writer.append('('); | ||
} | ||
for (IItem item : sequence) { | ||
item.accept(visitor); | ||
} | ||
|
||
if (wrap) { | ||
writer.append(')'); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeArray(IArrayItem<?> array) { | ||
writer.append('['); | ||
for (ICollectionValue value : array) { | ||
assert value != null; | ||
writeCollectionValue(value); | ||
} | ||
writer.append(']'); | ||
} | ||
|
||
@Override | ||
public void writeMap(IMapItem<?> map) { | ||
writer.append("map {"); | ||
for (ICollectionValue value : map.values()) { | ||
assert value != null; | ||
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()); | ||
} | ||
|
||
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
23 changes: 23 additions & 0 deletions
23
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,23 @@ | ||
/* | ||
* 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 { | ||
void visit(@NonNull IArrayItem<?> array); | ||
|
||
void visit(@NonNull IMapItem<?> map); | ||
|
||
void visit(@NonNull INodeItem node); | ||
|
||
void visit(@NonNull IAnyAtomicItem node); | ||
} |
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
/* | ||
* 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 { | ||
void writeSequence(@NonNull ISequence<?> sequence); | ||
|
||
void writeArray(@NonNull IArrayItem<?> array); | ||
|
||
void writeMap(@NonNull IMapItem<?> map); | ||
|
||
void writeNode(@NonNull INodeItem node); | ||
|
||
void writeAtomicValue(@NonNull IAnyAtomicItem 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
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
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
23 changes: 0 additions & 23 deletions
23
...-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/MetaschemaCommandSupport.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.