@Override protected boolean matchesSafely(DataType otherDataType) { return dataType.isCompatibleWith(otherDataType); }
/** * Creates a new {@link DefaultExtensionNotification} validating that the {@code actionDefinition} type information matches the * actual data to use. * * @param event the {@link Event} associated to the notification * @param component the {@link Component} associated to the notification * @param actionDefinition the {@link NotificationActionDefinition} to use * @param data the information to expose * @throws IllegalArgumentException when the {@code actionDefinition} type doesn't match {@code data} */ public DefaultExtensionNotification(Event event, Component component, NotificationActionDefinition actionDefinition, TypedValue<?> data) { DataType actualDataType = data.getDataType(); DataType expectedDataType = actionDefinition.getDataType(); checkArgument(expectedDataType.isCompatibleWith(actualDataType), () -> format("The action data type (%s) does not match the actual data type received (%s)", expectedDataType, actualDataType)); this.event = event; this.component = component; this.actionDefinition = actionDefinition; this.data = () -> data; }
/** * Creates a new {@link DefaultExtensionNotification} validating that the {@code actionDefinition} type information matches the * actual data to use. * * @param event the {@link Event} associated to the notification * @param component the {@link Component} associated to the notification * @param actionDefinition the {@link NotificationActionDefinition} to use * @param dataValue a supplier for the information to expose * @param actualDataType the data type of the information to expose * @throws IllegalArgumentException when the {@code actionDefinition} type doesn't match {@code data} */ public DefaultExtensionNotification(Event event, Component component, NotificationActionDefinition actionDefinition, Supplier<?> dataValue, DataType actualDataType) { DataType expectedDataType = actionDefinition.getDataType(); checkArgument(expectedDataType.isCompatibleWith(actualDataType), () -> format("The action data type (%s) does not match the actual data type received (%s)", expectedDataType, actualDataType)); this.event = event; this.component = component; this.actionDefinition = actionDefinition; this.data = new LazyValue<>(() -> new TypedValue<>(dataValue.get(), actualDataType)); }
@Override protected boolean matchesSafely(DataType otherDataType) { return dataType.isCompatibleWith(otherDataType); }
/** * Determines whether that data type passed in is supported by this transformer * * @param dataType the type to check against * @param exactMatch if set to true, this method will look for an exact match to the data type, if false it will look for a * compatible data type. * @return true if the source type is supported by this transformer, false otherwise */ public boolean isSourceDataTypeSupported(DataType dataType, boolean exactMatch) { int numTypes = sourceTypes.size(); if (numTypes == 0) { return !exactMatch; } for (DataType sourceType : sourceTypes) { if (exactMatch) { if (sourceType.equals(dataType)) { return true; } } else { if (sourceType.isCompatibleWith(dataType)) { return true; } } } return false; }
List<DataType> getSuperVertexes(DataType vertex) { //Use the parent's method to check if the actual vertex exists if (super.containsVertex(vertex)) { return asList(vertex); } return vertexSet().stream().filter(graphVertex -> graphVertex.isCompatibleWith(vertex)).collect(toList()); }
private List<List<TransformationEdge>> findTransformationPaths(DataType source, DataType target, Set<DataType> visited) { List<List<TransformationEdge>> validTransformationEdges = new LinkedList<>(); if (visited.contains(source)) { return validTransformationEdges; } else { visited.add(source); Set<TransformationEdge> transformationEdges = graph.outgoingEdgesOf(source); for (TransformationEdge transformationEdge : transformationEdges) { DataType edgeTarget = graph.getEdgeTarget(transformationEdge); if (target.isCompatibleWith(edgeTarget)) { LinkedList<TransformationEdge> transformationEdges1 = new LinkedList<>(); transformationEdges1.add(transformationEdge); validTransformationEdges.add(transformationEdges1); } else { List<List<TransformationEdge>> newTransformations = findTransformationPaths(edgeTarget, target, visited); for (List<TransformationEdge> transformationEdgeList : newTransformations) { transformationEdgeList.add(0, transformationEdge); validTransformationEdges.add(transformationEdgeList); } } } visited.remove(source); } return validTransformationEdges; }
@Override public boolean isCompatibleWith(DataType dataType) { if (!(dataType instanceof DefaultMapDataType)) { return false; } if (!super.isCompatibleWith(dataType)) { return false; } DefaultMapDataType that = (DefaultMapDataType) dataType; return getKeyDataType().isCompatibleWith(that.getKeyDataType()) && getValueDataType().isCompatibleWith(that.getValueDataType()); }
@Override public boolean isCompatibleWith(DataType dataType) { if (!(dataType instanceof DefaultCollectionDataType)) { return false; } if (!super.isCompatibleWith(dataType)) { return false; } DefaultCollectionDataType that = (DefaultCollectionDataType) dataType; return getItemDataType().isCompatibleWith(that.getItemDataType()); }
/** * Creates a new {@link DefaultExtensionNotification} validating that the {@code actionDefinition} type information matches the * actual data to use. * * @param event the {@link Event} associated to the notification * @param component the {@link Component} associated to the notification * @param actionDefinition the {@link NotificationActionDefinition} to use * @param data the information to expose * @throws IllegalArgumentException when the {@code actionDefinition} type doesn't match {@code data} */ public DefaultExtensionNotification(Event event, Component component, NotificationActionDefinition actionDefinition, TypedValue<?> data) { DataType actualDataType = data.getDataType(); DataType expectedDataType = actionDefinition.getDataType(); checkArgument(expectedDataType.isCompatibleWith(actualDataType), () -> format("The action data type (%s) does not match the actual data type received (%s)", expectedDataType, actualDataType)); this.event = event; this.component = component; this.actionDefinition = actionDefinition; this.data = data; }
continue; if (result.isCompatibleWith(transformer.getReturnDataType()) && transformer.isSourceDataTypeSupported(source)) { results.add(transformer);
if (((CollectionDataType) routeVars.get(key).getDataType()).getItemDataType().isCompatibleWith(value.getDataType())) {
@Override public Object doTransform(Object src, Charset outputEncoding) throws TransformerException { try { String data; if (src instanceof byte[]) { data = new String((byte[]) src, outputEncoding); } else if (src instanceof CursorStreamProvider) { data = handleStream(((CursorStreamProvider) src).openCursor(), outputEncoding); } else if (src instanceof InputStream) { data = handleStream((InputStream) src, outputEncoding); } else { data = (String) src; } byte[] result = Base64.decode(data); if (STRING.isCompatibleWith(getReturnDataType())) { return new String(result, outputEncoding); } else { return result; } } catch (Exception ex) { throw new TransformerException(transformFailed("base64", getReturnDataType()), this, ex); } }
/** * Checks whether a given value is a valid output for a transformer. * * @param transformer the transformer used to validate * @param value the output value * @throws TransformerException if the output value is of a unexpected type. */ public static void checkTransformerReturnClass(Transformer transformer, Object value) throws TransformerException { if (value == null && (transformer instanceof AbstractTransformer && ((AbstractTransformer) transformer).isAllowNullReturn())) { return; } if (transformer.getReturnDataType() != null) { DataTypeParamsBuilder dtBuilder = DataType.builder().fromObject(value); if (!(value instanceof DataHandler) && !(value instanceof DataSource)) { // To avoid getting an error because the DataType was constructed with a default mediaType dtBuilder = dtBuilder.mediaType(transformer.getReturnDataType().getMediaType()); } DataType dt = dtBuilder.build(); if (!transformer.getReturnDataType().isCompatibleWith(dt)) { throw new TransformerException(transformUnexpectedType(dt, transformer.getReturnDataType()), transformer); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("The transformed value is of expected type. Type is: " + ClassUtils.getSimpleName(value.getClass())); } }
if (DataType.STRING.isCompatibleWith(returnDataType)) { return new String(buffer, outputEncoding); } else if (!DataType.OBJECT.isCompatibleWith(returnDataType) && !DataType.BYTE_ARRAY.isCompatibleWith(returnDataType)) { try { return muleContext.getObjectSerializer().getExternalProtocol().deserialize(buffer);
if (resultType.isCompatibleWith(dataType)) { return (T) message.getPayload().getValue();