public boolean isStreamDefinitionValidForConfiguration( EventBuilderConfiguration eventBuilderConfiguration, StreamDefinition exportedStreamDefinition) { if (!(eventBuilderConfiguration.getToStreamName().equals(exportedStreamDefinition.getName()) && eventBuilderConfiguration .getToStreamVersion() .equals(exportedStreamDefinition.getVersion()))) { return false; } if (eventBuilderConfiguration.getInputMapping() instanceof XMLInputMapping) { XMLInputMapping xmlInputMapping = (XMLInputMapping) eventBuilderConfiguration.getInputMapping(); for (InputMappingAttribute inputMappingAttribute : xmlInputMapping.getInputMappingAttributes()) { Attribute attribute = new Attribute( inputMappingAttribute.getToElementKey(), inputMappingAttribute.getToElementType()); if (!exportedStreamDefinition.getPayloadData().contains(attribute)) { return false; } } } else { return false; } return true; }
public void createMapping( EventBuilderConfiguration eventBuilderConfiguration, StreamDefinition exportedStreamDefinition, List<XPathData> attributeXpathList) { if (eventBuilderConfiguration != null && eventBuilderConfiguration.getInputMapping() instanceof XMLInputMapping) { XMLInputMapping xmlInputMapping = (XMLInputMapping) eventBuilderConfiguration.getInputMapping(); XPathDefinition xPathDefinition = xmlInputMapping.getXpathDefinition(); for (InputMappingAttribute inputMappingAttribute : xmlInputMapping.getInputMappingAttributes()) { String xpathExpr = inputMappingAttribute.getFromElementKey(); try { AXIOMXPath xpath = new AXIOMXPath(xpathExpr); if (xPathDefinition != null && !xPathDefinition.isEmpty()) { xpath.addNamespace(xPathDefinition.getPrefix(), xPathDefinition.getNamespaceUri()); } String type = EventBuilderConstants.ATTRIBUTE_TYPE_CLASS_TYPE_MAP.get( inputMappingAttribute.getToElementType()); attributeXpathList.add( new XPathData(xpath, type, inputMappingAttribute.getDefaultValue())); exportedStreamDefinition.addPayloadData( inputMappingAttribute.getToElementKey(), inputMappingAttribute.getToElementType()); } catch (JaxenException e) { String errMsg = "Error parsing XPath expression: " + xpathExpr; log.error(errMsg, e); throw new EventBuilderConfigurationException(errMsg, e); } } if (!isStreamDefinitionValidForConfiguration( eventBuilderConfiguration, exportedStreamDefinition)) { throw new EventBuilderValidationException( "Exported stream definition does not match the specified configuration."); } } }