Class Model
- java.lang.Object
-
- software.amazon.smithy.model.Model
-
- All Implemented Interfaces:
software.amazon.smithy.utils.ToSmithyBuilder<Model>
public final class Model extends java.lang.Object implements software.amazon.smithy.utils.ToSmithyBuilder<Model>
A Smithy model, including shapes, traits, custom traits, validators, suppressions and metadata.A "model" contains all of the loaded shapes (including their traits), validator definitions, suppression definitions, metadata properties, the Smithy version number, and all custom trait definitions. Each of these properties of a model contain a
SourceLocation
, allowing a reference back to where they were defined and how they were originally grouped into separate document files.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Model.Builder
Builder used to create a Model.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
MODEL_VERSION
Specifies the highest supported version of the IDL.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ModelAssembler
assembler()
Assembles and validates a Smithy model from files, nodes, and other disparate sources.static ModelAssembler
assembler(java.lang.ClassLoader classLoader)
Creates aModelAssembler
that is configured to discover traits, validators, and built-in validators using the givenClassLoader
.static Model.Builder
builder()
Builds an explicitly configured Smithy model.boolean
equals(java.lang.Object other)
<T extends KnowledgeIndex>
TgetKnowledge(java.lang.Class<T> type)
Gets a computed knowledge index of a specific type for the model.java.util.Map<java.lang.String,Node>
getMetadata()
java.util.Optional<Node>
getMetadataProperty(java.lang.String name)
Gets a metadata property by namespace and name.ShapeIndex
getShapeIndex()
Gets theShapeIndex
of theModel
.java.lang.String
getSmithyVersion()
java.util.Optional<TraitDefinition>
getTraitDefinition(java.lang.String traitId)
Gets the trait definition of a specific trait shape ID.java.util.Optional<TraitDefinition>
getTraitDefinition(ToShapeId traitId)
Gets the trait definition of a specific trait shape ID.java.util.Map<Shape,TraitDefinition>
getTraitDefinitions()
Returns are trait shapes in the model as a map ofShape
objects to theirTraitDefinition
traits.java.util.Collection<Shape>
getTraitShapes()
int
hashCode()
Model.Builder
toBuilder()
-
-
-
Field Detail
-
MODEL_VERSION
public static final java.lang.String MODEL_VERSION
Specifies the highest supported version of the IDL.- See Also:
- Constant Field Values
-
-
Method Detail
-
builder
public static Model.Builder builder()
Builds an explicitly configured Smithy model.Note that the builder does not validate the correctness of the model. Use the
assembler()
method to build and validate a model.- Returns:
- Returns a model builder.
- See Also:
assembler()
-
assembler
public static ModelAssembler assembler()
Assembles and validates a Smithy model from files, nodes, and other disparate sources.- Returns:
- Returns a model assembler.
-
assembler
public static ModelAssembler assembler(java.lang.ClassLoader classLoader)
Creates aModelAssembler
that is configured to discover traits, validators, and built-in validators using the givenClassLoader
.- Parameters:
classLoader
- Class loader used to discover services.- Returns:
- Returns a model assembler.
-
getShapeIndex
public ShapeIndex getShapeIndex()
Gets theShapeIndex
of theModel
.- Returns:
- Returns the index of shapes.
-
getMetadataProperty
public java.util.Optional<Node> getMetadataProperty(java.lang.String name)
Gets a metadata property by namespace and name.- Parameters:
name
- Name of the property to retrieve.- Returns:
- Returns the optional property.
-
getMetadata
public java.util.Map<java.lang.String,Node> getMetadata()
- Returns:
- Gets the unmodifiable metadata of the model across all namespaces.
-
getSmithyVersion
public java.lang.String getSmithyVersion()
-
getTraitDefinitions
public java.util.Map<Shape,TraitDefinition> getTraitDefinitions()
Returns are trait shapes in the model as a map ofShape
objects to theirTraitDefinition
traits.- Returns:
- Returns all trait definitions in the model.
-
getTraitDefinition
public java.util.Optional<TraitDefinition> getTraitDefinition(ToShapeId traitId)
Gets the trait definition of a specific trait shape ID.- Parameters:
traitId
- ID of the shape to get the trait definition of.- Returns:
- Returns the optionally found trait definition.
-
getTraitDefinition
public java.util.Optional<TraitDefinition> getTraitDefinition(java.lang.String traitId)
Gets the trait definition of a specific trait shape ID.- Parameters:
traitId
- ID of the shape to get the trait definition of.- Returns:
- Returns the optionally found trait definition.
-
getTraitShapes
public java.util.Collection<Shape> getTraitShapes()
- Returns:
- Returns all trait definition shapes in the model.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toBuilder
public Model.Builder toBuilder()
- Specified by:
toBuilder
in interfacesoftware.amazon.smithy.utils.ToSmithyBuilder<Model>
-
getKnowledge
public <T extends KnowledgeIndex> T getKnowledge(java.lang.Class<T> type)
Gets a computed knowledge index of a specific type for the model.If a
KnowledgeIndex
of the given type has not yet been computed, one will be created using a constructor of the given type that accepts aModel
. Computed knowledge indexes are cached and returned on subsequent retrievals.Using this method is preferred over directly instantiating instances of a KnowledgeIndex if the KnowledgeIndex required in various unrelated code paths where passing around an instance of a KnowledgeIndex is not practical or impossible.
- Type Parameters:
T
- The type of knowledge index to retrieve.- Parameters:
type
- Type of knowledge index to retrieve.- Returns:
- Returns the computed knowledge index.
-
-