2 * Copyright (c) 2015 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.util.type;
10 import com.google.common.base.Preconditions;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
15 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
16 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
18 public final class StringTypeBuilder extends LengthRestrictedTypeBuilder<StringTypeDefinition> {
19 private final List<PatternConstraint> patternConstraints = new ArrayList<>(0);
21 StringTypeBuilder(final StringTypeDefinition baseType, final SchemaPath path) {
22 super(baseType, path);
25 public void addPatternConstraint(final PatternConstraint constraint) {
26 patternConstraints.add(Preconditions.checkNotNull(constraint));
31 List<LengthConstraint> getLengthConstraints(final StringTypeDefinition type) {
32 return type.getLengthConstraints();
36 List<LengthConstraint> typeLengthConstraints() {
38 * Length constraint imposed on YANG string type by our implementation. {@link String#length()} is an integer,
39 * capping our ability to support strings up to 18446744073709551615 as defined in
40 * http://tools.ietf.org/html/rfc6020#section-9.4.4.
42 * FIXME: We could bump this number up to allow such models, but that could lead to unexpected run-time errors.
43 * In order to do that, the parser would need another pass on the effective statements, which would cap
44 * the constraints to the run-time environment.
46 return JavaLengthConstraints.INTEGER_SIZE_CONSTRAINTS;
50 StringTypeDefinition buildType(final List<LengthConstraint> lengthConstraints) {
51 return new RestrictedStringType(getBaseType(), getPath(), getUnknownSchemaNodes(),
52 lengthConstraints, patternConstraints);