本文整理汇总了Java中org.onosproject.yangutils.datamodel.YangType.getDataType方法的典型用法代码示例。如果您正苦于以下问题:Java YangType.getDataType方法的具体用法?Java YangType.getDataType怎么用?Java YangType.getDataType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.onosproject.yangutils.datamodel.YangType
的用法示例。
在下文中一共展示了YangType.getDataType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isTypeEmpty
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* Returns the value as true if direct or referred type from leafref or
* derived points to empty data type; false otherwise.
*
* @param fieldValue value of the leaf
* @param dataType type of the leaf
* @return true if type is empty; false otherwise.
*/
private boolean isTypeEmpty(String fieldValue, YangType<?> dataType) {
if (fieldValue.equals(TRUE) || fieldValue.equals(FALSE)) {
switch (dataType.getDataType()) {
case EMPTY:
return true;
case LEAFREF:
YangLeafRef leafRef =
(YangLeafRef) dataType.getDataTypeExtendedInfo();
return isTypeEmpty(fieldValue,
leafRef.getEffectiveDataType());
case DERIVED:
YangDerivedInfo info =
(YangDerivedInfo) dataType
.getDataTypeExtendedInfo();
YangDataTypes type = info.getEffectiveBuiltInType();
return type == EMPTY;
default:
return false;
}
}
return false;
}
示例2: setPatternRestriction
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* Sets the pattern restriction to type.
*
* @param listener listener's object
* @param type Yang type for which pattern restriction to be set
* @param ctx context object of the grammar rule
*/
private static void setPatternRestriction(TreeWalkListener listener, YangType type,
GeneratedYangParser.PatternStatementContext ctx) {
if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) {
ParserException parserException = new ParserException("YANG file error : " +
YangConstructType.getYangConstructType(PATTERN_DATA) + " name " + ctx.string().getText() +
" can be used to restrict the built-in type string or types derived from string.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
// Validate and get valid pattern restriction string.
String patternArgument = getValidPattern(ctx);
if (type.getDataType() == YangDataTypes.STRING) {
YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
if (stringRestriction == null) {
stringRestriction = new YangStringRestriction();
type.setDataTypeExtendedInfo(stringRestriction);
stringRestriction.addPattern(patternArgument);
} else {
stringRestriction.addPattern(patternArgument);
}
listener.getParsedDataStack().push(stringRestriction);
} else {
YangPatternRestriction patternRestriction = (YangPatternRestriction) ((YangDerivedInfo<?>) type
.getDataTypeExtendedInfo()).getPatternRestriction();
if (patternRestriction == null) {
patternRestriction = new YangPatternRestriction();
((YangDerivedInfo<?>) type.getDataTypeExtendedInfo()).setPatternRestriction(patternRestriction);
patternRestriction.addPattern(patternArgument);
} else {
((YangDerivedInfo<?>) type.getDataTypeExtendedInfo()).setPatternRestriction(patternRestriction);
patternRestriction.addPattern(patternArgument);
}
}
}
示例3: getParseFromStringMethod
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* Returns from string method parsed string.
*
* @param targetDataType target data type
* @param yangType YANG type
* @return parsed string
*/
public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
YangDataTypes type = yangType.getDataType();
switch (type) {
case INT8:
return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
case INT16:
return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
case INT32:
return INTEGER_WRAPPER + PERIOD + PARSE_INT;
case INT64:
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT8:
return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
case UINT16:
return INTEGER_WRAPPER + PERIOD + PARSE_INT;
case UINT32:
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT64:
return NEW + SPACE + BIG_INTEGER;
case STRING:
return EMPTY_STRING;
case EMPTY:
case BOOLEAN:
return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
case DECIMAL64:
case BITS:
case BINARY:
case UNION:
case ENUMERATION:
case DERIVED:
return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
default:
throw new TranslatorException("given data type is not supported.");
}
}
示例4: getJavaDataType
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* Returns java type.
*
* @param yangType YANG type
* @return java type
*/
public static String getJavaDataType(YangType<?> yangType) {
YangDataTypes type = yangType.getDataType();
switch (type) {
case INT8:
return BYTE;
case INT16:
return SHORT;
case INT32:
return INT;
case INT64:
return LONG;
case UINT8:
return SHORT;
case UINT16:
return INT;
case UINT32:
return LONG;
case UINT64:
return BIG_INTEGER;
case BINARY:
return YANG_BINARY_CLASS;
case DECIMAL64:
return YANG_DECIMAL64_CLASS;
case STRING:
return STRING_DATA_TYPE;
case BOOLEAN:
return BOOLEAN_DATA_TYPE;
default:
throw new TranslatorException("given data type is not supported.");
}
}
示例5: isTypePrimitive
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* Returns true, if data type of leaf is primitive data type; false
* otherwise.
*
* @param yangType leaf type
* @return true if data type is primitive; false otherwise
*/
public static boolean isTypePrimitive(YangType yangType) {
if (yangType.getDataType() == LEAFREF) {
YangLeafRef leafRef =
(YangLeafRef) yangType.getDataTypeExtendedInfo();
return isPrimitiveDataType(leafRef.getEffectiveDataType()
.getDataType());
}
return isPrimitiveDataType(yangType.getDataType());
}
示例6: getStringFromType
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* Returns the string value from the respective data types of the
* leaf/leaf-list.
*
* @param holder leaf/leaf-list holder
* @param holderObj leaf/leaf-list holder object
* @param name leaf/leaf-list name
* @param fieldObj object of the leaf/leaf-list field
* @param dataType type of the leaf/leaf-list
* @return string value from the type
*/
public static String getStringFromType(YangSchemaNode holder, Object holderObj,
String name, Object fieldObj, YangType dataType) {
if (fieldObj == null) {
throw new YtbException("Value of " + holder.getName() + " is null");
}
YangDataTypes type = dataType.getDataType();
switch (type) {
case INT8:
case INT16:
case INT32:
case INT64:
case UINT8:
case UINT16:
case UINT32:
case UINT64:
case EMPTY:
case STRING:
case DECIMAL64:
case INSTANCE_IDENTIFIER:
case DERIVED:
case UNION:
case ENUMERATION:
case BOOLEAN:
return String.valueOf(fieldObj).trim();
case BITS:
return getBitsValue(holder, holderObj, name, fieldObj).trim();
case BINARY:
return Base64.getEncoder().encodeToString((byte[]) fieldObj);
case IDENTITYREF:
YangIdentityRef ir =
(YangIdentityRef) dataType.getDataTypeExtendedInfo();
if (ir.isInGrouping()) {
return String.valueOf(fieldObj).trim();
}
return getIdentityRefValue(fieldObj, ir, holderObj);
case LEAFREF:
YangLeafRef leafRef =
(YangLeafRef) dataType.getDataTypeExtendedInfo();
return getStringFromType(holder, holderObj, name, fieldObj,
leafRef.getEffectiveDataType());
default:
throw new YtbException("Unsupported data type. Cannot be " +
"processed.");
}
}
示例7: parseLeafRefTypeInfo
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* To set data into parent setter method from string value for leafref type.
*
* @param leafValue leaf value to be set
* @param parentSetterMethod the parent setter method to be invoked
* @param parentBuilderObject the parent build object on which to invoke
* the method
* @param ydtExtendedContext application context
* @throws InvocationTargetException if method could not be invoked
* @throws IllegalAccessException if method could not be accessed
* @throws NoSuchMethodException if method does not exist
*/
private static void parseLeafRefTypeInfo(YdtExtendedContext ydtExtendedContext,
Method parentSetterMethod,
Object parentBuilderObject,
String leafValue)
throws InvocationTargetException, IllegalAccessException,
NoSuchMethodException {
YangSchemaNode schemaNode = ydtExtendedContext.getYangSchemaNode();
while (schemaNode.getReferredSchema() != null) {
schemaNode = schemaNode.getReferredSchema();
}
YangLeafRef leafRef;
if (schemaNode instanceof YangLeaf) {
leafRef = (YangLeafRef) ((YangLeaf) schemaNode)
.getDataType().getDataTypeExtendedInfo();
} else {
leafRef = (YangLeafRef) ((YangLeafList) schemaNode)
.getDataType().getDataTypeExtendedInfo();
}
YangType type = leafRef.getEffectiveDataType();
if (type.getDataType() == YangDataTypes.DERIVED &&
schemaNode.getJavaPackage().equals(YobConstants.JAVA_LANG)) {
/*
* If leaf is inside grouping, then its return type will be of type
* Object and if its actual type is derived type then get the
* effective built-in type and set the value.
*/
YangDerivedInfo derivedInfo = (YangDerivedInfo) leafRef
.getEffectiveDataType()
.getDataTypeExtendedInfo();
YobUtils.setDataFromStringValue(derivedInfo.getEffectiveBuiltInType(),
leafValue, parentSetterMethod,
parentBuilderObject,
ydtExtendedContext);
} else {
YobUtils.setDataFromStringValue(type.getDataType(),
leafValue, parentSetterMethod,
parentBuilderObject,
ydtExtendedContext);
}
}
示例8: parseIdentityRefInfo
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* To set data into parent setter method from string value for identity ref.
*
* @param leafValue leaf value to be set
* @param parentSetterMethod the parent setter method to be invoked
* @param parentBuilderObject the parent build object on which to invoke
* the method
* @param ydtExtendedContext application context
* @throws InvocationTargetException if method could not be invoked
* @throws IllegalAccessException if method could not be accessed
* @throws NoSuchMethodException if method does not exist
*/
private static void parseIdentityRefInfo(YdtExtendedContext
ydtExtendedContext,
Method parentSetterMethod,
Object parentBuilderObject,
String leafValue)
throws InvocationTargetException, IllegalAccessException,
NoSuchMethodException {
Class<?> childSetClass = null;
Object childValue = null;
Method childMethod = null;
YangSchemaNode yangJavaModule = ydtExtendedContext.getYangSchemaNode();
while (yangJavaModule.getReferredSchema() != null) {
yangJavaModule = yangJavaModule.getReferredSchema();
}
String qualifiedClassName = null;
YangType type;
if (yangJavaModule instanceof YangLeaf) {
type = ((YangLeaf) yangJavaModule).getDataType();
} else {
type = ((YangLeafList) yangJavaModule).getDataType();
}
if (type.getDataType() == YangDataTypes.LEAFREF && yangJavaModule
.getJavaPackage().equals(YobConstants.JAVA_LANG)) {
YangLeafRef leafref = ((YangLeafRef) type.getDataTypeExtendedInfo());
YangType effectiveType = leafref.getEffectiveDataType();
if (effectiveType.getDataType() == YangDataTypes.IDENTITYREF) {
YangIdentityRef identityref = ((YangIdentityRef) effectiveType
.getDataTypeExtendedInfo());
YangIdentity identity = identityref.getReferredIdentity();
qualifiedClassName = identity.getJavaPackage() + PERIOD +
getCapitalCase(identity.getJavaClassNameOrBuiltInType());
}
} else {
qualifiedClassName = yangJavaModule.getJavaPackage() + PERIOD +
getCapitalCase(yangJavaModule.getJavaClassNameOrBuiltInType());
}
ClassLoader classLoader = getClassLoader(null, qualifiedClassName,
ydtExtendedContext, null);
try {
childSetClass = classLoader.loadClass(qualifiedClassName);
} catch (ClassNotFoundException e) {
log.error(L_FAIL_TO_LOAD_CLASS, qualifiedClassName);
}
if (childSetClass != null) {
childMethod = childSetClass
.getDeclaredMethod(FROM_STRING, String.class);
}
if (childMethod != null) {
childValue = childMethod.invoke(null, leafValue);
}
parentSetterMethod.invoke(parentBuilderObject, childValue);
}