本文整理汇总了Java中org.onosproject.yangutils.datamodel.YangType.getDataTypeExtendedInfo方法的典型用法代码示例。如果您正苦于以下问题:Java YangType.getDataTypeExtendedInfo方法的具体用法?Java YangType.getDataTypeExtendedInfo怎么用?Java YangType.getDataTypeExtendedInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.onosproject.yangutils.datamodel.YangType
的用法示例。
在下文中一共展示了YangType.getDataTypeExtendedInfo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypDefsPackage
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* Returns java package for typedef node.
*
* @param type YANG type
* @param conflictResolver object of YANG to java naming conflict util
* @return java package for typedef node
*/
private static String getTypDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
Object var = type.getDataTypeExtendedInfo();
if (!(var instanceof YangDerivedInfo)) {
throw new TranslatorException("type should have been derived.");
}
if (!(((YangDerivedInfo<?>) var).getReferredTypeDef() instanceof YangTypeDef)) {
throw new TranslatorException("derived info is not an instance of typedef.");
}
YangJavaTypeDef typedef = (YangJavaTypeDef) ((YangDerivedInfo<?>) var).getReferredTypeDef();
if (typedef.getJavaFileInfo().getPackage() == null) {
return getPackageFromParent(typedef.getParent(), conflictResolver);
}
return typedef.getJavaFileInfo().getPackage();
}
示例2: 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;
}
示例3: 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);
}
}
}
示例4: getUnionPackage
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* Returns java package for union node.
*
* @param type YANG type
* @param conflictResolver object of YANG to java naming conflict util
* @return java package for union node
*/
private static String getUnionPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) {
throw new TranslatorException("type should have been union.");
}
YangJavaUnion union = (YangJavaUnion) type.getDataTypeExtendedInfo();
if (union.getJavaFileInfo().getPackage() == null) {
return getPackageFromParent(union.getParent(), conflictResolver);
}
return union.getJavaFileInfo().getPackage();
}
示例5: getEnumsPackage
import org.onosproject.yangutils.datamodel.YangType; //导入方法依赖的package包/类
/**
* Returns YANG enumeration's java package.
*
* @param type YANG type
* @param conflictResolver object of YANG to java naming conflict util
* @return YANG enumeration's java package
*/
private static String getEnumsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) {
throw new TranslatorException("type should have been enumeration.");
}
YangJavaEnumeration enumeration = (YangJavaEnumeration) type.getDataTypeExtendedInfo();
if (enumeration.getJavaFileInfo().getPackage() == null) {
return getPackageFromParent(enumeration.getParent(), conflictResolver);
}
return enumeration.getJavaFileInfo().getPackage();
}
示例6: 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());
}
示例7: 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.");
}
}
示例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);
}