omp2.print();
Globals.stdOutPrintln("");
}
private int runAddCommand(ObjMgrProperties objMgrProps) {
ObjStore os;
int exitcode = 0;
String input = null;
Object object = null;
String yes, yesShort, no, noShort;
yes = ar.getString(ar.Q_RESPONSE_YES);
yesShort = ar.getString(ar.Q_RESPONSE_YES_SHORT);
no = ar.getString(ar.Q_RESPONSE_NO);
noShort = ar.getString(ar.Q_RESPONSE_NO_SHORT);
/*
* Get object type, props object, and lookup name
*/
String type = objMgrProps.getObjType();
Properties objProps = objMgrProps.getObjProperties();
String lookupName = objMgrProps.getLookupName();
ObjStoreAttrs osa = objMgrProps.getObjStoreAttrs();
/*
* Check for any mandatory bind attrs and display warning,
* if necessary.
*/
checkObjStoreAttrs(osa);
Attributes bindAttrs = objMgrProps.getBindAttrs();
/*
* Check if -f (force) was specified on cmd line.
*/
boolean force = objMgrProps.forceModeSet();
/*
* Create JMS Object with the specified properties.
*/
Object newObj = null;
try {
if (type.equals(OBJMGR_TYPE_QUEUE)) {
newObj = JMSObjFactory.createQueue(objProps);
} else if (type.equals(OBJMGR_TYPE_TOPIC)) {
newObj = JMSObjFactory.createTopic(objProps);
} else if (type.equals(OBJMGR_TYPE_QCF)) {
newObj = JMSObjFactory.createQueueConnectionFactory(objProps);
} else if (type.equals(OBJMGR_TYPE_TCF)) {
newObj = JMSObjFactory.createTopicConnectionFactory(objProps);
} else if (type.equals(OBJMGR_TYPE_CF)) {
newObj = JMSObjFactory.createConnectionFactory(objProps);
} else if (type.equals(OBJMGR_TYPE_XTCF)) {
newObj = JMSObjFactory.createXATopicConnectionFactory(objProps);
} else if (type.equals(OBJMGR_TYPE_XQCF)) {
newObj = JMSObjFactory.createXAQueueConnectionFactory(objProps);
} else if (type.equals(OBJMGR_TYPE_XCF)) {
newObj = JMSObjFactory.createXAConnectionFactory(objProps);
}
} catch (Exception e) {
handleRunCommandExceptions(e, lookupName);
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_OBJ_ADD_FAILED));
return(1);
}
/*
* Set this newly created obj to read-only if specified.
*/
JMSObjFactory.doReadOnlyForAdd(newObj, objMgrProps.readOnlyValue());
printAddCmdDescription(newObj, type, lookupName, osa,
objMgrProps.readOnlyValue());
os = createStore(osa);
if (os == null) {
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_OBJ_ADD_FAILED));
return(1);
}
/*
* Prompt for missing authentication info BEFORE opening the store.
*/
if (!force) {
// Update ObjStoreAttrs in ths ObjStore if some security
// info was missing.
os = promptForAuthentication(os);
}
/*
* Open/Initialize the object store
*/
try {
openStore(os);
} catch (Exception e) {
handleRunCommandExceptions(e, lookupName);
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_OBJ_ADD_FAILED));
return(1);
}
/*
* If no -f option, check if the object already exists
* so we can confirm with user to overwrite.
*/
if (!force) {
try {
object = os.retrieve(lookupName);
} catch (NameNotFoundException nnfe) {
// Make sure that this exception is NOT treated as an error for add
;
} catch (Exception e) {
handleRunCommandExceptions(e, lookupName);
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_OBJ_ADD_FAILED));
return(1);
}
// Object already exists so confirm with user.
if (object != null) {
Globals.stdOutPrintln(
ar.getCString(ar.I_WARNING_MESG),
ar.getString(ar.W_OBJ_ALREADY_EXISTS, lookupName));
Globals.stdOutPrintln(
ar.getCString(ar.I_WARNING_MESG),
ar.getString(ar.W_ADD_OBJ_BE_OVERWRITTEN));
input = getUserInput(ar.getString(ar.Q_OVERWRITE_OK), noShort);
}
}
if (noShort.equalsIgnoreCase(input) || no.equalsIgnoreCase(input)) {
Globals.stdOutPrintln("");
Globals.stdOutPrintln(
ar.getString(ar.I_OBJ_NOT_ADDED));
/*
* Case where user typed 'y' or 'yes' to overwrite OR
* case where object doesn't exist yet so no confirmation needed OR
* case where user used -f.
*/
} else if ((yesShort.equalsIgnoreCase(input) ||
yes.equalsIgnoreCase(input)) ||
(object == null) ||
(force)) {
/*
* Update the object in object store.
*/
try {
if (bindAttrs.size() > 0)
os.add(lookupName, newObj, bindAttrs, true);
else
os.add(lookupName, newObj, true);
} catch (NameAlreadyExistsException naee) {
; // Should never happen, since we pass true to add
} catch (NameNotFoundException nnfe) {