use of com.sun.messaging.jmq.admin.objstore.NameNotFoundException in project openmq by eclipse-ee4j.
the class CmdRunner method runUpdateCommand.
private int runUpdateCommand(ObjMgrProperties objMgrProps) {
int exitcode = 0;
String input = null;
Object object = null;
String type = null;
ObjStore os;
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 the lookup name
*/
String lookupName = objMgrProps.getLookupName();
/*
* Check if -f (force) was specified on cmd line.
*/
boolean force = objMgrProps.forceModeSet();
ObjStoreAttrs osa = objMgrProps.getObjStoreAttrs();
/*
* Check for any mandatory bind attrs and display warning, if necessary.
*/
checkObjStoreAttrs(osa);
Properties objProps = objMgrProps.getObjProperties();
type = objMgrProps.getObjType();
Attributes bindAttrs = objMgrProps.getBindAttrs();
printUpdateCmdDescription(type, lookupName, objProps, osa, objMgrProps.readOnlyValue());
os = createStore(osa);
if (os == null) {
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_OBJ_UPDATE_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_UPDATE_FAILED));
return (1);
}
/*
* Updates only work if the object already exists so check if one already exists.
*/
try {
object = os.retrieve(lookupName);
} catch (NameNotFoundException nnfe) {
Globals.stdErrPrintln(ar.getKString(ar.E_CANNOT_LOC_OBJ, lookupName));
Globals.stdOutPrintln("");
Globals.stdErrPrintln(ar.getString(ar.I_OBJ_UPDATE_FAILED));
return (1);
} catch (Exception e) {
handleRunCommandExceptions(e, lookupName);
Globals.stdOutPrintln("");
Globals.stdErrPrintln(ar.getString(ar.I_OBJ_UPDATE_FAILED));
return (1);
}
/*
* Check here if the type being updated and the type specified match.
*/
if (object != null) {
type = checkObjectType(object, type);
if (type == null) {
Globals.stdOutPrintln("");
Globals.stdErrPrintln(ar.getString(ar.I_OBJ_UPDATE_FAILED));
return (1);
}
} else {
// object == null
// Should not happen, since if the object cannot be retrieved,
// it should throw NameNotFoundException
Globals.stdErrPrintln(ar.getKString(ar.E_CANNOT_LOC_OBJ, lookupName));
Globals.stdOutPrintln("");
Globals.stdErrPrintln(ar.getString(ar.I_OBJ_UPDATE_FAILED));
return (1);
}
if (!force) {
// was the case.
if (object instanceof AdministeredObject) {
AdministeredObject adminObj = (AdministeredObject) object;
String curVersion = adminObj.getVERSION();
String objVersion = adminObj.getStoredVersion();
if (!adminObj.isStoredVersionCompatible()) {
Globals.stdErrPrintln(ar.getString(ar.W_INCOMPATIBLE_OBJ, objVersion, curVersion));
}
}
input = getUserInput(ar.getString(ar.Q_UPDATE_OK), noShort);
}
if (noShort.equalsIgnoreCase(input) || no.equalsIgnoreCase(input)) {
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_OBJ_NOT_UPDATED));
/*
* 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)) || (force))) {
/*
* Update the object with the new properties.
*/
Object updatedObject = updateObject(object, type, objMgrProps);
if (updatedObject == null)
return 1;
/*
* Add the object to object store.
*/
try {
if (bindAttrs.size() > 0)
os.add(lookupName, updatedObject, bindAttrs, true);
else
os.add(lookupName, updatedObject, true);
} catch (NameAlreadyExistsException naee) {
// Should never happen, since we pass true to add
exitcode = 1;
} catch (Exception e) {
handleRunCommandExceptions(e, lookupName);
exitcode = 1;
}
if (exitcode == 0) {
if (!force)
Globals.stdErrPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_OBJ_UPDATED));
} else {
Globals.stdErrPrintln("");
Globals.stdErrPrintln(ar.getString(ar.I_OBJ_UPDATE_FAILED));
}
} else {
Globals.stdOutPrintln(ar.getString(ar.I_UNRECOGNIZED_RES, input));
Globals.stdErrPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_OBJ_NOT_UPDATED));
exitcode = 1;
}
return (exitcode);
}
use of com.sun.messaging.jmq.admin.objstore.NameNotFoundException in project openmq by eclipse-ee4j.
the class CmdRunner method listByType.
/**
* List JMS administration objects of particular type.
*/
private int listByType(ObjStore os, String type) {
Vector v = null;
try {
v = os.list();
} catch (NameNotFoundException nnfe) {
Globals.stdErrPrintln(ar.getString(ar.I_ERROR_MESG), ar.getKString(ar.E_CANNOT_LOC_TREE));
return (1);
} catch (Exception e) {
handleRunCommandExceptions(e);
return (1);
}
ObjMgrPrinter omp = new ObjMgrPrinter(2, 4);
String[] row = new String[2];
row[0] = ar.getString(ar.I_JNDI_LOOKUPNAME);
row[1] = ar.getString(ar.I_OBJ_CLASS_NAME);
omp.addTitle(row);
for (int i = 0; i < v.size(); i++) {
NameClassPair obj = (NameClassPair) v.get(i);
if ((type.equals(OBJMGR_TYPE_TOPIC) && com.sun.messaging.Topic.class.getName().equals(obj.getClassName())) || (type.equals(OBJMGR_TYPE_QUEUE) && com.sun.messaging.Queue.class.getName().equals(obj.getClassName())) || (type.equals(OBJMGR_TYPE_TCF) && com.sun.messaging.TopicConnectionFactory.class.getName().equals(obj.getClassName())) || (type.equals(OBJMGR_TYPE_QCF) && com.sun.messaging.QueueConnectionFactory.class.getName().equals(obj.getClassName())) || (type.equals(OBJMGR_TYPE_CF) && com.sun.messaging.ConnectionFactory.class.getName().equals(obj.getClassName())) || (type.equals(OBJMGR_TYPE_XTCF) && com.sun.messaging.XATopicConnectionFactory.class.getName().equals(obj.getClassName())) || (type.equals(OBJMGR_TYPE_XQCF) && com.sun.messaging.XAQueueConnectionFactory.class.getName().equals(obj.getClassName())) || (type.equals(OBJMGR_TYPE_XCF) && com.sun.messaging.XAConnectionFactory.class.getName().equals(obj.getClassName()))) {
row[0] = obj.getName();
row[1] = obj.getClassName();
omp.add(row);
}
}
omp.print();
return (0);
}
use of com.sun.messaging.jmq.admin.objstore.NameNotFoundException in project openmq by eclipse-ee4j.
the class CmdRunner method listAll.
/**
* List JMS administration objects.
*/
private int listAll(ObjStore os) {
Vector v = null;
try {
v = os.list();
} catch (NameNotFoundException nnfe) {
Globals.stdErrPrintln(ar.getString(ar.I_ERROR_MESG), ar.getKString(ar.E_CANNOT_LOC_TREE));
return (1);
} catch (Exception e) {
handleRunCommandExceptions(e);
return (1);
}
ObjMgrPrinter omp = new ObjMgrPrinter(2, 4);
String[] row = new String[2];
row[0] = ar.getString(ar.I_JNDI_LOOKUPNAME);
row[1] = ar.getString(ar.I_OBJ_CLASS_NAME);
omp.addTitle(row);
for (int i = 0; i < v.size(); i++) {
NameClassPair obj = (NameClassPair) v.get(i);
if ((com.sun.messaging.Topic.class.getName().equals(obj.getClassName())) || (com.sun.messaging.Queue.class.getName().equals(obj.getClassName())) || (com.sun.messaging.TopicConnectionFactory.class.getName().equals(obj.getClassName())) || (com.sun.messaging.QueueConnectionFactory.class.getName().equals(obj.getClassName())) || (com.sun.messaging.ConnectionFactory.class.getName().equals(obj.getClassName())) || (com.sun.messaging.XATopicConnectionFactory.class.getName().equals(obj.getClassName())) || (com.sun.messaging.XAQueueConnectionFactory.class.getName().equals(obj.getClassName())) || (com.sun.messaging.XAConnectionFactory.class.getName().equals(obj.getClassName()))) {
row[0] = obj.getName();
row[1] = obj.getClassName();
omp.add(row);
}
}
omp.print();
return (0);
}
use of com.sun.messaging.jmq.admin.objstore.NameNotFoundException in project openmq by eclipse-ee4j.
the class CmdRunner method createStore.
/*
* 02/05/2001 Creates a store.
*/
private ObjStore createStore(ObjStoreAttrs osa) {
if (osa == null) {
return (null);
}
ObjStore os = null;
/*
* Create ObjStore
*/
try {
ObjStoreManager osmgr = ObjStoreManager.getObjStoreManager();
os = osmgr.createStore(osa);
} catch (NameNotFoundException nnfe) {
Globals.stdErrPrintln(ar.getString(ar.I_ERROR_MESG), ar.getKString(ar.E_CANNOT_LOC_TREE));
} catch (ObjStoreException e) {
handleRunCommandExceptions(e);
}
return (os);
}
Aggregations