public final class Model extends java.lang.Object implements ToSmithyBuilder<Model>
Modifier and Type | Class and Description |
---|---|
static class |
Model.Builder
Builder used to create a Model.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MODEL_VERSION
Specifies the highest supported version of the IDL.
|
Modifier and Type | Method and 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 a
ModelAssembler that is configured to discover traits,
validators, and built-in validators using the given
ClassLoader . |
static Model.Builder |
builder()
Builds an explicitly configured Smithy model.
|
boolean |
equals(java.lang.Object other) |
Shape |
expectShape(ShapeId id)
|
<T extends Shape> |
expectShape(ShapeId id,
java.lang.Class<T> type)
|
java.util.Set<ShapeId> |
getAppliedTraits()
Gets a set of every trait shape ID that is used in the model.
|
java.util.Set<BigDecimalShape> |
getBigDecimalShapes()
Gets an immutable set of all bigDecimals in the Model.
|
java.util.Set<BigDecimalShape> |
getBigDecimalShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all bigDecimals in the Model that have a specific trait.
|
java.util.Set<BigIntegerShape> |
getBigIntegerShapes()
Gets an immutable set of all bigIntegers in the Model.
|
java.util.Set<BigIntegerShape> |
getBigIntegerShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all bigIntegers in the Model that have a specific trait.
|
java.util.Set<BlobShape> |
getBlobShapes()
Gets an immutable set of all blobs in the Model.
|
java.util.Set<BlobShape> |
getBlobShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all blobs in the Model that have a specific trait.
|
java.util.Set<BooleanShape> |
getBooleanShapes()
Gets an immutable set of all booleans in the Model.
|
java.util.Set<BooleanShape> |
getBooleanShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all booleans in the Model that have a specific trait.
|
java.util.Set<ByteShape> |
getByteShapes()
Gets an immutable set of all bytes in the Model.
|
java.util.Set<ByteShape> |
getByteShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all bytes in the Model that have a specific trait.
|
java.util.Set<DocumentShape> |
getDocumentShapes()
Gets an immutable set of all documents in the Model.
|
java.util.Set<DocumentShape> |
getDocumentShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all documents in the Model that have a specific trait.
|
java.util.Set<DoubleShape> |
getDoubleShapes()
Gets an immutable set of all doubles in the Model.
|
java.util.Set<DoubleShape> |
getDoubleShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all doubles in the Model that have a specific trait.
|
java.util.Set<FloatShape> |
getFloatShapes()
Gets an immutable set of all floats in the Model.
|
java.util.Set<FloatShape> |
getFloatShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all floats in the Model that have a specific trait.
|
java.util.Set<IntegerShape> |
getIntegerShapes()
Gets an immutable set of all integers in the Model.
|
java.util.Set<IntegerShape> |
getIntegerShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all integers in the Model that have a specific trait.
|
<T extends KnowledgeIndex> |
getKnowledge(java.lang.Class<T> type)
Deprecated.
|
<T extends KnowledgeIndex> |
getKnowledge(java.lang.Class<T> type,
java.util.function.Function<Model,T> constructor)
Gets a computed "knowledge index" of a specific type for the model
and caches it for subsequent retrieval.
|
java.util.Set<ListShape> |
getListShapes()
Gets an immutable set of all lists in the Model.
|
java.util.Set<ListShape> |
getListShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all lists in the Model that have a specific trait.
|
java.util.Set<LongShape> |
getLongShapes()
Gets an immutable set of all longs in the Model.
|
java.util.Set<LongShape> |
getLongShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all longs in the Model that have a specific trait.
|
java.util.Set<MapShape> |
getMapShapes()
Gets an immutable set of all maps in the Model.
|
java.util.Set<MapShape> |
getMapShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all maps in the Model that have a specific trait.
|
java.util.Set<MemberShape> |
getMemberShapes()
Gets an immutable set of all members in the Model.
|
java.util.Set<MemberShape> |
getMemberShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all members in the Model that have a specific trait.
|
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.
|
java.util.Set<OperationShape> |
getOperationShapes()
Gets an immutable set of all operations in the Model.
|
java.util.Set<OperationShape> |
getOperationShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all operations in the Model that have a specific trait.
|
java.util.Set<ResourceShape> |
getResourceShapes()
Gets an immutable set of all resources in the Model.
|
java.util.Set<ResourceShape> |
getResourceShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all resources in the Model that have a specific trait.
|
java.util.Set<ServiceShape> |
getServiceShapes()
Gets an immutable set of all services in the Model.
|
java.util.Set<ServiceShape> |
getServiceShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all services in the Model that have a specific trait.
|
java.util.Set<SetShape> |
getSetShapes()
Gets an immutable set of all sets in the Model.
|
java.util.Set<SetShape> |
getSetShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all sets in the Model that have a specific trait.
|
java.util.Optional<Shape> |
getShape(ShapeId id)
|
java.util.Set<ShapeId> |
getShapeIds()
Gets the immutable set of
ShapeId in the model. |
java.util.Set<Shape> |
getShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets a set of shapes in the model marked with a specific trait.
|
java.util.Set<Shape> |
getShapesWithTrait(ToShapeId trait)
Gets a set of shapes in the model marked with a specific trait.
|
java.util.Set<ShortShape> |
getShortShapes()
Gets an immutable set of all shorts in the Model.
|
java.util.Set<ShortShape> |
getShortShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all shorts in the Model that have a specific trait.
|
java.util.Set<StringShape> |
getStringShapes()
Gets an immutable set of all strings in the Model.
|
java.util.Set<StringShape> |
getStringShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all strings in the Model that have a specific trait.
|
java.util.Set<StructureShape> |
getStructureShapes()
Gets an immutable set of all structures in the Model.
|
java.util.Set<StructureShape> |
getStructureShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all structures in the Model that have a specific trait.
|
java.util.Set<TimestampShape> |
getTimestampShapes()
Gets an immutable set of all timestamps in the Model.
|
java.util.Set<TimestampShape> |
getTimestampShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all timestamps in the Model that have a specific trait.
|
java.util.Optional<TraitDefinition> |
getTraitDefinition(ToShapeId traitId)
Gets the trait definition of a specific trait shape ID.
|
java.util.Set<UnionShape> |
getUnionShapes()
Gets an immutable set of all unions in the Model.
|
java.util.Set<UnionShape> |
getUnionShapesWithTrait(java.lang.Class<? extends Trait> trait)
Gets an immutable set of all unions in the Model that have a specific trait.
|
int |
hashCode() |
boolean |
isTraitApplied(java.lang.Class<? extends Trait> trait)
Returns true if the given trait shape ID was used in the model.
|
java.util.stream.Stream<Shape> |
shapes()
Gets a stream of
Shape s in the index. |
<T extends Shape> |
shapes(java.lang.Class<T> shapeType)
Gets a stream of shapes in the index of a specific type
T . |
Model.Builder |
toBuilder()
Take this object and create a builder that contains all of the
current property values of this object.
|
java.util.Set<Shape> |
toSet()
Converts the model to an immutable Set of shapes.
|
<T extends Shape> |
toSet(java.lang.Class<T> shapeType)
Gets an immutable Set of shapes of a specific type.
|
public static final java.lang.String MODEL_VERSION
public static Model.Builder builder()
Note that the builder does not validate the correctness of the
model. Use the assembler()
method to build and
validate a model.
assembler()
public static ModelAssembler assembler()
public static ModelAssembler assembler(java.lang.ClassLoader classLoader)
ModelAssembler
that is configured to discover traits,
validators, and built-in validators using the given
ClassLoader
.classLoader
- Class loader used to discover services.public java.util.Optional<Node> getMetadataProperty(java.lang.String name)
name
- Name of the property to retrieve.public java.util.Map<java.lang.String,Node> getMetadata()
public java.util.Optional<TraitDefinition> getTraitDefinition(ToShapeId traitId)
traitId
- ID of the shape to get the trait definition of.public java.util.Set<Shape> getShapesWithTrait(ToShapeId trait)
trait
- Trait shape ID to look for on shapes.public java.util.Set<ShapeId> getShapeIds()
ShapeId
in the model.public java.util.Set<Shape> getShapesWithTrait(java.lang.Class<? extends Trait> trait)
The result is an exact match on trait classes and does not utilize any kind of polymorphic instance of checks.
trait
- Trait class to look for on shapes.public java.util.Set<BigDecimalShape> getBigDecimalShapes()
bigDecimals
s.public java.util.Set<BigDecimalShape> getBigDecimalShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.bigdecimal
s that have a specific trait.public java.util.Set<BigIntegerShape> getBigIntegerShapes()
bigIntegers
s.public java.util.Set<BigIntegerShape> getBigIntegerShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.bigIntegers
s that have a specific trait.public java.util.Set<BlobShape> getBlobShapes()
blob
s.public java.util.Set<BlobShape> getBlobShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.blob
s that have a specific trait.public java.util.Set<BooleanShape> getBooleanShapes()
boolean
s.public java.util.Set<BooleanShape> getBooleanShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.boolean
s that have a specific trait.public java.util.Set<ByteShape> getByteShapes()
byte
s.public java.util.Set<ByteShape> getByteShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.byte
s that have a specific trait.public java.util.Set<DocumentShape> getDocumentShapes()
document
s.public java.util.Set<DocumentShape> getDocumentShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.document
s that have a specific trait.public java.util.Set<DoubleShape> getDoubleShapes()
double
s.public java.util.Set<DoubleShape> getDoubleShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.double
s that have a specific trait.public java.util.Set<FloatShape> getFloatShapes()
float
s.public java.util.Set<FloatShape> getFloatShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.float
s that have a specific trait.public java.util.Set<IntegerShape> getIntegerShapes()
integer
s.public java.util.Set<IntegerShape> getIntegerShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.integer
s that have a specific trait.public java.util.Set<ListShape> getListShapes()
list
s.public java.util.Set<ListShape> getListShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.list
s that have a specific trait.public java.util.Set<LongShape> getLongShapes()
long
s.public java.util.Set<LongShape> getLongShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.long
s that have a specific trait.public java.util.Set<MapShape> getMapShapes()
map
s.public java.util.Set<MapShape> getMapShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.map
s that have a specific trait.public java.util.Set<MemberShape> getMemberShapes()
member
s.public java.util.Set<MemberShape> getMemberShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.member
s that have a specific trait.public java.util.Set<OperationShape> getOperationShapes()
operation
s.public java.util.Set<OperationShape> getOperationShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.operation
s that have a specific trait.public java.util.Set<ResourceShape> getResourceShapes()
resource
s.public java.util.Set<ResourceShape> getResourceShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.resource
s that have a specific trait.public java.util.Set<ServiceShape> getServiceShapes()
service
s.public java.util.Set<ServiceShape> getServiceShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.service
s that have a specific trait.public java.util.Set<SetShape> getSetShapes()
set
s.public java.util.Set<SetShape> getSetShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.set
s that have a specific trait.public java.util.Set<ShortShape> getShortShapes()
short
s.public java.util.Set<ShortShape> getShortShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.short
s that have a specific trait.public java.util.Set<StringShape> getStringShapes()
string
s.public java.util.Set<StringShape> getStringShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.string
s that have a specific trait.public java.util.Set<StructureShape> getStructureShapes()
structure
s.public java.util.Set<StructureShape> getStructureShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.structure
s that have a specific trait.public java.util.Set<TimestampShape> getTimestampShapes()
timestamp
s.public java.util.Set<TimestampShape> getTimestampShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.timestamp
s that have a specific trait.public java.util.Set<UnionShape> getUnionShapes()
union
s.public java.util.Set<UnionShape> getUnionShapesWithTrait(java.lang.Class<? extends Trait> trait)
trait
- The exact trait class to look for on shapes.union
s that have a specific trait.public java.util.Set<ShapeId> getAppliedTraits()
public boolean isTraitApplied(java.lang.Class<? extends Trait> trait)
trait
- The trait class to check.public java.util.Optional<Shape> getShape(ShapeId id)
id
- Shape to retrieve by ID.public Shape expectShape(ShapeId id)
id
- Shape to retrieve by ID.ExpectationNotMetException
- if the shape is not found.public <T extends Shape> T expectShape(ShapeId id, java.lang.Class<T> type)
Shape
by ShapeId
and
throws if not found or if the shape is not of the expected type.T
- Expected shape type.id
- Shape to retrieve by ID.type
- Shape type to expect and convert to.ExpectationNotMetException
- if the shape is not found or is not the expected type.public java.util.stream.Stream<Shape> shapes()
Shape
s in the index.public <T extends Shape> java.util.stream.Stream<T> shapes(java.lang.Class<T> shapeType)
T
.
The provided shapeType class must exactly match the class of a
shape in the model in order to be returned from this method;
that is, the provided class must be a concrete subclass of
Shape
and not an abstract class like NumberShape
.
T
- Shape type to stream from the index.shapeType
- Shape type T
to retrieve.T
matching shapeType
.public <T extends Shape> java.util.Set<T> toSet(java.lang.Class<T> shapeType)
T
- Shape type to get from the index.shapeType
- Type of shape to get a set of.public java.util.Set<Shape> toSet()
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public Model.Builder toBuilder()
ToSmithyBuilder
toBuilder
in interface ToSmithyBuilder<Model>
@Deprecated public <T extends KnowledgeIndex> T getKnowledge(java.lang.Class<T> type)
of
method of the
KnowledgeIndex
you wish to create instead.T
- The type of knowledge index to retrieve.type
- Type of knowledge index to retrieve.public <T extends KnowledgeIndex> T getKnowledge(java.lang.Class<T> type, java.util.function.Function<Model,T> constructor)
This method should not typically be called directly because
KnowledgeIndex classes should all provide a public static of
method that accepts a Model
and returns an instance of the
index by invoking getKnowledge
.
If a KnowledgeIndex
of the given type has not yet been
computed, one will be created using the provided constructor
function that accepts a Model
. Computed knowledge indexes are
cached and returned on subsequent retrievals.
T
- The type of knowledge index to retrieve.type
- Type of knowledge index to retrieve.constructor
- The method used to create type
.