* @throws SAXParseException
* @throws SAXException
*/
public ServiceMergeResults loadConfigurationWithXmlDef(String strXMLDefintion, String tagArguments)
throws IOException, SAXParseException, SAXException {
ServiceMergeResults mergeResults = new ServiceMergeResults();
// ***** REMEMBER *****
// Every time a saveOrUpdateXXXX is made, the entire STORE is written to
// the file system.
// If the STORE has many definitions, then each SAVE will loop over
// every file and write.
//
// NOT GOOD FOR PERFORMANCE
//
// Solution: put the store in a temporary transient state
// (memory-mode-only), then revert to original transient setting,
// which could have been in memory-only or write-to-file in the
// first place.
//
// *********************
Boolean originalTransientState = store.getReadOnlyMode();
store.setReadOnlyMode(true);
// STEP #1. CREATE A TEMP STORE
// Read the incoming XML file, and create a new/temporary store for the
// need to ensure current store doesn't get overridden
//
MockeyXmlFileConfigurationReader msfr = new MockeyXmlFileConfigurationReader();
IMockeyStorage mockServiceStoreTemporary = msfr.readDefinition(strXMLDefintion);
// STEP #2. PROXY SETTINGS
// If the proxy settings are _empty_, then set the incoming
// proxy settings. Otherwise, call out a merge conflict.
//
ProxyServerModel proxyServerModel = store.getProxy();
if (proxyServerModel.hasSettings()) {
mergeResults.addConflictMsg("Proxy settings NOT set from incoming file.");
} else {
store.setProxy(mockServiceStoreTemporary.getProxy());
mergeResults.addAdditionMsg("Proxy settings set.");
}
// STEP #3. BUILD SERVICE REFERENCES
// Why is this needed?
// We are adding _new_ services into the Store, and that means that the
// store's state is always changing. We need references as a saved
// snapshot list of store state prior to adding new services.
// **********
// I forget why we really need this though...
// **********
List<Service> serviceListFromRefs = new ArrayList<Service>();
for (ServiceRef serviceRef : mockServiceStoreTemporary.getServiceRefs()) {
try {
String mockServiceDefinition = getFileContentAsString(new FileInputStream(serviceRef.getFileName()));
// HACK:
// I tried to find an easier way to use XML ENTITY and let
// Digester
// to the work of slurping up the XML but was unsuccessful.
// Hence, the brute force.
// YYYYY
//
List<Service> tmpList = msfr.readServiceDefinition(mockServiceDefinition);
for (Service tmpService : tmpList) {
serviceListFromRefs.add(tmpService);
}
} catch (SAXParseException spe) {
logger.error("Unable to parse file of name " + serviceRef.getFileName(), spe);
mergeResults.addConflictMsg("File not parseable: " + serviceRef.getFileName());
} catch (FileNotFoundException fnf) {
logger.error("File not found: " + serviceRef.getFileName());
mergeResults.addConflictMsg("File not found: " + serviceRef.getFileName());
}
}
addServicesToStore(mergeResults, serviceListFromRefs, tagArguments);
// STEP #4. MERGE SERVICES AND SCENARIOS
// Since this gets complicated, logic was moved to it's own method.
mergeResults = addServicesToStore(mergeResults, mockServiceStoreTemporary.getServices(), tagArguments);
// STEP #5. UNIVERSAL RESPONSE SETTINGS
// Important: usage of the temporary-store's Scenario reference
// information is used to set the primary in-memory store. The primary
// store has all the information and the TEMP store only needs to pass
// the references, e.g. Service 1, Scenario 2.
if (store.getUniversalErrorScenario() != null
&& mockServiceStoreTemporary.getUniversalErrorScenarioRef() != null) {
mergeResults.addConflictMsg("Universal error message already defined with name '"
+ store.getUniversalErrorScenario().getScenarioName() + "'");
} else if (store.getUniversalErrorScenario() == null
&& mockServiceStoreTemporary.getUniversalErrorScenarioRef() != null) {
store.setUniversalErrorScenarioRef(mockServiceStoreTemporary.getUniversalErrorScenarioRef());
mergeResults.addAdditionMsg("Universal error response defined.");
}
// STEP #6. MERGE SERVICE PLANS
for (ServicePlan servicePlan : mockServiceStoreTemporary.getServicePlans()) {