@Override public BPacket toBValue(BString bString, BValueSerializer serializer) { if (bString.stringValue() == null) { return BPacket.from(B_STRING, null); } return BPacket.from(B_STRING, bString); }
/** * {@inheritDoc} */ @Override public BString getTextValue() { StringBuilder seqTextBuilder = new StringBuilder(); for (int i = 0; i < sequence.size(); i++) { BXMLItem item = (BXMLItem) sequence.getRefValue(i); seqTextBuilder.append(item.getTextValue().stringValue()); } return new BString(seqTextBuilder.toString()); }
/** * {@inheritDoc} */ @Override public BXML<?> elements(String qname) { BValueArray elementsSeq = new BValueArray(); switch (nodeType) { case ELEMENT: if (getElementName().stringValue().equals(getQname(qname).toString())) { elementsSeq.add(0, this); } break; default: break; } return new BXMLSequence(elementsSeq); }
private Object createArrayInstance(BMap<String, BValue> jsonNode) { BString ct = (BString) jsonNode.get(COMPONENT_TYPE); String componentType = ct.stringValue(); BInteger bSize = (BInteger) jsonNode.get(LENGTH_TAG); int size = (int) bSize.intValue(); Class<?> clazz = findClass(componentType); if (clazz != null) { return Array.newInstance(clazz, size); } throw new BallerinaException("Can not create array instance of: " + componentType + "[]"); }
switch (algorithm.stringValue()) { case "SHA1": hashAlgorithm = "SHA-1";
public Descriptor build() throws IOException { try (InputStream targetStream = new ByteArrayInputStream(descriptorData)) { DescriptorProtos.FileDescriptorProto fileDescriptorSet = DescriptorProtos.FileDescriptorProto .parseFrom(targetStream); return new Descriptor(fileDescriptorSet.getName(), new BString(bytesToHex(descriptorData)) .stringValue()); } } }
/** * {@inheritDoc} */ @Override public BXML<?> elements(String qname) { BValueArray elementsSeq = new BValueArray(BTypes.typeXML); String qnameStr = getQname(qname).toString(); int j = 0; for (int i = 0; i < sequence.size(); i++) { BXMLItem item = (BXMLItem) sequence.getRefValue(i); if (item.getNodeType() == XMLNodeType.ELEMENT && item.getElementName().stringValue().equals(qnameStr)) { elementsSeq.add(j++, item); } } return new BXMLSequence(elementsSeq); }
switch (algorithm.stringValue()) { case "SHA1": hmacAlgorithm = "HmacSHA1";
@Override public void execute(Context context) { String configKey = context.getStringArgument(0); BString type = (BString) context.getNullableRefArgument(0); // TODO: Add a try-catch switch (type.stringValue()) { case "STRING": String val = configRegistry.getAsString(configKey); context.setReturnValues(val != null ? new BString(val) : null); break; case "INT": context.setReturnValues(new BInteger(configRegistry.getAsInt(configKey))); break; case "FLOAT": context.setReturnValues(new BFloat(configRegistry.getAsFloat(configKey))); break; case "BOOLEAN": context.setReturnValues(new BBoolean(configRegistry.getAsBoolean(configKey))); break; case "MAP": context.setReturnValues(buildBMap(configRegistry.getAsMap(configKey))); break; default: throw new IllegalStateException("invalid value type: " + type.stringValue()); } }