private static Map<String, Component> readComponents(Reader reader, boolean useShortName) throws IOException, EdiParseException { Map<String, Component> datas = new HashMap<String, Component>(); BufferedReader _reader = new BufferedReader(reader); moveToNextPart(_reader); Component component = new Component(); String id = populateComponent(_reader, component, useShortName); while (id != null) { datas.put(id, component); moveToNextPart(_reader); component = new Component(); id = populateComponent(_reader, component, useShortName); } return datas; }
public Component addSubComponent(SubComponent subComponent) { getSubComponents().add(subComponent); return this; }
private static void populateComponent(Component toComponent, Component fromComponent) { toComponent.setDocumentation(fromComponent.getDocumentation()); toComponent.setMaxLength(fromComponent.getMaxLength()); toComponent.setMinLength(fromComponent.getMinLength()); toComponent.setTruncatable(true); toComponent.setDataType(fromComponent.getDataType()); toComponent.setDataTypeParameters(fromComponent.getTypeParameters()); toComponent.setXmltag(XmlTagEncoder.encode(fromComponent.getXmltag())); toComponent.setName(fromComponent.getName()); }
/** * Set values in {@link org.dhatim.edisax.model.internal.Component}. * @param component the {@link org.dhatim.edisax.model.internal.Component} to populate. * @param node the Component element. * @throws org.dhatim.edisax.EDIConfigurationException is thrown when values are badly formatted. */ private void setValuesForComponent(Component component, Node node, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { component.setRequired(getNodeValueAsBoolean(node, "required")); component.setTruncatable(getNodeValueAsBoolean(node, "truncatable")); setValuesForValueNode(node, component, namespacePrefix, parent); }
private static Field convertToField(Component component, boolean isMandatory) { Field field = new Field(); field.setName(component.getName()); field.setXmltag(XmlTagEncoder.encode(component.getXmltag())); field.setNodeTypeRef(component.getNodeTypeRef()); field.setDocumentation(component.getDocumentation()); field.setMaxLength(component.getMaxLength()); field.setMinLength(component.getMinLength()); field.setRequired(isMandatory); field.setTruncatable(true); field.setDataType(component.getDataType()); field.setDataTypeParameters(component.getTypeParameters()); return field; }
/** * Converts {@link Component} to {@link EAttribute} * * @param component * @return */ private static EStructuralFeature componentToEAttribute(Component component) { if (!component.getSubComponents().isEmpty()) { throw new IllegalArgumentException( "Sub-components are not supported yet for component " + component.getXmltag()); } EAttribute result = EcoreFactory.eINSTANCE.createEAttribute(); result.setName(toJavaName(component.getXmltag(), false)); result.setLowerBound(component.isRequired() ? 1 : 0); result.setUpperBound(1); result.setEType(toEType(component.getTypeClass())); annotate(result, "truncable", String.valueOf(component.isTruncatable())); annotate(result, "required", String.valueOf(component.isRequired())); annotate(result, ANNOTATION_TYPE_KEY, SmooksMetadata.COMPONENT_TYPE); annotateValueNode(result, component); addMappingInformation(result, component); return result; }
List<SubComponent> expectedSubComponents = expectedComponent.getSubComponents(); for (int i = 0; i < currentComponentSubComponents.length; i++) { if (expectedSubComponents.get(i).isRequired() && currentComponentSubComponents[i].length() == 0) { throw new EDIParseException(edifactModel.getEdimap(), "Segment [" + segmentCode + "], field " + (fieldIndex + 1) + " (" + field + "), component " + (componentIndex + 1) + " (" + expectedComponent.getXmltag() + "), sub-component " + (i + 1) + " (" + expectedSubComponents.get(i).getXmltag() + ") expected to contain a value. Currently at segment number " + segmentReader.getCurrentSegmentNumber() + ".", expectedSubComponents.get(i), segmentReader.getCurrentSegmentNumber(), segmentReader.getCurrentSegmentFields()); if (expectedComponent.isRequired() && componentMessageVal.length() == 0) { throw new EDIParseException(edifactModel.getEdimap(), "Segment [" + segmentCode + "], field " + (fieldIndex + 1) + " (" + field + "), component " + (componentIndex + 1) + " (" + expectedComponent.getXmltag() + ") expected to contain a value. Currently at segment number " + segmentReader.getCurrentSegmentNumber() + ".", expectedComponent, segmentReader.getCurrentSegmentNumber(), segmentReader.getCurrentSegmentFields());
boolean throwException = false; if (expectedComponent.isTruncatable()) { throw new EDIParseException(edifactModel.getEdimap(), "Segment [" + segmentCode + "], field " + (fieldIndex + 1) + " (" + field + "), component " + (componentIndex + 1) + " (" + expectedComponent.getXmltag() + ") expected to contain " + expectedSubComponents.size() + " sub-components. Actually contains " + currentComponentSubComponents.length + " sub-components. Currently at segment number " + segmentReader.getCurrentSegmentNumber() + ".", expectedComponent, segmentReader.getCurrentSegmentNumber(), segmentReader.getCurrentSegmentFields());
if (expectedComponents.get(i).isRequired()) { throwException = true; break; if (component.getSubComponents().size() == 0 && (!currentFieldComponents[i].equals(""))) { validateValueNode(component, currentFieldComponents[i]);
linePart = getLinePart(reader, line); if (linePart != null) { Component component = new Component(); component.setRequired(linePart.isMandatory()); populateComponent(component, components.get(linePart.getId())); field.getComponents().add(component);
if (truncatableComponents != null) { for (Component component : field.getComponents()) { component.setTruncatable(isTruncatable(truncatableComponents, component.isTruncatable()));
/** * Digests attributes and child elements of Component element. * @param node the Component element. * @param component the {@link org.dhatim.edisax.model.internal.Component} to populate. * @param namespacePrefix the prefix used to name elements in xml. * @throws org.dhatim.edisax.EDIConfigurationException is thrown when values are badly formatted. */ private void digestComponent(Node node, Component component, String namespacePrefix, MappingNode parent) throws EDIConfigurationException { setValuesForComponent(component, 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 + "sub-component")) { SubComponent subComponent = new SubComponent(); component.getSubComponents().add(subComponent); setValuesForSubComponent(currentNode, subComponent, namespacePrefix, component); } } }
/** * Digests attributes and child elements of Field element. * @param node the Field element. * @param field the {@link org.dhatim.edisax.model.internal.Field} to populate * @param namespacePrefix the prefix used to name elements in xml. * @throws org.dhatim.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); } } }
private void addComponents(List<Component> components, Element fieldEl) { for(Component component : components) { Element componentEl = newElement("component", fieldEl, component); mapBeanProperties(component, componentEl, "name", "xmltag", "nodeTypeRef", "truncatable", "maxLength", "minLength", "required", "dataType", "dataTypeParametersString|dataTypeParameters"); addSubComponents(component.getSubComponents(), componentEl); } }