use of javax.naming.NameNotFoundException in project Payara by payara.
the class FileDirContext method unbind.
/**
* Unbinds the named object. Removes the terminal atomic name in name
* from the target context--that named by all but the terminal atomic
* part of name.
* <p>
* This method is idempotent. It succeeds even if the terminal atomic
* name is not bound in the target context, but throws
* NameNotFoundException if any of the intermediate contexts do not exist.
*
* @param name the name to bind; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NamingException if a naming exception is encountered
*/
public void unbind(String name) throws NamingException {
File file = file(name, true);
if (file == null)
throw new NameNotFoundException(MessageFormat.format(rb.getString(LogFacade.RESOURCES_NOT_FOUND), name));
// START S1AS8PE 4965170
fileCache.remove(name);
// END S1AS8PE 4965170
if (!file.delete())
throw new NamingException(MessageFormat.format(rb.getString(LogFacade.RESOURCES_NOT_FOUND), name));
}
use of javax.naming.NameNotFoundException in project Payara by payara.
the class GlassfishNamingManagerImpl method createSubContexts.
/**
* Create any sub-contexts in name that don't already exist.
*
* @param name Name containing sub-contexts to create
* @param rootCtx in which sub-contexts should be created
* @throws Exception
*/
private void createSubContexts(Name name, Context rootCtx) throws NamingException {
int numSubContexts = name.size() - 1;
Context currentCtx = rootCtx;
for (int subCtxIndex = 0; subCtxIndex < numSubContexts; subCtxIndex++) {
String subCtxName = name.get(subCtxIndex);
try {
Object obj = currentCtx.lookup(subCtxName);
if (obj == null) {
// Doesn't exist so create it.
currentCtx = currentCtx.createSubcontext(subCtxName);
} else if (obj instanceof Context) {
// OK -- no need to create it.
currentCtx = (Context) obj;
} else {
// Context name clashes with existing object.
throw new NameAlreadyBoundException(subCtxName);
}
} catch (NameNotFoundException e) {
// Doesn't exist so create it.
currentCtx = currentCtx.createSubcontext(subCtxName);
}
}
// End for -- each sub-context
}
use of javax.naming.NameNotFoundException in project Payara by payara.
the class GlassfishNamingManagerImpl method lookup.
private Object lookup(String componentId, String name, Context ctx) throws NamingException {
ComponentIdInfo info = componentIdInfo.get(componentId);
String logicalJndiName = name;
boolean replaceName = (info != null) && (info.treatComponentAsModule) && name.startsWith("java:comp");
if (replaceName) {
logicalJndiName = logicalCompJndiNameToModule(name);
}
Map namespace = getNamespace(componentId, logicalJndiName);
Object obj = namespace.get(logicalJndiName);
if (obj == null) {
throw new NameNotFoundException("No object bound to name " + name);
}
if (obj instanceof NamingObjectProxy) {
NamingObjectProxy namingProxy = (NamingObjectProxy) obj;
obj = namingProxy.create(ctx);
} else if (obj instanceof Context) {
// and return that.
if (replaceName) {
obj = new JavaURLContext(name, null);
}
if (obj instanceof JavaURLContext) {
if (ctx instanceof SerialContext) {
obj = new JavaURLContext((JavaURLContext) obj, (SerialContext) ctx);
} else {
obj = new JavaURLContext((JavaURLContext) obj, null);
}
}
}
return obj;
}
use of javax.naming.NameNotFoundException in project Payara by payara.
the class GlassfishNamingManagerImpl method listNames.
private ArrayList listNames(String name) throws NamingException {
// Get the component id and namespace to lookup
String componentId = getComponentId();
ComponentIdInfo info = componentIdInfo.get(componentId);
String logicalJndiName = name;
boolean replaceName = (info != null) && (info.treatComponentAsModule) && name.startsWith("java:comp");
if (replaceName) {
logicalJndiName = logicalCompJndiNameToModule(name);
}
Map namespace = getNamespace(componentId, logicalJndiName);
Object obj = namespace.get(logicalJndiName);
if (obj == null) {
throw new NameNotFoundException("No object bound to name " + name);
}
if (!(obj instanceof JavaURLContext)) {
throw new NotContextException(name + " cannot be listed");
}
// This iterates over all names in entire component namespace,
// so its a little inefficient. The alternative is to store
// a list of bindings in each javaURLContext instance.
ArrayList list = new ArrayList();
Iterator itr = namespace.keySet().iterator();
if (!logicalJndiName.endsWith("/")) {
logicalJndiName = logicalJndiName + "/";
}
while (itr.hasNext()) {
String key = (String) itr.next();
// The search string itself is excluded from the returned list
if (key.startsWith(logicalJndiName) && key.indexOf('/', logicalJndiName.length()) == -1 && !key.equals(logicalJndiName)) {
String toAdd = replaceName ? logicalModuleJndiNameToComp(key) : key;
list.add(toAdd);
}
}
return list;
}
use of javax.naming.NameNotFoundException in project cayenne by apache.
the class JMSBridge method startupExternal.
/**
* Starts up JMS machinery for "publish/subscribe" model.
*/
@Override
protected void startupExternal() throws Exception {
Context jndiContext = new InitialContext();
TopicConnectionFactory connectionFactory = (TopicConnectionFactory) jndiContext.lookup(topicConnectionFactoryName);
Topic topic = null;
try {
topic = (Topic) jndiContext.lookup(externalSubject);
} catch (NameNotFoundException ex) {
// can't find topic, try to create it
topic = topicNotFound(jndiContext, ex);
if (topic == null) {
throw ex;
}
}
// config publisher
if (receivesLocalEvents()) {
this.sendConnection = connectionFactory.createTopicConnection();
this.sendSession = sendConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
this.publisher = sendSession.createPublisher(topic);
}
// config subscriber
if (receivesExternalEvents()) {
this.receivedConnection = connectionFactory.createTopicConnection();
this.subscriber = receivedConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE).createSubscriber(topic);
this.subscriber.setMessageListener(this);
this.receivedConnection.start();
}
}
Aggregations