String dataStoreID = dataStoresForm.getDataStoreId();
String namespace = dataStoresForm.getNamespaceId();
String description = dataStoresForm.getDescription();
DataConfig dataConfig = (DataConfig) getDataConfig();
DataStoreConfig config = null;
config = (DataStoreConfig) dataConfig.getDataStore(dataStoreID);
if( config == null ) {
// we are creating a new one.
dataConfig.addDataStore(getUserContainer(request).getDataStoreConfig());
config = (DataStoreConfig) dataConfig.getDataStore(dataStoreID);
}
// After extracting params into a map
Map connectionParams = new HashMap(); // values used for connection
Map paramTexts = new HashMap(); // values as stored
Map params = dataStoresForm.getParams();
DataStoreFactorySpi factory = config.getFactory();
Param[] info = factory.getParametersInfo();
// Convert Params into the kind of Map we actually need
//
for (Iterator i = params.keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
Param param = DataStoreUtils.find(info, key);
if (param == null) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.cannotProcessConnectionParams"));
saveErrors(request, errors);
return mapping.findForward("config.data.store.editor");
}
Object value;
try {
value = param.lookUp(params);
} catch (IOException erp) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.cannotProcessConnectionParams"));
saveErrors(request, errors);
return mapping.findForward("config.data.store.editor");
}
if (value != null) {
connectionParams.put(key, value);
String text = param.text(value);
paramTexts.put(key, text);
}
}
// put magic namespace into the mix
// not sure if we want to do this, as we want the full namespace, not
//the id. But getParams in DataStore may override this - ch
connectionParams.put("namespace", dataStoresForm.getNamespaceId());
paramTexts.put("namespace", dataStoresForm.getNamespaceId());
//dump("editor", connectionParams );
//dump("texts ",paramTexts );
if (!factory.canProcess(connectionParams)) {
// We could not use these params!
//
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.cannotProcessConnectionParams"));
saveErrors(request, errors);
return mapping.findForward("config.data.store.editor");
}
try {
ServletContext sc = request.getSession().getServletContext();
Map niceParams = DataStoreUtils.getParams(connectionParams, sc);
DataStore victim = factory.createDataStore(niceParams);
if (victim == null) {
// We *really* could not use these params!
//
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.invalidConnectionParams"));
saveErrors(request, errors);
return mapping.findForward("config.data.store.editor");
}
String typeNames[] = victim.getTypeNames();
dump( "typeNames", typeNames );
} catch (Throwable throwable) {
throwable.printStackTrace();
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.exception", throwable.getMessage()));
saveErrors(request, errors);
return mapping.findForward("config.data.store.editor");
}
boolean enabled = dataStoresForm.isEnabled();
if (dataStoresForm.isEnabledChecked() == false) {
enabled = false;
}
config.setEnabled(enabled);
config.setNameSpaceId(namespace);
config.setAbstract(description);
config.setConnectionParams(paramTexts);
dataConfig.addDataStore(config);
getUserContainer(request).setDataStoreConfig(null);
getApplicationState().notifyConfigChanged();
return mapping.findForward("config.data.store");