| 1 | |
package com.aurea.maven.plugins.sonic.topology.utils; |
| 2 | |
|
| 3 | |
import java.util.HashMap; |
| 4 | |
import java.util.Iterator; |
| 5 | |
import java.util.SortedSet; |
| 6 | |
|
| 7 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
| 8 | |
|
| 9 | |
public class ParameterHolder implements java.io.Serializable { |
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
private static final long serialVersionUID = 1L; |
| 14 | |
private HashMap<String, String> pmholder; |
| 15 | |
|
| 16 | 0 | public ParameterHolder() { |
| 17 | 0 | pmholder = new HashMap<String, String>(); |
| 18 | 0 | } |
| 19 | |
|
| 20 | |
public boolean addParameter(String param, String value) |
| 21 | |
throws ParameterHandlingException { |
| 22 | 0 | if (pmholder.containsKey(param)) { |
| 23 | 0 | System.out |
| 24 | |
.println("Parametervalue is existing -- Cannot replace as this indicates a possible bad configuration"); |
| 25 | 0 | throw new ParameterHandlingException( |
| 26 | |
"Parametervalue is existing -- Cannot replace as this indicates a possible bad configuration"); |
| 27 | |
} |
| 28 | 0 | pmholder.put(param, value); |
| 29 | 0 | return true; |
| 30 | |
} |
| 31 | |
|
| 32 | |
public String getParameter(String param) throws ParameterHandlingException { |
| 33 | 0 | if (pmholder.containsKey(param)) { |
| 34 | 0 | return pmholder.get(param); |
| 35 | |
} else { |
| 36 | 0 | throw new ParameterHandlingException( |
| 37 | |
"Parameter not found ... faulty configuration!!!"); |
| 38 | |
} |
| 39 | |
} |
| 40 | |
|
| 41 | |
public String toString() { |
| 42 | 0 | StringBuffer sb = new StringBuffer(); |
| 43 | 0 | Iterator<String> it = pmholder.keySet().iterator(); |
| 44 | 0 | while (it.hasNext()) { |
| 45 | 0 | String key = it.next(); |
| 46 | 0 | sb.append(key + " : " + pmholder.get(key) + "\n"); |
| 47 | 0 | } |
| 48 | 0 | return sb.toString(); |
| 49 | |
} |
| 50 | |
|
| 51 | |
public void createParameterXmlContent(Xpp3Dom topology, |
| 52 | |
TopologyHolder tHolder, SortedSet<String> propNames) { |
| 53 | 0 | Xpp3Dom parameters = new Xpp3Dom("Parameters"); |
| 54 | 0 | Xpp3Dom parameter, id, value = null; |
| 55 | |
|
| 56 | 0 | for (String prop : propNames) { |
| 57 | 0 | parameter = new Xpp3Dom("Parameter"); |
| 58 | 0 | id = new Xpp3Dom("Id"); |
| 59 | 0 | value = new Xpp3Dom("Value"); |
| 60 | |
|
| 61 | 0 | id.setValue(prop); |
| 62 | |
String propValue; |
| 63 | |
try { |
| 64 | 0 | propValue = this.getParameter(prop); |
| 65 | 0 | if(propValue.equalsIgnoreCase("<<PARENT>>")){ |
| 66 | 0 | value.setValue(tHolder.getPholder().getParameter(prop)); |
| 67 | |
} |
| 68 | |
else{ |
| 69 | 0 | value.setValue(this.getParameter(prop)); |
| 70 | |
} |
| 71 | 0 | } catch (ParameterHandlingException e) { |
| 72 | |
try { |
| 73 | 0 | value.setValue(tHolder.getPholder().getParameter(prop)); |
| 74 | 0 | } catch (ParameterHandlingException e1) { |
| 75 | |
|
| 76 | 0 | continue; |
| 77 | 0 | } |
| 78 | 0 | } |
| 79 | 0 | parameter.addChild(id); |
| 80 | 0 | parameter.addChild(value); |
| 81 | 0 | parameters.addChild(parameter); |
| 82 | |
|
| 83 | 0 | } |
| 84 | |
|
| 85 | 0 | topology.addChild(parameters); |
| 86 | 0 | } |
| 87 | |
} |