2 * Copyright (c) 2015 Cisco Systems, Inc. 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.data.impl.codec;
10 import com.google.common.base.Optional;
11 import org.opendaylight.yangtools.yang.data.api.codec.StringCodec;
12 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
14 class StringStringCodec extends TypeDefinitionAwareCodec<String, StringTypeDefinition> implements
17 protected StringStringCodec(final StringTypeDefinition typeDef) {
18 super(Optional.of(typeDef), String.class);
19 typeDef.getLengthConstraints();
22 static TypeDefinitionAwareCodec<?, StringTypeDefinition> from(final StringTypeDefinition normalizedType) {
23 if (normalizedType.getPatternConstraints().isEmpty()) {
24 return new StringStringCodec(normalizedType);
27 return new StringPatternCheckingCodec(normalizedType);
31 public final String deserialize(final String stringRepresentation) {
32 if (stringRepresentation == null) {
33 // FIXME: These seems buggy, but someone may be using this behaviour
36 validate(stringRepresentation);
37 return stringRepresentation;
41 public final String serialize(final String data) {
42 return data == null ? "" : data;
45 protected void validate(final String s) {