- this.qname = ctx.getStatementArgument();
- this.path = Utils.getSchemaPath(ctx);
- // :TODO init other fields
-
- initSubstatementCollections();
- initCopyType(ctx);
- }
-
- private void initCopyType(
- StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
-
- TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
- switch (typeOfCopy) {
- case ADDED_BY_AUGMENTATION:
- augmenting = true;
- original = (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
- break;
- case ADDED_BY_USES:
- addedByUses = true;
- original = (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
- break;
- default:
- break;
- }
- }
-
- private void initSubstatementCollections() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
- List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
+ this.original = ctx.getOriginalCtx() == null ? null : (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
+
+ final TypeEffectiveStatement<?> typeStmt = SourceException.throwIfNull(
+ firstSubstatementOfType(TypeEffectiveStatement.class), ctx.getStatementSourceReference(),
+ "Leaf is missing a 'type' statement");
+
+ String dflt = null;
+ String units = null;
+ final ConcreteTypeBuilder<?> builder = ConcreteTypes.concreteTypeBuilder(typeStmt.getTypeDefinition(),
+ ctx.getSchemaPath().get());
+ for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
+ if (stmt instanceof DefaultEffectiveStatementImpl) {
+ dflt = ((DefaultEffectiveStatementImpl)stmt).argument();
+ builder.setDefaultValue(stmt.argument());
+ } else if (stmt instanceof DescriptionEffectiveStatementImpl) {
+ builder.setDescription(((DescriptionEffectiveStatementImpl)stmt).argument());
+ } else if (stmt instanceof ReferenceEffectiveStatementImpl) {
+ builder.setReference(((ReferenceEffectiveStatementImpl)stmt).argument());
+ } else if (stmt instanceof StatusEffectiveStatementImpl) {
+ builder.setStatus(((StatusEffectiveStatementImpl)stmt).argument());
+ } else if (stmt instanceof UnitsEffectiveStatementImpl) {
+ units = ((UnitsEffectiveStatementImpl)stmt).argument();
+ builder.setUnits(units);