1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package ca.uhn.hl7v2.testpanel.model.conn;
27
28 import java.io.StringReader;
29 import java.io.StringWriter;
30 import java.util.ArrayList;
31 import java.util.Iterator;
32 import java.util.List;
33
34 import jakarta.xml.bind.JAXB;
35 import jakarta.xml.bind.annotation.XmlAccessType;
36 import jakarta.xml.bind.annotation.XmlAccessorType;
37 import jakarta.xml.bind.annotation.XmlType;
38
39 import org.apache.commons.lang.Validate;
40
41 import ca.uhn.hl7v2.testpanel.controller.Controller;
42 import ca.uhn.hl7v2.testpanel.controller.Prefs;
43 import ca.uhn.hl7v2.testpanel.model.AbstractModelClass;
44 import ca.uhn.hl7v2.testpanel.xsd.Hl7V2EncodingTypeEnum;
45
46 @XmlAccessorType(XmlAccessType.FIELD)
47 @XmlType(name = "InboundConnectionList")
48 public class OutboundConnectionList extends AbstractModelClass {
49
50 public static final String PROP_LIST = OutboundConnectionList.class.getName() + "_LIST";
51
52 private List<OutboundConnection> myConnections = new ArrayList<OutboundConnection>();
53
54 public OutboundConnectionList() {
55 }
56
57 public void addConnection(OutboundConnection theCon) {
58 Validate.notNull(theCon);
59 myConnections.add(theCon);
60 firePropertyChange(PROP_LIST, null, null);
61 }
62
63 public OutboundConnection createDefaultConnection(int port) {
64 OutboundConnection initialConnection = new OutboundConnection();
65 initialConnection.setCharSet(Prefs.getInstance().getMostRecentConnectionCharset().displayName());
66 initialConnection.setDualPort(false);
67 initialConnection.setIncomingOrSinglePort(port);
68 initialConnection.setHost("localhost");
69 initialConnection.setEncoding(Hl7V2EncodingTypeEnum.ER_7);
70 return initialConnection;
71 }
72
73 @Override
74 public String exportConfigToXml() {
75 StringWriter writer = new StringWriter();
76 JAXB.marshal(this, writer);
77 return writer.toString();
78 }
79
80 public static OutboundConnectionList fromXml(Controller theController, String theXml) {
81 OutboundConnectionList retVal = JAXB.unmarshal(new StringReader(theXml), OutboundConnectionList.class);
82
83 for (OutboundConnection next : retVal.getConnections()) {
84 next.setController(theController);
85 }
86
87 return retVal;
88 }
89
90
91
92
93 public List<OutboundConnection> getConnections() {
94 return myConnections;
95 }
96
97 public void removeConnecion(OutboundConnection theCon) {
98 Validate.notNull(theCon);
99 myConnections.remove(theCon);
100 firePropertyChange(PROP_LIST, null, null);
101 }
102
103
104
105
106 public void removeNonPersistantConnections() {
107 for (Iterator<OutboundConnection> iter = myConnections.iterator(); iter.hasNext(); ) {
108 if (!iter.next().isPersistent()) {
109 iter.remove();
110 }
111 }
112 }
113
114 public OutboundConnection getWithId(String theId) {
115 for (OutboundConnection next : myConnections) {
116 if (next.getId().equals(theId)) {
117 return next;
118 }
119 }
120 return null;
121 }
122
123
124 }