|
3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
4 | 4 | */ |
5 | 5 |
|
6 | | -package software.amazon.smithy.java.dynamicclient; |
| 6 | +package software.amazon.smithy.java.dynamicschemas; |
7 | 7 |
|
8 | 8 | import java.util.Collections; |
9 | 9 | import java.util.HashMap; |
|
14 | 14 | import java.util.concurrent.ConcurrentMap; |
15 | 15 | import software.amazon.smithy.java.core.schema.Schema; |
16 | 16 | import software.amazon.smithy.java.core.schema.SchemaBuilder; |
| 17 | +import software.amazon.smithy.java.core.schema.ShapeBuilder; |
17 | 18 | import software.amazon.smithy.model.Model; |
18 | 19 | import software.amazon.smithy.model.shapes.Shape; |
19 | 20 | import software.amazon.smithy.model.shapes.ShapeId; |
20 | 21 | import software.amazon.smithy.model.shapes.ShapeType; |
21 | 22 | import software.amazon.smithy.model.traits.Trait; |
22 | 23 |
|
23 | | -final class SchemaConverter { |
| 24 | +/** |
| 25 | + * Converts {@link Shape}s to {@link Schema}s. |
| 26 | + */ |
| 27 | +public final class SchemaConverter { |
24 | 28 |
|
25 | 29 | private final Model model; |
26 | 30 | private final ConcurrentMap<Shape, Schema> schemas = new ConcurrentHashMap<>(); |
27 | 31 | private final Map<Shape, SchemaBuilder> recursiveBuilders = Collections.synchronizedMap(new HashMap<>()); |
28 | 32 |
|
29 | | - SchemaConverter(Model model) { |
| 33 | + /** |
| 34 | + * @param model Model used when converting shapes to schemas. |
| 35 | + */ |
| 36 | + public SchemaConverter(Model model) { |
30 | 37 | this.model = model; |
31 | 38 | } |
32 | 39 |
|
33 | | - Schema getSchema(Shape shape) { |
| 40 | + /** |
| 41 | + * Create a schema-guided document shape builder. |
| 42 | + * |
| 43 | + * @param schema Schema used to inform deserialization. |
| 44 | + * @param serviceId The shape ID of the service that is used to provide default namespaces for relative shape IDs. |
| 45 | + * @return the created shape builder. |
| 46 | + */ |
| 47 | + public static ShapeBuilder<WrappedDocument> createDocumentBuilder(Schema schema, ShapeId serviceId) { |
| 48 | + return new SchemaGuidedDocumentBuilder(schema, serviceId); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Get the converted {@link Schema} of a Smithy {@link Shape}. |
| 53 | + * |
| 54 | + * @param shape Shape to get the converted schema from. |
| 55 | + * @return the converted schema. |
| 56 | + */ |
| 57 | + public Schema getSchema(Shape shape) { |
34 | 58 | // Aggregate shapes are re-entrant and may need to recursively set values in the CHM. |
35 | 59 | var result = schemas.get(shape); |
36 | 60 |
|
|
0 commit comments