One, based on the spring listener, in the Web. XML configuration
Second, put in the collection, call where needed
1, Interface:
Public interface Uumsyncexceptionlistener {
void Uumempsyncexceptionoccur ();
void Uumorgsyncexceptionoccur ();
void Uumrelationexceptionoccur (list<string> relationdatas);
}
2, implements the interface class, provides the Add collection method, and traverses the collection, calls the corresponding method
@Service (value = "Uumsyncexceptiondispatcher")
public class Uumsyncexceptiondispatcher implements Uumsyncexceptionlistener {
Private static final list<uumsyncexceptionlistener> listeners = new arraylist<uumsyncexceptionlistener> () ;
public void AddListener (Uumsyncexceptionlistener listener) {
Listeners.add (listener);
}
@Override
public void Uumempsyncexceptionoccur () {
for (Uumsyncexceptionlistener listener:listeners) {
Listener.uumempsyncexceptionoccur ();
}
}
@Override
public void Uumorgsyncexceptionoccur () {
for (Uumsyncexceptionlistener listener:listeners) {
Listener.uumorgsyncexceptionoccur ();
}
}
@Override
public void Uumrelationexceptionoccur (list<string> relationdatas) {
for (Uumsyncexceptionlistener listener:listeners) {
Listener.uumrelationexceptionoccur (Relationdatas);
}
}
}
3, realize the interface, the concrete realization business processing logic, and joins collection
@Service (value = "Uumrelationsyncexceptionlistener")
public class Uumrelationsyncexceptionlistener implements Uumsyncexceptionlistener {
@Autowired
Syncfaileddatawriter writer;
@Autowired
public void Initialize (
@Qualifier ("Uumsyncexceptiondispatcher") Uumsyncexceptiondispatcher dispatcher) {
Dispatcher.addlistener (this);
}
@Override
public void Uumempsyncexceptionoccur () {
}
@Override
public void Uumorgsyncexceptionoccur () {
}
@Override
public void Uumrelationexceptionoccur (list<string> relationdatas) {
if (Relationdatas! = null &&!relationdatas.isempty ()) {
StringBuilder sb = new StringBuilder ();
for (String Relationdata:relationdatas) {
Sb.append (Relationdata). Append ("\ n");
}
Writer.write ("Relation_", sb.tostring ());
}
}
}
4, call the Traversal collection related method where needed, call the corresponding concrete implementation
@Autowired
Uumsyncexceptiondispatcher Dispatcher;
@Override
protected void Dotranstodb (String msgId, String text) throws Documentexception {
Document document = NULL;
try {
Document = Documenthelper.parsetext (text);
list<element> elements = document.selectnodes ("//ucimrelation");
This.elementcollection (elements);
} catch (Exception e) {
Logger.error ("receiving department head information, parsing XML error", E);
list<string> Faileddatas = new arraylist<string> ();
Faileddatas.add (text);
Dispatcher.uumrelationexceptionoccur (Faileddatas);
throw new Baseexception ("Parse XML error");
}
}
Spring Custom Listener