/** * Encodes a String into standard java attribute name convention. The following steps are performed * on the name: * 1. First character is set to lower case. * 2. Illegal characters like '-' and whitespace are removed. * 3. If attributetype is a Collection a 's'-character is appended. * * @param type the type of attribute. * @param name the original attribut name. * @return the attribute name complying with standard java attribute name convention. * @throws IllegalNameException when attribute name is a reserved keyword in java. */ public static String encodeAttributeName(JType type, String name) throws IllegalNameException { String result = encodeAttributeName(name); if(type != null && Collection.class.isAssignableFrom(type.getClass())) { result += "s"; } return result; }
public String getJavaName() throws IllegalNameException { String javaName = xmltag.replace(INDEXED_NODE_SEPARATOR, "_"); if(name != null && name.trim().length() > 0) { javaName += "_" + EDIUtils.encodeClassName(name); } return javaName; }
@Override protected synchronized Map<String, EdifactModel> demandLoading(String[] nameComponents) throws EDIConfigurationException, IOException, SAXException { String urn = "urn:org.milyn.edi.unedifact:" + nameComponents[1] + nameComponents[2] + "-mapping:*"; Map<String, EdifactModel> result = new LinkedHashMap<String, EdifactModel>(); EDIUtils.loadMappingModels(urn.toLowerCase(), result, URI.create("/")); return result; }
private static List<String> getMappingModelList(String urn) throws IOException, EDIConfigurationException { InputStream mappingModelListStream = getMappingModelConfigStream(urn, EDI_MAPPING_MODEL_ZIP_LIST_FILE); if(mappingModelListStream == null) { throw new EDIConfigurationException("Failed to locate jar file for EDI Mapping Model URN '" + urn + "'. Jar must be available on classpath."); } return getMappingModelList(mappingModelListStream); }
public static String encodeAttributeName(String name) { String result; if(name.toUpperCase().equals(name)) { result = name.toLowerCase(); } else { result = name; } result = deleteWithPascalNotation(result, '_'); result = encodeJavaIdentifier(result); if(Character.isUpperCase(result.charAt(0))) { result = Character.toLowerCase(result.charAt(0)) + result.substring(1); } if (reservedKeywords.contains(result)) { result = "_" + result; } return result; }
/** * Encodes a String into standard java class name convention. The following steps are performed * on the name: * 1. First character is set to upper case. * 2. Illegal characters like '-' and whitespace are removed. * * @param name the original class name. * @return the class name complying with standard java class name convention. * @throws IllegalNameException when class name is a reserved keyword in java. */ public static String encodeClassName(String name) throws IllegalNameException { String result = name; if (name.toUpperCase().equals(name)) { StringBuilder nameRebuilder = new StringBuilder(); nameRebuilder.append(name.toLowerCase()); nameRebuilder.setCharAt(0, name.charAt(0)); result = nameRebuilder.toString(); } result = deleteWithPascalNotation(result, '_'); result = encodeJavaIdentifier(result); if(Character.isLowerCase(result.charAt(0))) { result = Character.toUpperCase(result.charAt(0)) + result.substring(1); } assertLegalName(result); return result; }
if(loadXMLMappingModel(mappingModelFile, mappingModels, baseURI)) { if(loadZippedMappingModels(mappingModelFile, mappingModels, baseURI)) { List<String> rootMappingModels = getMappingModelList(urn); loadMappingModels(mappingModels, baseURI, rootMappingModels); if(!loadXMLMappingModel(mappingModelFile, mappingModels, baseURI)) { if(!loadZippedMappingModels(mappingModelFile, mappingModels, baseURI)) { throw new EDIConfigurationException("Failed to process EDI Mapping Model config file '" + mappingModelFile + "'. Not a valid EDI Mapping Model configuration.");
private static boolean loadZippedMappingModels(String mappingModelFile, Map<String, EdifactModel> mappingModels, URI baseURI) throws IOException, SAXException, EDIConfigurationException { URIResourceLocator locator = new URIResourceLocator(); locator.setBaseURI(baseURI); InputStream rawZipStream = locator.getResource(mappingModelFile); if(rawZipStream != null) { Archive archive = loadArchive(rawZipStream); if(archive != null) { List<String> rootMappingModels = getMappingModelList(archive); if(rootMappingModels.isEmpty()) { logger.debug("Configured mapping model file '" + mappingModelFile + "' is not a valid Mapping Model zip file. Check that the zip has a valid '" + EDI_MAPPING_MODEL_ZIP_LIST_FILE + "' mapping list file."); return false; } ClassLoader threadCCL = Thread.currentThread().getContextClassLoader(); try { ArchiveClassLoader archiveClassLoader = new ArchiveClassLoader(threadCCL, archive); Thread.currentThread().setContextClassLoader(archiveClassLoader); loadMappingModels(mappingModels, baseURI, rootMappingModels); } finally { Thread.currentThread().setContextClassLoader(threadCCL); } return true; } } return false; }
Properties interchangeProperties = EDIUtils.getInterchangeProperties(ediMappingModel); EDIUtils.loadMappingModels(ediMappingModel, mappingModels, URIResourceLocator.DEFAULT_BASE_URI); deleteFile(messagePackageName, EDIUtils.encodeClassName(description.getName()) + "Factory.java");
interchangePropertiesStream = getMappingModelConfigStream(ediMappingModel, EDI_MAPPING_MODEL_INTERCHANGE_PROPERTIES_FILE); Archive archive = loadArchive(rawZipStream); if(archive != null) { byte[] bytes = archive.getEntryBytes(EDI_MAPPING_MODEL_INTERCHANGE_PROPERTIES_FILE);
String className = EDIUtils.encodeClassName(mappingNode.getJavaName()); String propertyName = EDIUtils.encodeAttributeName(jtype, mappingNode.getJavaName()); JNamedType childProperty = new JNamedType(jtype, propertyName);
@SuppressWarnings("unchecked") private static List<String> getMappingModelList(Archive archive) throws IOException { byte[] zipEntryBytes = archive.getEntryBytes(EDI_MAPPING_MODEL_ZIP_LIST_FILE); if(zipEntryBytes != null) { return getMappingModelList(new ByteArrayInputStream(zipEntryBytes)); } return Collections.EMPTY_LIST; }
if (builderEndsWith(stringBuilder, delimiter)) { stringBuilder.setLength(curTokenLength - delimiterLength); if (stringBuilder.length() > 0) { } else if (builderEndsWith(stringBuilder, escape)) { stringBuilder.setLength(curTokenLength - escapeLength); if (stringBuilder.length() > 0) {
if(loadXMLMappingModel(mappingModelFile, mappingModels, baseURI)) { if(loadZippedMappingModels(mappingModelFile, mappingModels, baseURI)) { List<String> rootMappingModels = getMappingModelList(urn); loadMappingModels(mappingModels, baseURI, rootMappingModels); if(!loadXMLMappingModel(mappingModelFile, mappingModels, baseURI)) { if(!loadZippedMappingModels(mappingModelFile, mappingModels, baseURI)) { throw new EDIConfigurationException("Failed to process EDI Mapping Model config file '" + mappingModelFile + "'. Not a valid EDI Mapping Model configuration.");
private static boolean loadZippedMappingModels(String mappingModelFile, Map<String, EdifactModel> mappingModels, URI baseURI) throws IOException, SAXException, EDIConfigurationException { URIResourceLocator locator = new URIResourceLocator(); locator.setBaseURI(baseURI); InputStream rawZipStream = locator.getResource(mappingModelFile); if(rawZipStream != null) { Archive archive = loadArchive(rawZipStream); if(archive != null) { List<String> rootMappingModels = getMappingModelList(archive); if(rootMappingModels.isEmpty()) { logger.debug("Configured mapping model file '" + mappingModelFile + "' is not a valid Mapping Model zip file. Check that the zip has a valid '" + EDI_MAPPING_MODEL_ZIP_LIST_FILE + "' mapping list file."); return false; } ClassLoader threadCCL = Thread.currentThread().getContextClassLoader(); try { ArchiveClassLoader archiveClassLoader = new ArchiveClassLoader(threadCCL, archive); Thread.currentThread().setContextClassLoader(archiveClassLoader); loadMappingModels(mappingModels, baseURI, rootMappingModels); } finally { Thread.currentThread().setContextClassLoader(threadCCL); } return true; } } return false; }
/** * Encodes a String into standard java class name convention. The following steps are performed * on the name: * 1. First character is set to upper case. * 2. Illegal characters like '-' and whitespace are removed. * * @param name the original class name. * @return the class name complying with standard java class name convention. * @throws IllegalNameException when class name is a reserved keyword in java. */ public static String encodeClassName(String name) throws IllegalNameException { String result = name; if (name.toUpperCase().equals(name)) { StringBuilder nameRebuilder = new StringBuilder(); nameRebuilder.append(name.toLowerCase()); nameRebuilder.setCharAt(0, name.charAt(0)); result = nameRebuilder.toString(); } result = deleteWithPascalNotation(result, '_'); result = encodeJavaIdentifier(result); if(Character.isLowerCase(result.charAt(0))) { result = Character.toUpperCase(result.charAt(0)) + result.substring(1); } assertLegalName(result); return result; }
private static List<String> getMappingModelList(String urn) throws IOException, EDIConfigurationException { InputStream mappingModelListStream = getMappingModelConfigStream(urn, EDI_MAPPING_MODEL_ZIP_LIST_FILE); if(mappingModelListStream == null) { throw new EDIConfigurationException("Failed to locate jar file for EDI Mapping Model URN '" + urn + "'. Jar must be available on classpath."); } return getMappingModelList(mappingModelListStream); }
public static String encodeAttributeName(String name) { String result; if(name.toUpperCase().equals(name)) { result = name.toLowerCase(); } else { result = name; } result = deleteWithPascalNotation(result, '_'); result = encodeJavaIdentifier(result); if(Character.isUpperCase(result.charAt(0))) { result = Character.toLowerCase(result.charAt(0)) + result.substring(1); } if (reservedKeywords.contains(result)) { result = "_" + result; } return result; }
interchangePropertiesStream = getMappingModelConfigStream(ediMappingModel, EDI_MAPPING_MODEL_INTERCHANGE_PROPERTIES_FILE); Archive archive = loadArchive(rawZipStream); if(archive != null) { byte[] bytes = archive.getEntryBytes(EDI_MAPPING_MODEL_INTERCHANGE_PROPERTIES_FILE);
@SuppressWarnings("unchecked") private static List<String> getMappingModelList(Archive archive) throws IOException { byte[] zipEntryBytes = archive.getEntryBytes(EDI_MAPPING_MODEL_ZIP_LIST_FILE); if(zipEntryBytes != null) { return getMappingModelList(new ByteArrayInputStream(zipEntryBytes)); } return Collections.EMPTY_LIST; }