public Description getDescription() { if(description != null) { return description; } return getEdimap().getDescription(); }
/** * Parse the supplied mapping model config stream and return the generated EdiMap. * <p/> * Can be used to set the mapping model to be used during the parsing operation. * See {@link #setMappingModel(org.milyn.edisax.model.EdifactModel)}. * @param mappingConfigStream Config stream. Must conform with the * <a href="http://www.milyn.org/schema/edi-message-mapping-1.0.xsd">edi-message-mapping-1.0.xsd</a> * schema. * @param mappingDescription Mapping Model Description. * @param resourceURI The resource URI. * @param importBaseURI The base URI for loading imports. * @return The EdifactModel for the mapping model. * @throws IOException Error reading the model stream. * @throws SAXException Invalid model. * @throws EDIConfigurationException when edi-mapping-configuration is incorrect. */ public static EdifactModel parseMappingModel(Reader mappingConfigStream, Description mappingDescription, URI resourceURI, URI importBaseURI) throws IOException, SAXException, EDIConfigurationException { AssertArgument.isNotNull(mappingConfigStream, "mappingConfigStream"); AssertArgument.isNotNull(importBaseURI, "importBaseURI"); // The resourceURI can be null e.g. when the mapping model was inlined in the Smooks config. EdifactModel edifactModel; edifactModel = new EdifactModel(resourceURI, importBaseURI, mappingConfigStream); edifactModel.setDescription(mappingDescription); return edifactModel; }
public static void loadMappingModels(Map<String, EdifactModel> mappingModels, URI baseURI, List<String> rootMappingModels) throws IOException, SAXException, EDIConfigurationException { for (String rootMappingModel : rootMappingModels) { try { EdifactModel mappingModel = EDIParser.parseMappingModel(rootMappingModel, baseURI); mappingModel.setAssociateModels(mappingModels.values()); mappingModels.put(toLookupName(mappingModel.getDescription()), mappingModel); } catch(Exception e) { throw new EDIConfigurationException("Error parsing EDI Mapping Model '" + rootMappingModel + "'.", e); } } }
/** * Returns the Edimap for a given edi-mapping inputstream. * @param inputStream the edi-mapping. * @return the Edimap. * @throws EDIConfigurationException When edi-mapping-configuration is badly formatted. * @throws IOException When unable to read edi-mapping-configuration. */ private Edimap readEDIConfig(InputStream inputStream) throws EDIConfigurationException, IOException { EdifactModel edifactModel = new EdifactModel(inputStream); return edifactModel.getEdimap(); }
private Map<String, Segment> getImportedSegments(URI importUri) { if(associateModels != null) { for(EdifactModel model : associateModels) { if(model.getModelURI().equals(importUri)) { return createImportMap(model.getEdimap()); } } } return null; }
private void applyImportOnSegments(List<SegmentGroup> segmentGroup, Import imp, Map<String, Segment> importedSegments) throws EDIParseException { for (SegmentGroup segment : segmentGroup) { if(segment instanceof Segment) { applyImportOnSegment((Segment)segment, imp, importedSegments); } if (segment.getSegments() != null) { applyImportOnSegments(segment.getSegments(), imp, importedSegments); } } }
importedSegments = getImportedSegments(importUri); if(importedSegments == null) { EDIConfigDigester digester = new EDIConfigDigester(importUri, URIResourceLocator.extractBaseURI(importUri)); importFiles(child, importedEdimap, tree); importedSegments = createImportMap(importedEdimap); applyImportOnSegments(edimap.getSegments().getSegments(), imp, importedSegments);
/** * Parse an EDI InputSource. */ public void parse(InputSource ediInputSource) throws IOException, SAXException { if(contentHandler == null) { throw new IllegalStateException("'contentHandler' not set. Cannot parse EDI stream."); } if(edifactModel == null || edifactModel.getEdimap() == null) { throw new IllegalStateException("'mappingModel' not set. Cannot parse EDI stream."); } try { // Create a reader for reading the EDI segments... segmentReader = new BufferedSegmentReader(ediInputSource, edifactModel.getDelimiters()); segmentReader.setIgnoreNewLines(getFeature(FEATURE_IGNORE_NEWLINES)); // Initialize the indent counter... indentDepth = new MutableInt(0); // Fire the startDocument event, as well as the startElement event... contentHandler.startDocument(); parse(false); contentHandler.endDocument(); } finally { contentHandler = null; } }
definitionsClassModel = ejc.compile(definitionsModel.getEdimap(), commonsPackageName, destDir.getAbsolutePath()); StringBuilder rootClassesListFileBuilder = new StringBuilder(); for(Map.Entry<String, EdifactModel> model : modelSet) { Description description = model.getValue().getDescription(); if(definitionsClassModel != null) { String messagePackageName = packageName + "." + description.getName(); ClassModel classModel = ejc.compile(model.getValue().getEdimap(), messagePackageName, destDir.getAbsolutePath(), definitionsClassModel.getClassesByNode()); ejc.compile(model.getValue().getEdimap(), packageName, destDir.getAbsolutePath());
EdifactModel controlModel = new EdifactModel(controlMap);
/** * Constructor mostly used for tests * * @param models */ public DefaultMappingsRegistry(EdifactModel... models) { for (EdifactModel model : models) { content.put(EDIUtils.toLookupName(model.getDescription()), model); } }
private void writeToContentHandler(String messageVal) throws SAXException { if (edifactModel.getDelimiters() != null && edifactModel.getDelimiters().getEscape() != null) { String escapeDelimiter = edifactModel.getDelimiters().getEscape(); messageVal = messageVal.replace(escapeDelimiter+escapeDelimiter, escapeDelimiter); } contentHandler.characters(messageVal.toCharArray(), 0, messageVal.length()); }
/** * Set the edifact edimap from the mapping model InputStream. * @throws org.milyn.edisax.EDIParseException is thrown when EdifactModel is unable to initialize edimap. * @throws org.milyn.edisax.EDIConfigurationException is thrown when edi-message-mapping contains multiple or no namespace declaration. * @throws java.io.IOException is thrown when error occurs when parsing edi-message-mapping. */ private synchronized void parseSequence() throws EDIConfigurationException, IOException, SAXException { if(edimap != null) { return; } //To prevent circular dependency the name/url of all imported urls are stored in a dependency tree. //If a name/url already exists in a parent node, we have a circular dependency. DependencyTree<String> tree = new DependencyTree<String>(); EDIConfigDigester digester = new EDIConfigDigester(modelURI, importBaseURI); edimap = digester.digestEDIConfig(new StringReader(mappingConfig)); description = edimap.getDescription(); importFiles(tree.getRoot(), edimap, tree); }
private Map<String, Segment> getImportedSegments(URI importUri) { if(associateModels != null) { for(EdifactModel model : associateModels) { if(model.getModelURI().equals(importUri)) { return createImportMap(model.getEdimap()); } } } return null; }
importedSegments = getImportedSegments(importUri); if(importedSegments == null) { EDIConfigDigester digester = new EDIConfigDigester(importUri, URIResourceLocator.extractBaseURI(importUri)); importFiles(child, importedEdimap, tree); importedSegments = createImportMap(importedEdimap); applyImportOnSegments(edimap.getSegments().getSegments(), imp, importedSegments);
/** * Parse an EDI InputSource. */ public void parse(InputSource ediInputSource) throws IOException, SAXException { if(contentHandler == null) { throw new IllegalStateException("'contentHandler' not set. Cannot parse EDI stream."); } if(edifactModel == null || edifactModel.getEdimap() == null) { throw new IllegalStateException("'mappingModel' not set. Cannot parse EDI stream."); } try { // Create a reader for reading the EDI segments... segmentReader = new BufferedSegmentReader(ediInputSource, edifactModel.getDelimiters()); segmentReader.setIgnoreNewLines(getFeature(FEATURE_IGNORE_NEWLINES)); // Initialize the indent counter... indentDepth = new MutableInt(0); // Fire the startDocument event, as well as the startElement event... contentHandler.startDocument(); parse(false); contentHandler.endDocument(); } finally { contentHandler = null; } }
public UnEdifactSpecificationReader(ZipInputStream specificationInStream, boolean useImport, boolean useShortName) throws IOException { this.useImport = useImport; this.useShortName = useShortName; definitionFiles = new HashMap<String, byte[]>(); messageFiles = new HashMap<String, byte[]>(); readDefinitionEntries(specificationInStream, new ZipDirectoryEntry("eded.", definitionFiles), new ZipDirectoryEntry("edcd.", definitionFiles), new ZipDirectoryEntry("edsd.", definitionFiles), new ZipDirectoryEntry("edmd.", "*", messageFiles)); if (versions.size() != 1) { if (versions.size() == 0) { throw new EdiParseException("Seems that we have a directory containing 0 parseable version inside: " + versions + ".\n All messages:\n\t" + messages); } throw new EdiParseException("Seems that we have a directory containing more than one parseable version inside: " + versions + ".\n All messages:\n\t" + messages); } String version = versions.iterator().next(); // Read Definition Configuration definitionModel = parseEDIDefinitionFiles(); addMissingDefinitions(definitionModel); definitionModel.getDescription().setNamespace(ControlBlockHandlerFactory.NAMESPACE_ROOT + ":un:" + version + ":common"); //Interchange envelope is inserted into the definitions. Handcoded at the moment. try { String interchangeSegmentDefinitions = INTERCHANGE_DEFINITION_SHORTNAME; if (!useShortName) { interchangeSegmentDefinitions = INTERCHANGE_DEFINITION; } EdifactModel interchangeEnvelope = new EdifactModel(ClassUtil.getResourceAsStream(interchangeSegmentDefinitions, this.getClass())); definitionModel.getSegments().getSegments().addAll(interchangeEnvelope.getEdimap().getSegments().getSegments()); } catch (Exception e) { throw new EdiParseException(e.getMessage(), e); } }
private void applyImportOnSegments(List<SegmentGroup> segmentGroup, Import imp, Map<String, Segment> importedSegments) throws EDIParseException { for (SegmentGroup segment : segmentGroup) { if(segment instanceof Segment) { applyImportOnSegment((Segment)segment, imp, importedSegments); } if (segment.getSegments() != null) { applyImportOnSegments(segment.getSegments(), imp, importedSegments); } } }
EdifactModel controlModel = new EdifactModel(controlMap);
/** * Constructor mostly used for tests * * @param models Edifact models */ public DefaultMappingsRegistry(EdifactModel... models) { for (EdifactModel model : models) { content.put(EDIUtils.toLookupName(model.getDescription()), model); } }