public Annotation element(String key, String value) { elements.add(new Element(key, value)); return this; }
@Override public String toString() { boolean isFirst = true; StringBuilder definitionBuilder = new StringBuilder("@").append(name).append("( "); if (elements != null && elements.size() > 0) { for (Element element : elements) { if (!isFirst) { definitionBuilder.append(", "); } else { isFirst = false; } definitionBuilder.append(element.toString()); } } if (annotations != null && annotations.size() > 0) { for (Annotation annotation : annotations) { if (!isFirst) { definitionBuilder.append(", "); } else { isFirst = false; } definitionBuilder.append(annotation.toString()); } } definitionBuilder.append(")"); return definitionBuilder.toString(); }
for (Element aElement : annotation.getElements()) { if (elementName == null) { if (aElement.getKey() == null) { } else { throw new DuplicateAnnotationException("Annotation element @" + annotationName + "(...) " + "is defined twice", aElement.getQueryContextStartIndex(), aElement.getQueryContextEndIndex()); if (elementName.equalsIgnoreCase(aElement.getKey())) { } else { throw new DuplicateAnnotationException("Annotation element @" + annotationName + "(" + elementName + "=...) is defined twice", aElement.getQueryContextStartIndex(), aElement.getQueryContextEndIndex());
public Partition addQuery(Query query) { if (query == null) { throw new SiddhiAppValidationException("Query should not be null"); } String name = null; Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants .ANNOTATION_ELEMENT_NAME, query.getAnnotations()); if (element != null) { name = element.getValue(); } if (name != null && queryNameList.contains(name)) { throw new SiddhiAppValidationException("Cannot add Query as another Execution Element already uses " + "its name=" + name + " within the same Partition", element.getQueryContextStartIndex(), element.getQueryContextEndIndex()); } queryNameList.add(name); this.queryList.add(query); return this; }
/** * Util method used to convert a list of elements in an annotation to a comma-separated string. * * @param elements the list of annotation elements. * @return a comma-separated string of all elements in the list. */ public static String flattenAnnotatedElements(List<Element> elements) { StringBuilder sb = new StringBuilder(); elements.forEach(elem -> { sb.append(elem.getValue()); if (elements.indexOf(elem) != elements.size() - 1) { sb.append(RDBMSTableConstants.SEPARATOR); } }); return sb.toString(); }
/** * Generates config for a Mapper * @param mapAnnotation Siddhi annotation that contains details of a Siddhi Mapper * @return MapperConfig object * @throws DesignGenerationException Error while generating MapperConfig */ private MapperConfig generateMapperConfig(Annotation mapAnnotation) throws DesignGenerationException { String type = null; List<String> options = new ArrayList<>(); for (Element element : mapAnnotation.getElements()) { if (element.getKey().equalsIgnoreCase(TYPE)) { type = element.getValue(); } else { options.add(element.toString()); } } if (type == null) { throw new DesignGenerationException("Unable to find 'type' of the mapper"); } MapperPayloadOrAttribute payloadOrAttribute = null; if (!mapAnnotation.getAnnotations().isEmpty()) { payloadOrAttribute = generateMapperPayloadOrAttributes(mapAnnotation.getAnnotations().get(0)); } MapperConfig mapperConfig = new MapperConfig(type, options, payloadOrAttribute); preserveAndBindCodeSegment(mapAnnotation, mapperConfig); return mapperConfig; }
/** * Get user preference on creating kafka topics from {@link org.wso2.carbon.sp.jobmanager.core.SiddhiAppCreator}. * If no value is defined 'true' is returned */ private boolean isTransportChannelCreationEnabled(List<Annotation> annotationList) { Element element = AnnotationHelper.getAnnotationElement( SiddhiTopologyCreatorConstants.TRANSPORT_CHANNEL_CREATION_IDENTIFIER, null, annotationList); if (element == null) { return true; } else { return Boolean.valueOf(element.getValue()); } }
public SiddhiApp addQuery(Query query) { if (query == null) { throw new SiddhiAppValidationException("Query should not be null"); } String name = null; Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants .ANNOTATION_ELEMENT_NAME, query.getAnnotations()); if (element != null) { name = element.getValue(); } if (name != null && executionElementNameList.contains(name)) { throw new SiddhiAppValidationException( "Cannot add Query as another Execution Element already uses " + "its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex()); } executionElementNameList.add(name); this.executionElementList.add(query); return this; }
List<String> options = new ArrayList<>(); for (Element element : sourceOrSinkAndConnectedElement.getKey().getElements()) { if (element.getKey().equalsIgnoreCase(TYPE)) { type = element.getValue(); } else { options.add(element.toString()); if (element.getKey().equalsIgnoreCase(SINK_ID) || element.getKey().equalsIgnoreCase(SOURCE_ID)) { correlationId = element.getValue();
for (Element aElement : annotation.getElements()) { if (elementName == null) { if (aElement.getKey() == null) { } else { throw new DuplicateAnnotationException("Annotation element @" + annotationName + "(...) " + "is defined twice", aElement.getQueryContextStartIndex(), aElement.getQueryContextEndIndex()); if (elementName.equalsIgnoreCase(aElement.getKey())) { } else { throw new DuplicateAnnotationException("Annotation element @" + annotationName + "(" + elementName + "=...) is defined twice", aElement.getQueryContextStartIndex(), aElement.getQueryContextEndIndex());
/** * Get parallel value of the execGroup if given by the user unless default parallel. * {@link SiddhiTopologyCreatorConstants#DEFAULT_PARALLEL} value is returned */ private int getExecGroupParallel(ExecutionElement executionElement) { Element element = AnnotationHelper.getAnnotationElement(SiddhiTopologyCreatorConstants.DISTRIBUTED_IDENTIFIER, SiddhiTopologyCreatorConstants.PARALLEL_IDENTIFIER, executionElement.getAnnotations()); if (element == null) { return SiddhiTopologyCreatorConstants.DEFAULT_PARALLEL; } else { return Integer.parseInt(element.getValue()); } }
public SiddhiApp addPartition(Partition partition) { if (partition == null) { throw new SiddhiAppValidationException("Partition should not be null"); } String name = null; Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants .ANNOTATION_ELEMENT_NAME, partition.getAnnotations()); if (element != null) { name = element.getValue(); } if (name != null && executionElementNameList.contains(name)) { throw new SiddhiAppValidationException( "Cannot add Partition as another Execution Element already " + "uses its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex()); } executionElementNameList.add(name); this.executionElementList.add(partition); return this; }
public Annotation element(String value) { elements.add(new Element(null, value)); return this; }
@Override public String toString() { boolean isFirst = true; StringBuilder definitionBuilder = new StringBuilder("@").append(name).append("( "); if (elements != null && elements.size() > 0) { for (Element element : elements) { if (!isFirst) { definitionBuilder.append(", "); } else { isFirst = false; } definitionBuilder.append(element.toString()); } } if (annotations != null && annotations.size() > 0) { for (Annotation annotation : annotations) { if (!isFirst) { definitionBuilder.append(", "); } else { isFirst = false; } definitionBuilder.append(annotation.toString()); } } definitionBuilder.append(")"); return definitionBuilder.toString(); }
/** * Traverse annotations and returns the name * * @param annotations * @return */ private static String getName(List<Annotation> annotations) { String name = UUID.randomUUID().toString(); if (annotations != null) { for (Annotation annotation : annotations) { if (annotation.getName().equals(EventProcessorConstants.NAME)) { name = annotation.getElements().get(0).getValue(); } } } return name; }
/** * Generates a PayloadOrAttributeElement object from the given Siddhi Element object * @param element Siddhi Element object * @return PayloadOrAttributeElement object */ private PayloadOrAttributeElement generatePayloadOrAttributesElement(Element element) { PayloadOrAttributeElement payloadOrAttributeElement = new PayloadOrAttributeElement(); payloadOrAttributeElement.key = element.getKey(); payloadOrAttributeElement.value = element.getValue(); return payloadOrAttributeElement; }
public SiddhiApp addQuery(Query query) { if (query == null) { throw new SiddhiAppValidationException("Query should not be null"); } String name = null; Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants .ANNOTATION_ELEMENT_NAME, query.getAnnotations()); if (element != null) { name = element.getValue(); } if (name != null && executionElementNameList.contains(name)) { throw new SiddhiAppValidationException( "Cannot add Query as another Execution Element already uses " + "its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex()); } executionElementNameList.add(name); this.executionElementList.add(query); return this; }
public Annotation element(String key, String value) { elements.add(new Element(key, value)); return this; }