/** * Digest the XML edi-message-mapping configuration stream. * @param stream the edi-message-mapping stream. * @return the {@link org.milyn.edisax.model.internal.Edimap}. * @throws IOException Error parsing the XML stream. * @throws SAXException Error parsing the XML stream. * @throws EDIConfigurationException Multiple or no namespaces in edi-message-mapping. */ public static Edimap digestConfig(InputStream stream) throws IOException, SAXException, EDIConfigurationException { return new EDIConfigDigester().digestEDIConfig(stream); }
/** * Digest child elements of edimap. * @param configDoc the Edimap element. * @param edimap the {@link org.milyn.edisax.model.internal.Edimap} to populate. * @param schemaName the schema uri. * @throws org.milyn.edisax.EDIConfigurationException is thrown when unable to retrieve namespace in configuration. */ private void digestXSDValidatedConfig(Document configDoc, Edimap edimap, String schemaName) throws EDIConfigurationException { // Check the namespace attribute Element documentElement = configDoc.getDocumentElement(); //Retrieve the namespace for the schema. String namespacePrefix = retrieveNamespace(documentElement, schemaName); NodeList nodes = documentElement.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeName().equalsIgnoreCase(namespacePrefix + "import")) { digestImport(node, edimap); } else if (node.getNodeName().equalsIgnoreCase(namespacePrefix + "description")) { digestDescription(node, edimap); } else if (node.getNodeName().equalsIgnoreCase(namespacePrefix + "delimiters")) { digestDelimiters(node, edimap); } else if (node.getNodeName().equalsIgnoreCase(namespacePrefix + "segments")) { digestSegments(node, edimap, namespacePrefix); } } }
/** * Set values in {@link org.milyn.edisax.model.internal.ValueNode}. * @param node the {@link org.milyn.edisax.model.internal.ValueNode} to populate. * @param valueNode the ValueNode element. * @throws org.milyn.edisax.EDIConfigurationException is thrown when values are badly formatted. */ private void setValuesForValueNode(Node node, ValueNode valueNode, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { setValuesForMappingNode(node, valueNode, namespacePrefix, parent); String type = getAttributeValue(node, "dataType"); if(type != null) { valueNode.setDataType(type); } else { valueNode.setDataType(getAttributeValue(node, "type")); } valueNode.setMinLength(getNodeValueAsInteger(node, "minLength")); valueNode.setMaxLength(getNodeValueAsInteger(node, "maxLength")); String dataTypeParams = getAttributeValue(node, "dataTypeParameters"); if(dataTypeParams != null) { digestParameters(valueNode, dataTypeParams); } else { digestParameters(valueNode, getAttributeValue(node, "typeParameters")); } }
setValuesForSegment(segment, node, namespacePrefix, parent); Field field = new Field(); segment.getFields().add(field); digestField(currentNode, field, namespacePrefix, segment); } else { digestSegmentGroup(currentNode, segment.getSegments(), namespacePrefix, segment); segmentGroup.setMaxOccurs(getNodeValueAsInteger(node, "maxOccurs")); segmentGroup.setMinOccurs(getNodeValueAsInteger(node, "minOccurs")); setValuesForMappingNode(node, segmentGroup, namespacePrefix, parent); Node currentNode = nodes.item(i); digestSegmentGroup(currentNode, segmentGroup.getSegments(), namespacePrefix, segmentGroup);
private boolean digestSegmentGroup(Node currentNode, List<SegmentGroup> segmentGroupList, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { if (currentNode.getNodeName().equalsIgnoreCase(namespacePrefix + "segmentGroup")) { SegmentGroup segment = new SegmentGroup(); segment.setDocumentation(getNodeValue(currentNode, namespacePrefix + "documentation")); segmentGroupList.add(segment); digestSegment(currentNode, segment, namespacePrefix, parent); return true; } else if (currentNode.getNodeName().equalsIgnoreCase(namespacePrefix + "segment")) { Segment segment = new Segment(); segmentGroupList.add(segment); digestSegment(currentNode, segment, namespacePrefix, parent); return true; } return false; }
private Edimap digestEDIConfig(Document configDoc) throws SAXException, EDIConfigurationException, IOException { XsdDOMValidator validator = new XsdDOMValidator(configDoc); if (validator.getNamespaces().size() == 0) { throw new EDIConfigurationException("The edi-message-mapping configuration must contain a namespace."); } if (validator.getNamespaces().size() > 1) { throw new EDIConfigurationException("Unsupported use of multiple configuration namespaces from inside the edi-message-mapping configuration."); } String ediNS = validator.getNamespaces().get(0).toString(); validator.validate(); Edimap edimap = new Edimap(modelURI); if(assertValidXSD(ediNS)) { digestXSDValidatedConfig(configDoc, edimap, ediNS); } else { throw new SAXException("Cannot parse edi-message-mapping configuration. Unsupported default Namespace '" + ediNS + "'."); } return edimap; }
/** * Digests attributes and child elements of Field element. * @param node the Field element. * @param field the {@link org.milyn.edisax.model.internal.Field} to populate * @param namespacePrefix the prefix used to name elements in xml. * @throws org.milyn.edisax.EDIConfigurationException is thrown when values are badly formatted. */ private void digestField(Node node, Field field, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { setValuesForField(field, node, namespacePrefix, parent); NodeList nodes = node.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node currentNode = nodes.item(i); if (currentNode.getNodeName().equalsIgnoreCase(namespacePrefix + "component")) { Component component = new Component(); field.getComponents().add(component); digestComponent(currentNode, component, namespacePrefix, field); } } }
/** * Digest the XML edi-message-mapping configuration stream. * @param stream the edi-message-mapping stream. * @return the {@link org.milyn.edisax.model.internal.Edimap}. * @throws IOException Error parsing the XML stream. * @throws SAXException Error parsing the XML stream. * @throws EDIConfigurationException Multiple or no namespaces in edi-message-mapping. */ public Edimap digestEDIConfig(Reader stream) throws IOException, SAXException, EDIConfigurationException { Document configDoc; try { configDoc = XmlUtil.parseStream(stream); } catch (ParserConfigurationException ee) { throw new SAXException("Unable to parse Smooks configuration.", ee); } return digestEDIConfig(configDoc); }
setValuesForSegment(segment, node, namespacePrefix, parent); Field field = new Field(); segment.getFields().add(field); digestField(currentNode, field, namespacePrefix, segment); } else { digestSegmentGroup(currentNode, segment.getSegments(), namespacePrefix, segment); segmentGroup.setMaxOccurs(getNodeValueAsInteger(node, "maxOccurs")); segmentGroup.setMinOccurs(getNodeValueAsInteger(node, "minOccurs")); setValuesForMappingNode(node, segmentGroup, namespacePrefix, parent); Node currentNode = nodes.item(i); digestSegmentGroup(currentNode, segmentGroup.getSegments(), namespacePrefix, segmentGroup);
private boolean digestSegmentGroup(Node currentNode, List<SegmentGroup> segmentGroupList, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { if (currentNode.getNodeName().equalsIgnoreCase(namespacePrefix + "segmentGroup")) { SegmentGroup segment = new SegmentGroup(); segment.setDocumentation(getNodeValue(currentNode, namespacePrefix + "documentation")); segmentGroupList.add(segment); digestSegment(currentNode, segment, namespacePrefix, parent); return true; } else if (currentNode.getNodeName().equalsIgnoreCase(namespacePrefix + "segment")) { Segment segment = new Segment(); segmentGroupList.add(segment); digestSegment(currentNode, segment, namespacePrefix, parent); return true; } return false; }
private Edimap digestEDIConfig(Document configDoc) throws SAXException, EDIConfigurationException, IOException { XsdDOMValidator validator = new XsdDOMValidator(configDoc); if (validator.getNamespaces().size() == 0) { throw new EDIConfigurationException("The edi-message-mapping configuration must contain a namespace."); } if (validator.getNamespaces().size() > 1) { throw new EDIConfigurationException("Unsupported use of multiple configuration namespaces from inside the edi-message-mapping configuration."); } String ediNS = validator.getNamespaces().get(0).toString(); validator.validate(); Edimap edimap = new Edimap(modelURI); if(assertValidXSD(ediNS)) { digestXSDValidatedConfig(configDoc, edimap, ediNS); } else { throw new SAXException("Cannot parse edi-message-mapping configuration. Unsupported default Namespace '" + ediNS + "'."); } return edimap; }
/** * Digests attributes and child elements of Field element. * @param node the Field element. * @param field the {@link org.milyn.edisax.model.internal.Field} to populate * @param namespacePrefix the prefix used to name elements in xml. * @throws org.milyn.edisax.EDIConfigurationException is thrown when values are badly formatted. */ private void digestField(Node node, Field field, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { setValuesForField(field, node, namespacePrefix, parent); NodeList nodes = node.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node currentNode = nodes.item(i); if (currentNode.getNodeName().equalsIgnoreCase(namespacePrefix + "component")) { Component component = new Component(); field.getComponents().add(component); digestComponent(currentNode, component, namespacePrefix, field); } } }
/** * Digest the XML edi-message-mapping configuration stream. * @param stream the edi-message-mapping stream. * @return the {@link org.milyn.edisax.model.internal.Edimap}. * @throws IOException Error parsing the XML stream. * @throws SAXException Error parsing the XML stream. * @throws EDIConfigurationException Multiple or no namespaces in edi-message-mapping. */ public Edimap digestEDIConfig(InputStream stream) throws IOException, SAXException, EDIConfigurationException { Document configDoc; try { configDoc = XmlUtil.parseStream(stream); } catch (ParserConfigurationException ee) { throw new SAXException("Unable to parse Smooks configuration.", ee); } return digestEDIConfig(configDoc); }
/** * Digest child elements of edimap. * @param configDoc the Edimap element. * @param edimap the {@link org.milyn.edisax.model.internal.Edimap} to populate. * @param schemaName the schema uri. * @throws org.milyn.edisax.EDIConfigurationException is thrown when unable to retrieve namespace in configuration. */ private void digestXSDValidatedConfig(Document configDoc, Edimap edimap, String schemaName) throws EDIConfigurationException { // Check the namespace attribute Element documentElement = configDoc.getDocumentElement(); //Retrieve the namespace for the schema. String namespacePrefix = retrieveNamespace(documentElement, schemaName); NodeList nodes = documentElement.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeName().equalsIgnoreCase(namespacePrefix + "import")) { digestImport(node, edimap); } else if (node.getNodeName().equalsIgnoreCase(namespacePrefix + "description")) { digestDescription(node, edimap); } else if (node.getNodeName().equalsIgnoreCase(namespacePrefix + "delimiters")) { digestDelimiters(node, edimap); } else if (node.getNodeName().equalsIgnoreCase(namespacePrefix + "segments")) { digestSegments(node, edimap, namespacePrefix); } } }
setValuesForSegment(segment, node, namespacePrefix, parent); Field field = new Field(); segment.getFields().add(field); digestField(currentNode, field, namespacePrefix, segment); } else { digestSegmentGroup(currentNode, segment.getSegments(), namespacePrefix, segment); segmentGroup.setMaxOccurs(getNodeValueAsInteger(node, "maxOccurs")); segmentGroup.setMinOccurs(getNodeValueAsInteger(node, "minOccurs")); setValuesForMappingNode(node, segmentGroup, namespacePrefix, parent); Node currentNode = nodes.item(i); digestSegmentGroup(currentNode, segmentGroup.getSegments(), namespacePrefix, segmentGroup);
/** * Set values in {@link org.milyn.edisax.model.internal.ValueNode}. * @param node the {@link org.milyn.edisax.model.internal.ValueNode} to populate. * @param valueNode the ValueNode element. * @throws org.milyn.edisax.EDIConfigurationException is thrown when values are badly formatted. */ private void setValuesForValueNode(Node node, ValueNode valueNode, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { setValuesForMappingNode(node, valueNode, namespacePrefix, parent); String type = getAttributeValue(node, "dataType"); if(type != null) { valueNode.setDataType(type); } else { valueNode.setDataType(getAttributeValue(node, "type")); } valueNode.setMinLength(getNodeValueAsInteger(node, "minLength")); valueNode.setMaxLength(getNodeValueAsInteger(node, "maxLength")); String dataTypeParams = getAttributeValue(node, "dataTypeParameters"); if(dataTypeParams != null) { digestParameters(valueNode, dataTypeParams); } else { digestParameters(valueNode, getAttributeValue(node, "typeParameters")); } }
/** * Digest the XML edi-message-mapping configuration stream. * @param stream the edi-message-mapping stream. * @return the {@link org.milyn.edisax.model.internal.Edimap}. * @throws IOException Error parsing the XML stream. * @throws SAXException Error parsing the XML stream. * @throws EDIConfigurationException Multiple or no namespaces in edi-message-mapping. */ public static Edimap digestConfig(InputStream stream) throws IOException, SAXException, EDIConfigurationException { return new EDIConfigDigester().digestEDIConfig(stream); }
private boolean digestSegmentGroup(Node currentNode, List<SegmentGroup> segmentGroupList, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { if (currentNode.getNodeName().equalsIgnoreCase(namespacePrefix + "segmentGroup")) { SegmentGroup segment = new SegmentGroup(); segment.setDocumentation(getNodeValue(currentNode, namespacePrefix + "documentation")); segmentGroupList.add(segment); digestSegment(currentNode, segment, namespacePrefix, parent); return true; } else if (currentNode.getNodeName().equalsIgnoreCase(namespacePrefix + "segment")) { Segment segment = new Segment(); segmentGroupList.add(segment); digestSegment(currentNode, segment, namespacePrefix, parent); return true; } return false; }
private Edimap digestEDIConfig(Document configDoc) throws SAXException, EDIConfigurationException, IOException { XsdDOMValidator validator = new XsdDOMValidator(configDoc); if (validator.getNamespaces().size() == 0) { throw new EDIConfigurationException("The edi-message-mapping configuration must contain a namespace."); } if (validator.getNamespaces().size() > 1) { throw new EDIConfigurationException("Unsupported use of multiple configuration namespaces from inside the edi-message-mapping configuration."); } String ediNS = validator.getNamespaces().get(0).toString(); validator.validate(); Edimap edimap = new Edimap(modelURI); if(assertValidXSD(ediNS)) { digestXSDValidatedConfig(configDoc, edimap, ediNS); } else { throw new SAXException("Cannot parse edi-message-mapping configuration. Unsupported default Namespace '" + ediNS + "'."); } return edimap; }
/** * Digests attributes and child elements of Field element. * @param node the Field element. * @param field the {@link org.milyn.edisax.model.internal.Field} to populate * @param namespacePrefix the prefix used to name elements in xml. * @throws org.milyn.edisax.EDIConfigurationException is thrown when values are badly formatted. */ private void digestField(Node node, Field field, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { setValuesForField(field, node, namespacePrefix, parent); NodeList nodes = node.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node currentNode = nodes.item(i); if (currentNode.getNodeName().equalsIgnoreCase(namespacePrefix + "component")) { Component component = new Component(); field.getComponents().add(component); digestComponent(currentNode, component, namespacePrefix, field); } } }