import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.DerivedType;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("unchecked")
private JSONCodec<Object> createCodec(final DataSchemaNode key, final TypeDefinition<?> type) {
- final TypeDefinition<?> normalizedType = DerivedType.from(type);
- if (normalizedType instanceof LeafrefTypeDefinition) {
- return createReferencedTypeCodec(key, (LeafrefTypeDefinition) normalizedType);
- } else if (normalizedType instanceof IdentityrefTypeDefinition) {
+ if (type instanceof LeafrefTypeDefinition) {
+ return createReferencedTypeCodec(key, (LeafrefTypeDefinition) type);
+ } else if (type instanceof IdentityrefTypeDefinition) {
final JSONCodec<?> jsonStringIdentityrefCodec =
new JSONStringIdentityrefCodec(schemaContext, key.getQName().getModule());
return (JSONCodec<Object>) jsonStringIdentityrefCodec;
}
- return createFromSimpleType(normalizedType);
+ return createFromSimpleType(type);
}
private JSONCodec<Object> createReferencedTypeCodec(final DataSchemaNode schema,
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.DerivedType;
public abstract class TypeDefinitionAwareCodec<J, T extends TypeDefinition<T>> implements DataStringCodec<J> {
private final Optional<T> typeDefinition;
@SuppressWarnings("unchecked")
public static <T extends TypeDefinition<T>> TypeDefinitionAwareCodec<?, T> fromType(final T typeDefinition) {
- // FIXME: this is not necessary with yang.model.util.type
- final T normalizedType = (T) DerivedType.from(typeDefinition);
@SuppressWarnings("rawtypes")
final TypeDefinitionAwareCodec codec;
- if (normalizedType instanceof BinaryTypeDefinition) {
- codec = BinaryStringCodec.from((BinaryTypeDefinition)normalizedType);
- } else if (normalizedType instanceof BitsTypeDefinition) {
- codec = BitsStringCodec.from((BitsTypeDefinition)normalizedType);
- } else if (normalizedType instanceof BooleanTypeDefinition) {
- codec = BooleanStringCodec.from((BooleanTypeDefinition)normalizedType);
- } else if (normalizedType instanceof DecimalTypeDefinition) {
- codec = DecimalStringCodec.from((DecimalTypeDefinition)normalizedType);
- } else if (normalizedType instanceof EmptyTypeDefinition) {
+ if (typeDefinition instanceof BinaryTypeDefinition) {
+ codec = BinaryStringCodec.from((BinaryTypeDefinition)typeDefinition);
+ } else if (typeDefinition instanceof BitsTypeDefinition) {
+ codec = BitsStringCodec.from((BitsTypeDefinition)typeDefinition);
+ } else if (typeDefinition instanceof BooleanTypeDefinition) {
+ codec = BooleanStringCodec.from((BooleanTypeDefinition)typeDefinition);
+ } else if (typeDefinition instanceof DecimalTypeDefinition) {
+ codec = DecimalStringCodec.from((DecimalTypeDefinition)typeDefinition);
+ } else if (typeDefinition instanceof EmptyTypeDefinition) {
codec = EmptyStringCodec.INSTANCE;
- } else if (normalizedType instanceof EnumTypeDefinition) {
- codec = EnumStringCodec.from((EnumTypeDefinition)normalizedType);
- } else if (normalizedType instanceof IntegerTypeDefinition) {
- codec = AbstractIntegerStringCodec.from((IntegerTypeDefinition) normalizedType);
- } else if (normalizedType instanceof StringTypeDefinition) {
- codec = StringStringCodec.from((StringTypeDefinition)normalizedType);
- } else if (normalizedType instanceof UnionTypeDefinition) {
- codec = UnionStringCodec.from((UnionTypeDefinition)normalizedType);
- } else if (normalizedType instanceof UnsignedIntegerTypeDefinition) {
- codec = AbstractIntegerStringCodec.from((UnsignedIntegerTypeDefinition) normalizedType);
+ } else if (typeDefinition instanceof EnumTypeDefinition) {
+ codec = EnumStringCodec.from((EnumTypeDefinition)typeDefinition);
+ } else if (typeDefinition instanceof IntegerTypeDefinition) {
+ codec = AbstractIntegerStringCodec.from((IntegerTypeDefinition) typeDefinition);
+ } else if (typeDefinition instanceof StringTypeDefinition) {
+ codec = StringStringCodec.from((StringTypeDefinition)typeDefinition);
+ } else if (typeDefinition instanceof UnionTypeDefinition) {
+ codec = UnionStringCodec.from((UnionTypeDefinition)typeDefinition);
+ } else if (typeDefinition instanceof UnsignedIntegerTypeDefinition) {
+ codec = AbstractIntegerStringCodec.from((UnsignedIntegerTypeDefinition) typeDefinition);
} else {
codec = null;
}
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.DerivedType;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
}
public static Object parseXmlValue(final Element xml, final XmlCodecProvider codecProvider, final DataSchemaNode schema, final TypeDefinition<?> type, final SchemaContext schemaCtx) {
- TypeDefinition<?> baseType = DerivedType.from(type);
-
String text = xml.getTextContent();
text = text.trim();
final Object value;
- if (baseType instanceof LeafrefTypeDefinition) {
- final LeafrefTypeDefinition leafrefTypeDefinition = (LeafrefTypeDefinition) baseType;
- baseType = SchemaContextUtil.getBaseTypeForLeafRef(leafrefTypeDefinition, schemaCtx, schema);
+ if (type instanceof LeafrefTypeDefinition) {
+ final LeafrefTypeDefinition leafrefTypeDefinition = (LeafrefTypeDefinition) type;
+ TypeDefinition<?> baseType = SchemaContextUtil.getBaseTypeForLeafRef(leafrefTypeDefinition, schemaCtx, schema);
value = parseXmlValue(xml, codecProvider, schema, baseType, schemaCtx);
- } else if (baseType instanceof InstanceIdentifierTypeDefinition) {
+ } else if (type instanceof InstanceIdentifierTypeDefinition) {
value = InstanceIdentifierForXmlCodec.deserialize(xml, schemaCtx);
- } else if (baseType instanceof IdentityrefTypeDefinition) {
+ } else if (type instanceof IdentityrefTypeDefinition) {
value = InstanceIdentifierForXmlCodec.toIdentity(text, xml, schemaCtx);
} else {
value = parseXmlValue(xml, codecProvider, type);
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.DerivedType;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
@Beta
}
private void emitTypeBodyNodes(final TypeDefinition<?> typeDef) {
- if (typeDef instanceof ExtendedType) {
- emitTypeBodyNodes(DerivedType.from((ExtendedType) typeDef));
- } else if (typeDef instanceof UnsignedIntegerTypeDefinition) {
+ if (typeDef instanceof UnsignedIntegerTypeDefinition) {
emitUnsignedIntegerSpecification((UnsignedIntegerTypeDefinition) typeDef);
} else if (typeDef instanceof IntegerTypeDefinition) {
emitIntegerSpefication((IntegerTypeDefinition) typeDef);
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedBinaryType extends DerivedType<BinaryTypeDefinition> implements BinaryTypeDefinition {
-
- public DerivedBinaryType(final ExtendedType definition) {
- super(BinaryTypeDefinition.class, definition);
- }
-
- @Override
- BinaryTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedBinaryType(base);
- }
-
- @Override
- public List<LengthConstraint> getLengthConstraints() {
- return delegate().getLengthConstraints();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedBitsType extends DerivedType<BitsTypeDefinition> implements BitsTypeDefinition {
-
- public DerivedBitsType(final ExtendedType definition) {
- super(BitsTypeDefinition.class, definition);
- }
-
- @Override
- BitsTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedBitsType(base);
- }
-
- @Override
- public List<Bit> getBits() {
- return getBaseType().getBits();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedBooleanType extends DerivedType<BooleanTypeDefinition> implements BooleanTypeDefinition {
-
- public DerivedBooleanType(final ExtendedType definition) {
- super(BooleanTypeDefinition.class, definition);
- }
-
- @Override
- BooleanTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedBooleanType(base);
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedDecimalType extends DerivedType<DecimalTypeDefinition> implements DecimalTypeDefinition {
-
- public DerivedDecimalType(final ExtendedType definition) {
- super(DecimalTypeDefinition.class, definition);
- }
-
- @Override
- DecimalTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedDecimalType(base);
- }
-
- @Override
- public List<RangeConstraint> getRangeConstraints() {
- return delegate().getRangeConstraints();
- }
-
- @Override
- public Integer getFractionDigits() {
- return delegate().getFractionDigits();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedEnumType extends DerivedType<EnumTypeDefinition> implements EnumTypeDefinition {
-
- public DerivedEnumType(final ExtendedType definition) {
- super(EnumTypeDefinition.class, definition);
- }
-
- @Override
- EnumTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedEnumType(base);
- }
-
- @Override
- public List<EnumPair> getValues() {
- return getBaseType().getValues();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
-import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedIdentityrefType extends DerivedType<IdentityrefTypeDefinition> implements
- IdentityrefTypeDefinition {
-
- public DerivedIdentityrefType(final ExtendedType definition) {
- super(IdentityrefTypeDefinition.class, definition);
- }
-
- @Override
- IdentityrefTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedIdentityrefType(base);
- }
-
- @Override
- public IdentitySchemaNode getIdentity() {
- // FIXME: Is this really correct?
- return getBaseType().getIdentity();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
-import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedInstanceIdentifierType extends DerivedType<InstanceIdentifierTypeDefinition> implements
- InstanceIdentifierTypeDefinition {
-
- public DerivedInstanceIdentifierType(final ExtendedType definition) {
- super(InstanceIdentifierTypeDefinition.class, definition);
- }
-
- @Override
- InstanceIdentifierTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedInstanceIdentifierType(base);
- }
-
- @Override
- public RevisionAwareXPath getPathStatement() {
- throw new UnsupportedOperationException("Path statement is not part of instance-identifier type");
- }
-
- @Override
- public boolean requireInstance() {
- return getBaseType().requireInstance();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedIntegerType extends DerivedType<IntegerTypeDefinition> implements IntegerTypeDefinition {
-
- public DerivedIntegerType(final ExtendedType definition) {
- super(IntegerTypeDefinition.class, definition);
- }
-
- @Override
- IntegerTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedIntegerType(base);
- }
-
- @Override
- public List<RangeConstraint> getRangeConstraints() {
- return delegate().getRangeConstraints();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
-import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedLeafrefType extends DerivedType<LeafrefTypeDefinition> implements LeafrefTypeDefinition {
-
- public DerivedLeafrefType(final ExtendedType definition) {
- super(LeafrefTypeDefinition.class, definition);
- }
-
- @Override
- LeafrefTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedLeafrefType(base);
- }
-
- @Override
- public RevisionAwareXPath getPathStatement() {
- return getBaseType().getPathStatement();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedStringType extends DerivedType<StringTypeDefinition> implements StringTypeDefinition {
-
- public DerivedStringType(final ExtendedType definition) {
- super(StringTypeDefinition.class, definition);
- }
-
- @Override
- StringTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedStringType(base);
- }
-
- @Override
- public List<LengthConstraint> getLengthConstraints() {
- return delegate().getLengthConstraints();
- }
-
- @Override
- public List<PatternConstraint> getPatternConstraints() {
- return delegate().getPatternConstraints();
- }
-
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import com.google.common.base.Preconditions;
-import java.util.List;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
-
-/**
- *
- * Implementations of derived type.
- *
- * This is set of utility classes which implements derived YANG type,
- * preserving original implemented interface instead of {@link ExtendedType}
- * which does not preserve final type of data.
- *
- * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.DerivedTypes} or
- * {@link org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes} instead
- */
-@Deprecated
-public abstract class DerivedType<T extends TypeDefinition<T>> implements TypeDefinition<T> {
-
- private final ExtendedType definition;
- private final Class<T> publicType;
-
- DerivedType(final Class<T> publicType, final ExtendedType delegate) {
- this.definition = Preconditions.checkNotNull(delegate);
- this.publicType = Preconditions.checkNotNull(publicType);
- }
-
- public static TypeDefinition<?> from(final TypeDefinition<?> type) {
- if (type instanceof ExtendedType) {
- return from((ExtendedType) type);
- }
- return type;
- }
-
- public static TypeDefinition<?> from(final ExtendedType type) {
- TypeDefinition<? extends TypeDefinition<?>> baseType = type;
- while (baseType.getBaseType() != null) {
- baseType = baseType.getBaseType();
- }
- if (baseType instanceof BinaryTypeDefinition) {
- return new DerivedBinaryType(type);
- }
- if (baseType instanceof BooleanTypeDefinition) {
- return new DerivedBooleanType(type);
- }
- if (baseType instanceof DecimalTypeDefinition) {
- return new DerivedDecimalType(type);
- }
- if (baseType instanceof IdentityrefTypeDefinition) {
- return new DerivedIdentityrefType(type);
- }
- if (baseType instanceof InstanceIdentifierTypeDefinition) {
- return new DerivedInstanceIdentifierType(type);
- }
- if (baseType instanceof IntegerTypeDefinition) {
- return new DerivedIntegerType(type);
- }
- if (baseType instanceof LeafrefTypeDefinition) {
- return new DerivedLeafrefType(type);
- }
- if (baseType instanceof UnsignedIntegerTypeDefinition) {
- return new DerivedUnsignedIntegerType(type);
- }
- if (baseType instanceof StringTypeDefinition) {
- return new DerivedStringType(type);
- }
- if (baseType instanceof UnionTypeDefinition) {
- return new DerivedUnionType(type);
- }
- if (baseType instanceof EnumTypeDefinition) {
- return new DerivedEnumType(type);
- }
- if (baseType instanceof BitsTypeDefinition) {
- return new DerivedBitsType(type);
- }
- throw new IllegalArgumentException("Not supported base type of " + baseType.getClass());
- }
-
- @Override
- public final QName getQName() {
- return definition.getQName();
- }
-
- @Override
- public final SchemaPath getPath() {
- return definition.getPath();
- }
-
- @Override
- public final List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return definition.getUnknownSchemaNodes();
- }
-
- @Override
- public final String getDescription() {
- return definition.getDescription();
- }
-
- @Override
- public final String getReference() {
- return definition.getReference();
- }
-
- @Override
- public final String getUnits() {
- return definition.getUnits();
- }
-
- @Override
- public final Object getDefaultValue() {
- return definition.getDefaultValue();
- }
-
- @Override
- public final Status getStatus() {
- return definition.getStatus();
- }
-
- @Override
- public final T getBaseType() {
- final TypeDefinition<?> base = definition.getBaseType();
- if (publicType.isInstance(base)) {
- return publicType.cast(base);
- } else if (base instanceof ExtendedType) {
- return createDerived((ExtendedType) base);
- }
- throw new IllegalStateException("Unsupported base type.");
- }
-
- protected ExtendedType delegate() {
- return definition;
- }
-
- /**
- *
- * Creates derived type from supplied ExtendedType, which will implement
- * proper {@link TypeDefinition} interface.
- *
- * @param base Base definition, which does not implement concrete API
- * @return wrapper which implements proper subinterface of {@link TypeDefinition}.
- */
- abstract T createDerived(ExtendedType base);
-
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedUnionType extends DerivedType<UnionTypeDefinition> implements UnionTypeDefinition {
-
- public DerivedUnionType(final ExtendedType definition) {
- super(UnionTypeDefinition.class, definition);
- }
-
- @Override
- UnionTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedUnionType(base);
- }
-
- @Override
- public List<TypeDefinition<?>> getTypes() {
- return getBaseType().getTypes();
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
-
-/**
- * @deprecated Deprecated {@link DerivedType} subclass.
- */
-@Deprecated
-class DerivedUnsignedIntegerType extends DerivedType<UnsignedIntegerTypeDefinition> implements
- UnsignedIntegerTypeDefinition {
-
- public DerivedUnsignedIntegerType(final ExtendedType definition) {
- super(UnsignedIntegerTypeDefinition.class, definition);
- }
-
- @Override
- UnsignedIntegerTypeDefinition createDerived(final ExtendedType base) {
- return new DerivedUnsignedIntegerType(base);
- }
-
- @Override
- public List<RangeConstraint> getRangeConstraints() {
- return delegate().getRangeConstraints();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import java.util.Collections;
-import java.util.List;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
-
-/**
- * Extended Type represents YANG type derived from other type.
- *
- * Extended type object is decorator on top of existing {@link TypeDefinition}
- * which represents original type, and extended type
- * may define additional constraints, modify description or reference
- * of parent type or provide new type capture for specific use-cases.
- *
- * @deprecated Use of this class is deprecated, use {@link DerivedType} instead.
- */
-@Deprecated
-public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
-
- private final QName typeName;
- private final TypeDefinition<?> baseType;
- private final SchemaPath path;
- private final String description;
- private final String reference;
- private final List<UnknownSchemaNode> unknownSchemaNodes;
-
- private final Status status;
- private final String units;
- private final Object defaultValue;
- private final boolean addedByUses;
-
- private List<RangeConstraint> ranges = Collections.emptyList();
- private List<LengthConstraint> lengths = Collections.emptyList();
- private List<PatternConstraint> patterns = Collections.emptyList();
- private Integer fractionDigits = null;
-
- /**
- *
- * Creates Builder for extended / derived type.
- *
- * @param typeName QName of derived type
- * @param baseType Base type of derived type
- * @param description Description of type
- * @param reference Reference of Type
- * @param path Schema path to type definition.
- */
- public static Builder builder(final QName typeName, final TypeDefinition<?> baseType,
- final Optional<String> description, final Optional<String> reference, final SchemaPath path) {
- return new Builder(typeName, baseType, description.or(""), reference.or(""), path);
- }
-
- public static class Builder {
- private final QName typeName;
- private final TypeDefinition<?> baseType;
-
- private final SchemaPath path;
- private final String description;
- private final String reference;
-
- private List<UnknownSchemaNode> unknownSchemaNodes = Collections
- .emptyList();
- private Status status = Status.CURRENT;
- private String units = null;
- private Object defaultValue = null;
- private boolean addedByUses;
-
- private List<RangeConstraint> ranges = Collections.emptyList();
- private List<LengthConstraint> lengths = Collections.emptyList();
- private List<PatternConstraint> patterns = Collections.emptyList();
- private Integer fractionDigits = null;
-
- /**
- * Creates Builder for extended / derived type.
- *
- * @param typeName QName of derived type
- * @param baseType Base type of derived type
- * @param description Description of type
- * @param reference Reference of Type
- * @param path Schema path to type definition.
- */
- protected Builder(final QName typeName, final TypeDefinition<?> baseType,
- final String description, final String reference,
- final SchemaPath path) {
- this.typeName = Preconditions.checkNotNull(typeName, "type name must not be null.");
- this.baseType = Preconditions.checkNotNull(baseType, "base type must not be null");
- this.path = Preconditions.checkNotNull(path, "path must not be null.");
- this.description = description;
- this.reference = reference;
- }
-
- public Builder status(final Status status) {
- this.status = status;
- return this;
- }
-
- public Builder units(final String units) {
- this.units = units;
- return this;
- }
-
- public Builder defaultValue(final Object defaultValue) {
- this.defaultValue = defaultValue;
- return this;
- }
-
- public Builder addedByUses(final boolean addedByUses) {
- this.addedByUses = addedByUses;
- return this;
- }
-
- public Builder unknownSchemaNodes(
- final List<UnknownSchemaNode> unknownSchemaNodes) {
- if (unknownSchemaNodes.isEmpty()) {
- this.unknownSchemaNodes = Collections.emptyList();
- } else {
- this.unknownSchemaNodes = unknownSchemaNodes;
- }
- return this;
- }
-
- public Builder ranges(final List<RangeConstraint> ranges) {
- if (ranges != null) {
- this.ranges = ranges;
- }
- return this;
- }
-
- public Builder lengths(final List<LengthConstraint> lengths) {
- if (lengths != null) {
- this.lengths = lengths;
- }
- return this;
- }
-
- public Builder patterns(final List<PatternConstraint> patterns) {
- if (patterns != null) {
- this.patterns = patterns;
- }
- return this;
- }
-
- public Builder fractionDigits(final Integer fractionDigits) {
- this.fractionDigits = fractionDigits;
- return this;
- }
-
- public ExtendedType build() {
- return new ExtendedType(this);
- }
- }
-
- private ExtendedType(final Builder builder) {
- this.typeName = builder.typeName;
- this.baseType = builder.baseType;
- this.path = builder.path;
- this.description = builder.description;
- this.reference = builder.reference;
- this.unknownSchemaNodes = builder.unknownSchemaNodes;
- this.status = builder.status;
- this.units = builder.units;
- this.defaultValue = builder.defaultValue;
- this.addedByUses = builder.addedByUses;
-
- this.ranges = builder.ranges;
- this.lengths = builder.lengths;
- this.patterns = builder.patterns;
- this.fractionDigits = builder.fractionDigits;
- }
-
- @Override
- public TypeDefinition<?> getBaseType() {
- return baseType;
- }
-
- @Override
- public String getUnits() {
- return units;
- }
-
- @Override
- public Object getDefaultValue() {
- return defaultValue;
- }
-
- public boolean isAddedByUses() {
- return addedByUses;
- }
-
- @Override
- public QName getQName() {
- return typeName;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownSchemaNodes;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof ExtendedType)) {
- return false;
- }
-
- ExtendedType that = (ExtendedType) o;
- if (path != null ? !path.equals(that.path) : that.path != null) {
- return false;
- }
- if (typeName != null ? !typeName.equals(that.typeName) : that.typeName != null) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = typeName != null ? typeName.hashCode() : 0;
- result = 31 * result + (path != null ? path.hashCode() : 0);
- return result;
- }
-
- @Override
- public String toString() {
- return "ExtendedType [typeName=" +
- typeName +
- ", baseType=" +
- baseType +
- ", path=" +
- path +
- ", description=" +
- description +
- ", reference=" +
- reference +
- ", unknownSchemaNodes=" +
- unknownSchemaNodes +
- ", status=" +
- status +
- ", units=" +
- units +
- ", defaultValue=" +
- defaultValue +
- "]";
- }
-
- public List<RangeConstraint> getRangeConstraints() {
- return ranges;
- }
-
- public List<LengthConstraint> getLengthConstraints() {
- return lengths;
- }
-
- public List<PatternConstraint> getPatternConstraints() {
- return patterns;
- }
-
- public Integer getFractionDigits() {
- return fractionDigits;
- }
-}
nodeType = ((LeafSchemaNode) schemaNode).getType();
} else if (schemaNode instanceof LeafListSchemaNode) {
nodeType = ((LeafListSchemaNode) schemaNode).getType();
+ } else {
+ throw new IllegalArgumentException("Unsupported node " + schemaNode);
}
- if (nodeType instanceof ExtendedType) {
- while (nodeType.getBaseType() instanceof ExtendedType) {
- nodeType = nodeType.getBaseType();
- }
-
- QNameModule typeDefModuleQname = nodeType.getQName().getModule();
- return schemaContext.findModuleByNamespaceAndRevision(typeDefModuleQname.getNamespace(),
- typeDefModuleQname.getRevision());
- } else if (nodeType.getBaseType() != null) {
+ if (nodeType.getBaseType() != null) {
while (nodeType.getBaseType() != null) {
nodeType = nodeType.getBaseType();
}
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
/**
- * Compatibility utilities for dealing with differences between the {@link ExtendedType}-driven type representation
- * versus the representation this package models.
+ * Compatibility utilities for dealing with differences between the old parser's ExtendedType-driven type
+ * representation versus the representation this package models.
*
* @deprecated This class is provided strictly for compatibility only. No new users should be introduced, as this class
* is scheduled for removal when its two OpenDaylight users, Java Binding v1 and YANG JMX Bindings are
final TypeDefinition<?> leafType = leaf.getType();
Preconditions.checkNotNull(leafType);
- if (leafType instanceof ExtendedType) {
- // Old parser referring to a typedef
- return leafType;
- }
-
if (!leaf.getPath().equals(leafType.getPath())) {
// Old parser semantics, or no new default/units defined for this leaf
return leafType;
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import com.google.common.base.Optional;
-import java.util.Collections;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-
-public class ExtendedTypeTest {
- @Test
- public void canCreateExtendedType() {
- String namespace = "TestType";
- String revision = "2014-08-26";
- String localName = "testType";
- QName testType = QName.create(namespace, revision, localName);
- IntegerTypeDefinition int32 = BaseTypes.int32Type();
- String description = "This type is used for testing purpose";
- Optional<String> desc = Optional.of(description);
- String reference = "Test Reference";
- Optional<String> ref = Optional.of(reference);
-
- ExtendedType.Builder extendedTypeBuilder = ExtendedType.builder(testType, int32, desc, ref, SchemaPath.ROOT);
-
- int defValue = 12;
- extendedTypeBuilder.defaultValue(defValue);
-
- extendedTypeBuilder.status(Status.OBSOLETE);
- extendedTypeBuilder.addedByUses(false);
-
- int digits = 2;
- extendedTypeBuilder.fractionDigits(digits);
-
- String units = "KiloTest";
- extendedTypeBuilder.units(units);
-
- Number min = 3;
- Number max = 15;
- LengthConstraint lengthCons = BaseConstraints.newLengthConstraint(min, max, desc, ref);
- extendedTypeBuilder.lengths(Collections.singletonList(lengthCons));
-
- ExtendedType extendedType = extendedTypeBuilder.build();
-
- assertEquals("BaseType is int32", int32, extendedType.getBaseType());
- assertEquals("Description", description, extendedType.getDescription());
- assertEquals("Reference", reference, extendedType.getReference());
- assertEquals("Path", SchemaPath.ROOT, extendedType.getPath());
- assertEquals("Default Value is 12", defValue, extendedType.getDefaultValue());
- assertEquals("Status is OBSOLETE", Status.OBSOLETE, extendedType.getStatus());
- assertFalse("AddedByUses", extendedType.isAddedByUses());
- assertTrue("should be 2", digits == extendedType.getFractionDigits());
- assertTrue("Should contain description", extendedType.toString().contains(description));
- assertEquals("Units", units, extendedType.getUnits());
- assertEquals("Length Constraints", Collections.singletonList(lengthCons), extendedType.getLengthConstraints());
- assertTrue("Should contain name of type", extendedType.getQName().toString().contains(localName));
-
- assertEquals("extendedType should equals to itself",extendedType, extendedType);
- assertFalse("extendedType shouldn't equal to null", extendedType.equals(null));
- assertTrue("Hash code of unionType should be equal to itself",
- extendedType.hashCode() == extendedType.hashCode());
-
- }
-
-}
\ No newline at end of file