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.
Added the ability to dynamically build note item trees to support uni…
…t testing and future parsing use cases. Build a unit test of fn:name using this new functionality.
- Loading branch information
1 parent
2262817
commit c8363b1
Showing
19 changed files
with
959 additions
and
31 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
core/src/main/java/gov/nist/secauto/metaschema/core/mdm/IDMAssemblyNodeItem.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.mdm; | ||
|
||
import gov.nist.secauto.metaschema.core.mdm.impl.IDMModelNodeItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; | ||
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; | ||
import gov.nist.secauto.metaschema.core.model.IAssemblyInstance; | ||
import gov.nist.secauto.metaschema.core.model.IFieldInstance; | ||
import gov.nist.secauto.metaschema.core.model.IResourceLocation; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
/** | ||
* An assembly node item implementation that is backed by a simple Metaschema | ||
* module-based data model. | ||
*/ | ||
public interface IDMAssemblyNodeItem | ||
extends IAssemblyNodeItem, IDMModelNodeItem<IAssemblyDefinition, IAssemblyInstance> { | ||
/** | ||
* Create and add a new field to the underlying data model. | ||
* | ||
* @param instance | ||
* the Metaschema field instance describing the field | ||
* @param resourceLocation | ||
* information about the location of the field within the containing | ||
* resource | ||
* @param value | ||
* the atomic field value | ||
* @return the new field node item | ||
*/ | ||
@NonNull | ||
IDMFieldNodeItem newField( | ||
@NonNull IFieldInstance instance, | ||
@NonNull IResourceLocation resourceLocation, | ||
@NonNull IAnyAtomicItem value); | ||
|
||
/** | ||
* Create and add a new assembly to the underlying data model. | ||
* | ||
* @param instance | ||
* the Metaschema assembly instance describing the assembly | ||
* @param resourceLocation | ||
* information about the location of the assembly within the containing | ||
* resource | ||
* @return the new assembly node item | ||
*/ | ||
@NonNull | ||
IDMAssemblyNodeItem newAssembly( | ||
@NonNull IAssemblyInstance instance, | ||
@NonNull IResourceLocation resourceLocation); | ||
} |
48 changes: 48 additions & 0 deletions
48
core/src/main/java/gov/nist/secauto/metaschema/core/mdm/IDMDocumentNodeItem.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,48 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.core.mdm; | ||
|
||
import gov.nist.secauto.metaschema.core.mdm.impl.DocumentImpl; | ||
import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; | ||
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; | ||
import gov.nist.secauto.metaschema.core.model.IResourceLocation; | ||
|
||
import java.net.URI; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
/** | ||
* A document node item implementation that is backed by a simple Metaschema | ||
* module-based data model. | ||
*/ | ||
public interface IDMDocumentNodeItem | ||
extends IDocumentNodeItem { | ||
@Override | ||
IDMRootAssemblyNodeItem getRootAssemblyNodeItem(); | ||
|
||
/** | ||
* Create a new Metaschema document-based data model. | ||
* | ||
* @param resource | ||
* the base URI of the document resource | ||
* @param resourceLocation | ||
* information about the (intended) location of the document resource | ||
* @param rootAssembly | ||
* the assembly that is at the root of the node tree for this document | ||
* @param rootAssemblyLocation | ||
* information about the (intended) location of the root assembly | ||
* resource | ||
* @return the document node item | ||
*/ | ||
@NonNull | ||
static IDMDocumentNodeItem newInstance( | ||
@NonNull URI resource, | ||
@NonNull IResourceLocation resourceLocation, | ||
@NonNull IAssemblyDefinition rootAssembly, | ||
@NonNull IResourceLocation rootAssemblyLocation) { | ||
return new DocumentImpl(resource, resourceLocation, rootAssembly, rootAssemblyLocation); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
core/src/main/java/gov/nist/secauto/metaschema/core/mdm/IDMFieldNodeItem.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,20 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.core.mdm; | ||
|
||
import gov.nist.secauto.metaschema.core.mdm.impl.IDMModelNodeItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.node.IFieldNodeItem; | ||
import gov.nist.secauto.metaschema.core.model.IFieldDefinition; | ||
import gov.nist.secauto.metaschema.core.model.IFieldInstance; | ||
|
||
/** | ||
* A field node item implementation that is backed by a simple Metaschema | ||
* module-based data model. | ||
*/ | ||
public interface IDMFieldNodeItem | ||
extends IFieldNodeItem, IDMModelNodeItem<IFieldDefinition, IFieldInstance> { | ||
// no additional methods | ||
} |
17 changes: 17 additions & 0 deletions
17
core/src/main/java/gov/nist/secauto/metaschema/core/mdm/IDMRootAssemblyNodeItem.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,17 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.core.mdm; | ||
|
||
import gov.nist.secauto.metaschema.core.metapath.item.node.IRootAssemblyNodeItem; | ||
|
||
/** | ||
* A root assembly node item implementation that is backed by a simple | ||
* Metaschema module-based data model. | ||
*/ | ||
public interface IDMRootAssemblyNodeItem | ||
extends IDMAssemblyNodeItem, IRootAssemblyNodeItem { | ||
// no additional methods | ||
} |
104 changes: 104 additions & 0 deletions
104
core/src/main/java/gov/nist/secauto/metaschema/core/mdm/impl/AbstractDMAssemblyNodeItem.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,104 @@ | ||
|
||
package gov.nist.secauto.metaschema.core.mdm.impl; | ||
|
||
import gov.nist.secauto.metaschema.core.mdm.IDMAssemblyNodeItem; | ||
import gov.nist.secauto.metaschema.core.mdm.IDMFieldNodeItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.node.AbstractNodeItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.node.IFlagNodeItem; | ||
import gov.nist.secauto.metaschema.core.model.IAssemblyInstance; | ||
import gov.nist.secauto.metaschema.core.model.IFieldInstance; | ||
import gov.nist.secauto.metaschema.core.model.IFlagInstance; | ||
import gov.nist.secauto.metaschema.core.model.IResourceLocation; | ||
import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; | ||
import gov.nist.secauto.metaschema.core.util.CollectionUtil; | ||
import gov.nist.secauto.metaschema.core.util.ObjectUtils; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
public abstract class AbstractDMAssemblyNodeItem | ||
extends AbstractNodeItem | ||
implements IDMAssemblyNodeItem { | ||
@NonNull | ||
private final Map<IEnhancedQName, IFlagNodeItem> flags = new ConcurrentHashMap<>(); | ||
@NonNull | ||
private final Map<IEnhancedQName, List<IDMModelNodeItem<?, ?>>> modelItems | ||
= new ConcurrentHashMap<>(); | ||
|
||
protected AbstractDMAssemblyNodeItem() { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public String stringValue() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
protected String getValueSignature() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public Collection<? extends IFlagNodeItem> getFlags() { | ||
return ObjectUtils.notNull(flags.values()); | ||
} | ||
|
||
@Override | ||
public IFlagNodeItem getFlagByName(IEnhancedQName name) { | ||
return flags.get(name); | ||
} | ||
|
||
@Override | ||
public IFlagNodeItem newFlag( | ||
@NonNull IFlagInstance instance, | ||
@NonNull IResourceLocation resourceLocation, | ||
@NonNull IAnyAtomicItem value) { | ||
IFlagNodeItem flag = new FlagImpl(instance, this, resourceLocation, value); | ||
flags.put(instance.getQName(), flag); | ||
return flag; | ||
} | ||
|
||
@Override | ||
public Collection<List<IDMModelNodeItem<?, ?>>> getModelItems() { | ||
return ObjectUtils.notNull(modelItems.values()); | ||
} | ||
|
||
@Override | ||
public List<? extends IDMModelNodeItem<?, ?>> getModelItemsByName(IEnhancedQName name) { | ||
List<? extends IDMModelNodeItem<?, ?>> retval = modelItems.get(name); | ||
return retval == null ? CollectionUtil.emptyList() : retval; | ||
} | ||
|
||
@Override | ||
public IDMFieldNodeItem newField(IFieldInstance instance, IResourceLocation resourceLocation, IAnyAtomicItem value) { | ||
List<IDMModelNodeItem<?, ?>> result = modelItems.computeIfAbsent( | ||
instance.getQName(), | ||
name -> Collections.synchronizedList(new LinkedList<IDMModelNodeItem<?, ?>>())); | ||
IDMFieldNodeItem field = new FieldImpl(instance, this, resourceLocation, value); | ||
result.add(field); | ||
return field; | ||
} | ||
|
||
@Override | ||
public IDMAssemblyNodeItem newAssembly(IAssemblyInstance instance, IResourceLocation resourceLocation) { | ||
List<IDMModelNodeItem<?, ?>> result = modelItems.computeIfAbsent( | ||
instance.getQName(), | ||
name -> Collections.synchronizedList(new LinkedList<IDMModelNodeItem<?, ?>>())); | ||
IDMAssemblyNodeItem assembly = new AssemblyImpl(instance, this, resourceLocation); | ||
result.add(assembly); | ||
return assembly; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
core/src/main/java/gov/nist/secauto/metaschema/core/mdm/impl/AbstractDMInstanceNodeItem.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,45 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.core.mdm.impl; | ||
|
||
import gov.nist.secauto.metaschema.core.metapath.StaticContext; | ||
import gov.nist.secauto.metaschema.core.metapath.item.node.AbstractInstanceNodeItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.node.IModelNodeItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; | ||
import gov.nist.secauto.metaschema.core.model.IDefinition; | ||
import gov.nist.secauto.metaschema.core.model.IModelDefinition; | ||
import gov.nist.secauto.metaschema.core.model.INamedInstance; | ||
import gov.nist.secauto.metaschema.core.model.IResourceLocation; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
public abstract class AbstractDMInstanceNodeItem< | ||
D extends IDefinition, | ||
I extends INamedInstance, | ||
P extends IModelNodeItem<? extends IModelDefinition, ? extends INamedInstance>> | ||
extends AbstractInstanceNodeItem<D, I, P> | ||
implements INodeItem { | ||
@NonNull | ||
private final IResourceLocation resourceLocation; | ||
|
||
protected AbstractDMInstanceNodeItem( | ||
@NonNull I instance, | ||
@NonNull P parent, | ||
@NonNull IResourceLocation resourceLocation) { | ||
super(instance, parent); | ||
this.resourceLocation = resourceLocation; | ||
} | ||
|
||
@Override | ||
public IResourceLocation getLocation() { | ||
return resourceLocation; | ||
} | ||
|
||
@Override | ||
public StaticContext getStaticContext() { | ||
return getParentNodeItem().getStaticContext(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
core/src/main/java/gov/nist/secauto/metaschema/core/mdm/impl/AssemblyImpl.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,70 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.core.mdm.impl; | ||
|
||
import gov.nist.secauto.metaschema.core.mdm.IDMAssemblyNodeItem; | ||
import gov.nist.secauto.metaschema.core.metapath.StaticContext; | ||
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; | ||
import gov.nist.secauto.metaschema.core.model.IAssemblyInstance; | ||
import gov.nist.secauto.metaschema.core.model.IResourceLocation; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
public class AssemblyImpl | ||
extends AbstractDMAssemblyNodeItem { | ||
@NonNull | ||
private final IAssemblyInstance instance; | ||
@NonNull | ||
private final IDMAssemblyNodeItem parent; | ||
@NonNull | ||
private final IResourceLocation resourceLocation; | ||
|
||
public AssemblyImpl( | ||
@NonNull IAssemblyInstance instance, | ||
@NonNull IDMAssemblyNodeItem parent, | ||
@NonNull IResourceLocation resourceLocation) { | ||
this.instance = instance; | ||
this.parent = parent; | ||
this.resourceLocation = resourceLocation; | ||
} | ||
|
||
@Override | ||
public IResourceLocation getLocation() { | ||
return resourceLocation; | ||
} | ||
|
||
@Override | ||
public int getPosition() { | ||
return getParentNodeItem().getModelItemsByName(getQName()).indexOf(this); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public IDMAssemblyNodeItem getParentNodeItem() { | ||
return getParentContentNodeItem(); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public IDMAssemblyNodeItem getParentContentNodeItem() { | ||
return parent; | ||
} | ||
|
||
@Override | ||
public IAssemblyDefinition getDefinition() { | ||
return getInstance().getDefinition(); | ||
} | ||
|
||
@Override | ||
public IAssemblyInstance getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public StaticContext getStaticContext() { | ||
return getParentNodeItem().getStaticContext(); | ||
} | ||
} |
Oops, something went wrong.