protected List<MappingWithDirection> findApplicable(MappingKey key) { ArrayList<MappingWithDirection> result = new ArrayList<MappingWithDirection>(); for (ParsedMapping pm : mappings) { if ((pm.mappingCase == null && key.mappingCase == null) ^ (pm.mappingCase != null && pm.mappingCase.equals(key.mappingCase))) { if (pm.sideA.isAssignableFrom(key.source) && pm.sideB.isAssignableFrom(key.target)) result.add(new MappingWithDirection(pm, true)); else if (pm.sideB.isAssignableFrom(key.source) && pm.sideA.isAssignableFrom(key.target)) result.add(new MappingWithDirection(pm, false)); } } if (!result.isEmpty()) { Collections.sort(result, new MappingComparator(key.target)); } else if (automappingEnabled) { logger.info( "Could not find applicable mappings between {} and {}. A mapping will be created using automapping facility", key.source.getName(), key.target.getName()); ParsedMapping pm = new Mapping(key.source, key.target, this).automap().parse(); logger.debug("Automatically created {}", pm); mappings.add(pm); result.add(new MappingWithDirection(pm, true)); } else logger.warn( "Could not find applicable mappings between {} and {}!", key.source.getName(), key.target.getName()); return result; }
protected void addOrReplace(ParsedMapping parsedMapping) { MappingKey key = new MappingKey(parsedMapping); for (int i = 0; i < mappings.size(); i++) { if (key.equals(new MappingKey(mappings.get(i)))) { logger.warn("{}\nis replaced with\n{}", mappings.get(i), parsedMapping); mappings.set(i, parsedMapping); return; } } logger.debug("Parsed {}", parsedMapping); mappings.add(parsedMapping); }
public Nomin disableAutomapping() { this.automappingEnabled = false; logger.debug("Nomin's automapping facility is disabled"); return this; }
public Nomin enableAutomapping() { this.automappingEnabled = true; logger.debug("Nomin's automapping facility is enabled"); return this; }