private boolean isNullObj(BMap<String, BValue> jBMap) { return jBMap.hasKey(NULL_OBJ); }
/** * Check whether JSON has particular field. * * @param json JSON to be considered. * @param elementName String name json field to be considered. * @return Boolean 'true' if JSON has given field. */ public static boolean hasElement(BRefType<?> json, String elementName) { if (json.getType().getTag() != TypeTags.MAP_TAG) { return false; } return ((BMap<String, BValue>) json).hasKey(elementName); }
private String resolveTargetTypeName(Class<?> targetType, BMap<String, BValue> jBMap) { if (jBMap.hasKey(TYPE_TAG)) { BValue jType = jBMap.get(TYPE_TAG); return jType.stringValue(); } else if (targetType != null) { return ObjectHelper.getTrimmedClassName(targetType); } throw new IllegalStateException("Target type should either come from jBMap or via targetType param"); }
public void execute(Context ctx) { BMap<String, BValue> map = (BMap<String, BValue>) ctx.getRefArgument(0); String key = ctx.getStringArgument(0); ctx.setReturnValues(new BBoolean(map.hasKey(key))); } }
private Object findExistingReference(BMap<String, BValue> jBMap) { if (!jBMap.hasKey(EXISTING_TAG)) { return null; } BInteger existingObjId = (BInteger) jBMap.get(EXISTING_TAG); Object existingObjRef = getExistingObjRef(existingObjId.intValue()); if (existingObjRef == null) { throw new BallerinaException("Can not find existing reference: " + existingObjId); } return existingObjRef; }
/** * Create a empty java object instance for target type. * * @param jsonNode Data to be populated. * @param target type of which the object to be created. * @return instance of given type. */ private Object createInstance(BMap<String, BValue> jsonNode, Class<?> target) { if (target != null && Enum.class.isAssignableFrom(target)) { return createEnumInstance(jsonNode); } if (jsonNode.hasKey(TYPE_TAG)) { BValue typeNode = jsonNode.get(TYPE_TAG); String type = typeNode.stringValue(); if (type.equals(ARRAY_TAG)) { return createArrayInstance(jsonNode); } return getObjectOf(type); } return getObjectOf(target); }
@SuppressWarnings("unchecked") private Object deserializeMap(BMap<String, BValue> payload, Map target) { BValue complexKeyMap = payload.get(COMPLEX_KEY_MAP_TAG); if (complexKeyMap instanceof BMap) { return deserializeComplexKeyMap((BMap<String, BValue>) complexKeyMap, payload, target); } for (String key : payload.keys()) { if (key.equals(COMPLEX_KEY_MAP_TAG)) { // don't process this entry here, as this is the complex key-map entry continue; } BValue value = payload.get(key); Class<?> fieldType = Object.class; if (value instanceof BMap) { BMap<String, BValue> item = (BMap<String, BValue>) value; if (item.hasKey(TYPE_TAG)) { BValue val = item.get(TYPE_TAG); String typeName = val.stringValue(); fieldType = findClass(typeName); } } else if (value instanceof BBoolean) { fieldType = BBoolean.class; } target.put(key, deserialize(value, fieldType)); } return target; }
for (Map.Entry<String, BField> tFieldEntry : tFields.entrySet()) { String fieldName = tFieldEntry.getKey(); if (!jsonObject.hasKey(fieldName)) { return false;
private Descriptors.FileDescriptor getFileDescriptor(String rootDescriptor, BMap<String, BValue> descriptorMap) throws InvalidProtocolBufferException, Descriptors.DescriptorValidationException { byte[] descriptor = hexStringToByteArray(rootDescriptor); if (descriptor.length == 0) { throw new ClientRuntimeException("Error while reading the service proto descriptor. input descriptor " + "string is null."); } DescriptorProtos.FileDescriptorProto descriptorProto = DescriptorProtos.FileDescriptorProto.parseFrom (descriptor); if (descriptorProto == null) { throw new ClientRuntimeException("Error while reading the service proto descriptor. File proto descriptor" + " is null."); } Descriptors.FileDescriptor[] fileDescriptors = new Descriptors.FileDescriptor[descriptorProto .getDependencyList().size()]; int i = 0; for (ByteString dependency : descriptorProto.getDependencyList().asByteStringList()) { if (descriptorMap.hasKey(dependency.toStringUtf8())) { fileDescriptors[i++] = getFileDescriptor(descriptorMap.get(dependency.toString(Charset.forName ("UTF8"))).stringValue(), descriptorMap); } } if (fileDescriptors.length > 0 && i == 0) { throw new ClientRuntimeException("Error while reading the service proto descriptor. Couldn't find any " + "dependent descriptors."); } return Descriptors.FileDescriptor.buildFrom(descriptorProto, fileDescriptors); }
private static void processAnnotations(String pkgPath, ProgramFile programFile, AnnotatableNode annotatableNode) { final BMap bMap = getAnnotationVariable(pkgPath, programFile); if (!bMap.hasKey(annotatableNode.getAnnotationEntryKey())) { return; } final BValue map = bMap.get(annotatableNode.getAnnotationEntryKey()); if (map == null || map.getType().getTag() != BTypes.typeMap.getTag()) { return; } BMap<String, BValue> annotationMap = (BMap<String, BValue>) map; for (String key : annotationMap.keys()) { final BMap<String, BValue> annotationData = (BMap<String, BValue>) annotationMap.get(key); StructImpl struct = null; if (annotationData != null) { struct = new StructImpl(annotationData); } final String annotaionQName = key.split("\\$")[0]; final String[] qNameParts = annotaionQName.split(":"); final AnnotationImpl annotation = new AnnotationImpl(qNameParts[1], qNameParts[0], struct); annotatableNode.addAnnotation(annotaionQName, annotation); } } }
@SuppressWarnings("unchecked") private Object deserializeInto(Object instance, BMap<String, BValue> data, Class<?> targetType) { BValue valueNode = data.get(VALUE_TAG); if (data.hasKey(TYPE_TAG)) { BValue type = data.get(TYPE_TAG); switch (type.stringValue()) { case MAP_TAG: return deserializeMap((BMap<String, BValue>) valueNode, (Map) instance); case LIST_TAG: return deserializeList((BValueArray) valueNode, targetType, (List) instance); case ENUM_TAG: return instance; case ARRAY_TAG: return deserializeBRefValueArray((BValueArray) valueNode, instance); default: // no op } } /* If all the data are contained in data it self, use data as valueNode */ if (valueNode == null) { valueNode = data; } return deserializeReflectively(instance, (BMap<String, BValue>) valueNode); }
private BMap<String, BRefType<?>> setDataSourcePropertiesMap(BMap<String, BRefType<?>> dataSourceConfigMap, String jdbcurl, String username, String password) { if (dataSourceConfigMap != null) { if (!dataSourceConfigMap.hasKey(Constants.URL)) { dataSourceConfigMap.put(Constants.URL, new BString(jdbcurl)); } } else { dataSourceConfigMap = new BMap<>(); dataSourceConfigMap.put(Constants.URL, new BString(jdbcurl)); } dataSourceConfigMap.put(Constants.USER, new BString(username)); dataSourceConfigMap.put(Constants.PASSWORD, new BString(password)); return dataSourceConfigMap; }
if (fieldDescriptor.isRepeated()) { BValueArray floatArray = new BValueArray(BTypes.typeFloat); if (bMapValue.hasKey(name)) { floatArray = (BValueArray) bMapValue.get(name); if (fieldDescriptor.isRepeated()) { BValueArray floatArray = new BValueArray(BTypes.typeFloat); if (bMapValue.hasKey(name)) { floatArray = (BValueArray) bMapValue.get(name); if (fieldDescriptor.isRepeated()) { BValueArray intArray = new BValueArray(BTypes.typeInt); if (bMapValue.hasKey(name)) { intArray = (BValueArray) bMapValue.get(name); if (fieldDescriptor.isRepeated()) { BValueArray intArray = new BValueArray(BTypes.typeInt); if (bMapValue.hasKey(name)) { intArray = (BValueArray) bMapValue.get(name); if (fieldDescriptor.isRepeated()) { BValueArray intArray = new BValueArray(BTypes.typeInt); if (bMapValue.hasKey(name)) { intArray = (BValueArray) bMapValue.get(name); if (fieldDescriptor.isRepeated()) { BValueArray intArray = new BValueArray(BTypes.typeInt); if (bMapValue.hasKey(name)) { intArray = (BValueArray) bMapValue.get(name);
switch (fieldDescriptor.getType().toProto().getNumber()) { case DescriptorProtos.FieldDescriptorProto.Type.TYPE_DOUBLE_VALUE: { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) {
try { if (!jsonObject.hasKey(fieldName)) { bStruct.put(fieldName, fieldType.getZeroValue()); continue;
switch (fieldDescriptor.getType().toProto().getNumber()) { case DescriptorProtos.FieldDescriptorProto.Type.TYPE_DOUBLE_VALUE: { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) { if (bMapValue != null && bMapValue.hasKey(fieldDescriptor.getName())) { BValue bValue = bMapValue.getIfExist(fieldDescriptor.getName()); if (bValue.getType().getTag() == TypeTags.ARRAY_TAG) {
BType fieldType = fieldInfo.getFieldType(); boolean containsField = bMap.hasKey(key); if (!containsField) { DefaultValueAttributeInfo defaultValAttrInfo = (DefaultValueAttributeInfo)