/** * {@inheritDoc} */ @Override public BMap<?, ?> getAttributesMap() { if (sequence.size() == 1) { return ((BXMLItem) sequence.getRefValue(0)).getAttributesMap(); } return new BMap<>(new BMapType(BTypes.typeString)); }
private BMap<String, BString> getTags(MetricId metricId) { BMap<String, BString> bTags = new BMap<>(new BMapType(BTypes.typeString)); Set<Tag> tags = metricId.getTags(); for (Tag tag : tags) { bTags.put(tag.getKey(), new BString(tag.getValue())); } return bTags; } }
private BMap<String, BString> getTags(MetricId metricId) { BMap<String, BString> bTags = new BMap<>(new BMapType(BTypes.typeString)); Set<Tag> tags = metricId.getTags(); for (Tag tag : tags) { bTags.put(tag.getKey(), new BString(tag.getValue())); } return bTags; } }
/** * {@inheritDoc} */ @Override public BMap<?, ?> getAttributesMap() { BMap<String, BString> attrMap = new BMap<>(new BMapType(BTypes.typeString)); if (nodeType != XMLNodeType.ELEMENT) { return attrMap; } OMNamespace defaultNs = ((OMElement) omNode).getDefaultNamespace(); String namespaceOfPrefix = '{' + (defaultNs == null ? XMLConstants.XMLNS_ATTRIBUTE_NS_URI : defaultNs.getNamespaceURI()) + '}'; Iterator<OMNamespace> namespaceIterator = ((OMElement) omNode).getAllDeclaredNamespaces(); while (namespaceIterator.hasNext()) { OMNamespace namespace = namespaceIterator.next(); String prefix = namespace.getPrefix(); if (prefix.isEmpty()) { continue; } attrMap.put(namespaceOfPrefix + prefix, new BString(namespace.getNamespaceURI())); } Iterator<OMAttribute> attrIterator = ((OMElement) omNode).getAllAttributes(); while (attrIterator.hasNext()) { OMAttribute attr = attrIterator.next(); attrMap.put(attr.getQName().toString(), new BString(attr.getAttributeValue())); } return attrMap; }
@Override public BType getConstrainedType(char typeChar, BType constraint) { switch (typeChar) { case 'J': if (constraint == null) { return BTypes.typeJSON; } return new BJSONType(constraint); case 'D': if (constraint == null) { return BTypes.typeTable; } return new BTableType(constraint); case 'M': if (constraint == null || constraint == BTypes.typeAny) { return BTypes.typeMap; } return new BMapType(constraint); case 'H': return new BStreamType(constraint); case 'G': case 'T': case 'X': case 'Q': default: return constraint; } }
@Override public void receive(Event[] events) { BValueArray outputArray = new BValueArray(new BMapType(structType)); int j = 0; for (Event event : events) { // Here it is assumed that an event data will contain all the fields // of the record. Otherwise, some fields will be missing from the record value. BMap<String, BValue> output = new BMap<String, BValue>(structType); Iterator<String> fieldNamesIterator = structType.getFields().keySet().iterator(); for (Object field : event.getData()) { if (field instanceof Long || field instanceof Integer) { output.put(fieldNamesIterator.next(), new BInteger(((Number) field).longValue())); } else if (field instanceof Double || field instanceof Float) { output.put(fieldNamesIterator.next(), new BFloat(((Number) field).doubleValue())); } else if (field instanceof Boolean) { output.put(fieldNamesIterator.next(), new BBoolean(((Boolean) field))); } else if (field instanceof String) { output.put(fieldNamesIterator.next(), new BString((String) field)); } } outputArray.add(j, output); j++; } List<BValue> argsList = new ArrayList<>(); argsList.addAll(closureArgs); argsList.add(outputArray); BVMExecutor.executeFunction(functionPointer.value().getPackageInfo().getProgramFile(), functionPointer.value(), argsList.toArray(new BValue[0])); } });
@Override public void execute(Context context) { try { BMap<String, BValue> requestStruct = ((BMap<String, BValue>) context.getRefArgument(0)); HttpCarbonMessage httpCarbonMessage = (HttpCarbonMessage) requestStruct .getNativeData(HttpConstants.TRANSPORT_MESSAGE); BMapType mapType = new BMapType(BTypes.typeString); if (httpCarbonMessage.getProperty(HttpConstants.QUERY_STR) != null) { String queryString = (String) httpCarbonMessage.getProperty(HttpConstants.QUERY_STR); BMap<String, BString> params = new BMap<>(mapType); URIUtil.populateQueryParamMap(queryString, params); context.setReturnValues(params); } else { context.setReturnValues(new BMap<>(mapType)); } } catch (Exception e) { throw new BallerinaException("Error while retrieving query param from message: " + e.getMessage()); } } }
BType anydataMapType = new BMapType(type); if (checkIsLikeType(value, anydataMapType)) { return anydataMapType;