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; }
private ArrayList getLocalViaHeaders() throws IOException { /* * We can't keep a cached copy because the callers * of this method change the viaHeaders. In particular * a branch may be added which causes INVITES to fail. */ if (viaHeaders != null) { return viaHeaders; } ListeningPoint lp = sipProvider.getListeningPoint(); viaHeaders = new ArrayList(); try { String addr = lp.getIPAddress(); ViaHeader viaHeader = headerFactory.createViaHeader(addr, lp.getPort(), lp.getTransport(), null); viaHeader.setRPort(); viaHeaders.add(viaHeader); return viaHeaders; } catch (ParseException e) { throw new IOException( "A ParseException occurred while creating Via Headers! " + e.getMessage()); } catch (InvalidArgumentException e) { throw new IOException( "Unable to create a via header for port " + lp.getPort() + " " + e.getMessage()); } }