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 InboundConnectionList extends AbstractModelClass {
49
50 public static final String PROP_LIST = InboundConnectionList.class.getName() + "_LIST";
51
52 private List<InboundConnection> myConnections = new ArrayList<InboundConnection>();
53
54 private transient Controller myController;
55
56 public InboundConnectionList() {
57 }
58
59 public InboundConnection createDefaultConnection(int port) {
60 InboundConnection initialConnection = new InboundConnection();
61 initialConnection.setCharSet(Prefs.getInstance().getMostRecentConnectionCharset().displayName());
62 initialConnection.setDualPort(false);
63 initialConnection.setIncomingOrSinglePort(port);
64 initialConnection.setHost("localhost");
65 initialConnection.setEncoding(Hl7V2EncodingTypeEnum.ER_7);
66 initialConnection.setController(myController);
67 return initialConnection;
68 }
69
70 @Override
71 public String exportConfigToXml() {
72 StringWriter writer = new StringWriter();
73 JAXB.marshal(this, writer);
74 return writer.toString();
75 }
76
77 public static InboundConnectionList fromXml(Controller theController, String theXml) {
78 InboundConnectionList retVal = JAXB.unmarshal(new StringReader(theXml), InboundConnectionList.class);
79 retVal.myController = theController;
80
81 for (InboundConnection next : retVal.getConnections()) {
82 next.setController(theController);
83 }
84
85 return retVal;
86 }
87
88
89
90
91 public List<InboundConnection> getConnections() {
92 return myConnections;
93 }
94
95 public void addConnection(InboundConnection theCon) {
96 Validate.notNull(theCon);
97
98 myConnections.add(theCon);
99 theCon.setController(myController);
100
101 firePropertyChange(PROP_LIST, null, null);
102 }
103
104 public void removeConnecion(InboundConnection theCon) {
105 Validate.notNull(theCon);
106 myConnections.remove(theCon);
107 firePropertyChange(PROP_LIST, null, null);
108 }
109
110
111
112
113 public void removeNonPersistantConnections() {
114 for (Iterator<InboundConnection> iter = myConnections.iterator(); iter.hasNext(); ) {
115 if (!iter.next().isPersistent()) {
116 iter.remove();
117 }
118 }
119 }
120
121 public InboundConnection getWithId(String theId) {
122 for (InboundConnection next : myConnections) {
123 if (next.getId().equals(theId)) {
124 return next;
125 }
126 }
127 return null;
128 }
129
130
131 }