| 1 | |
package com.aurea.maven.plugins.sonic.sdm; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.Collections; |
| 5 | |
import java.util.List; |
| 6 | |
|
| 7 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 8 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
public class QueueMappings { |
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
private final List<QueueMapping> mappings; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | 0 | public QueueMappings() { |
| 28 | |
|
| 29 | 0 | this.mappings = new ArrayList<QueueMapping>(); |
| 30 | 0 | } |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public QueueMappings(Xpp3Dom dom, String defaultQueuesId) { |
| 42 | |
|
| 43 | 0 | this(); |
| 44 | |
|
| 45 | |
|
| 46 | 0 | Xpp3Dom[] queueMappingElements = dom.getChildren("queueMapping"); |
| 47 | 0 | for (Xpp3Dom queueMappingElement : queueMappingElements) { |
| 48 | 0 | addMapping(new QueueMapping(queueMappingElement)); |
| 49 | |
} |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | 0 | Xpp3Dom defaultMappingElement = dom.getChild("defaultMapping"); |
| 54 | 0 | if (defaultMappingElement != null) { |
| 55 | 0 | addMapping(new QueueMapping(defaultMappingElement)); |
| 56 | |
} else { |
| 57 | 0 | addMapping(new QueueMapping(defaultQueuesId, ".*")); |
| 58 | |
} |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
public void addMapping(QueueMapping mapping) { |
| 62 | |
|
| 63 | 0 | mappings.add(mapping); |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
public void removeMapping(QueueMapping mapping) { |
| 67 | |
|
| 68 | 0 | mappings.remove(mapping); |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
public List<QueueMapping> getMappings() { |
| 72 | |
|
| 73 | 0 | return Collections.unmodifiableList(mappings); |
| 74 | |
} |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
public QueueMapping getMappingForQueue(String queueName) throws MojoExecutionException { |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | 0 | for (QueueMapping mapping : mappings) { |
| 90 | 0 | if (mapping.matches(queueName)) { |
| 91 | 0 | return mapping; |
| 92 | |
} |
| 93 | 0 | } |
| 94 | |
|
| 95 | 0 | throw new MojoExecutionException("Unable to find a matching queue mapping for queue " + queueName); |
| 96 | |
} |
| 97 | |
|
| 98 | |
@Override |
| 99 | |
public String toString() { |
| 100 | |
|
| 101 | 0 | return "Queue mappings: " + mappings; |
| 102 | |
} |
| 103 | |
} |