use of javax.naming.directory.DirContext in project Payara by payara.
the class StandardContext method listCollectionPaths.
/**
* List resource paths (recursively), and store all of them in the given
* Set.
*/
private static void listCollectionPaths(Set<String> set, DirContext resources, String path) throws NamingException {
Enumeration<Binding> childPaths = resources.listBindings(path);
while (childPaths.hasMoreElements()) {
Binding binding = childPaths.nextElement();
String name = binding.getName();
StringBuilder childPath = new StringBuilder(path);
if (!"/".equals(path) && !path.endsWith("/"))
childPath.append("/");
childPath.append(name);
Object object = binding.getObject();
if (object instanceof DirContext && childPath.charAt(childPath.length() - 1) != '/') {
childPath.append("/");
}
set.add(childPath.toString());
}
}
use of javax.naming.directory.DirContext in project Payara by payara.
the class StandardContext method alternateResourcesStop.
/**
* Stops this context's alternate doc base resources.
*/
public boolean alternateResourcesStop() {
boolean ok = true;
if (alternateDocBases == null || alternateDocBases.isEmpty()) {
return ok;
}
for (AlternateDocBase alternateDocBase : alternateDocBases) {
final DirContext alternateResources = ContextsAdapterUtility.unwrap(alternateDocBase.getResources());
if (alternateResources instanceof Lifecycle) {
try {
((Lifecycle) alternateResources).stop();
} catch (Throwable t) {
log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
ok = false;
}
}
final DirContext alternateWebappResources = ContextsAdapterUtility.unwrap(alternateDocBase.getWebappResources());
if (alternateWebappResources instanceof BaseDirContext) {
try {
((BaseDirContext) alternateWebappResources).release();
} catch (Throwable t) {
log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
ok = false;
}
}
}
this.alternateDocBases = null;
return (ok);
}
use of javax.naming.directory.DirContext in project Payara by payara.
the class StandardContext method alternateResourcesStart.
/**
* Starts this context's alternate doc base resources.
*/
public void alternateResourcesStart() throws LifecycleException {
if (alternateDocBases == null || alternateDocBases.isEmpty()) {
return;
}
Hashtable<String, String> env = new Hashtable<String, String>();
if (getParent() != null) {
env.put(ProxyDirContext.HOST, getParent().getName());
}
env.put(ProxyDirContext.CONTEXT, getName());
for (AlternateDocBase alternateDocBase : alternateDocBases) {
String basePath = alternateDocBase.getBasePath();
DirContext alternateWebappResources = ContextsAdapterUtility.unwrap(alternateDocBase.getWebappResources());
try {
ProxyDirContext proxyDirContext = new ProxyDirContext(env, alternateWebappResources);
if (alternateWebappResources instanceof BaseDirContext) {
((BaseDirContext) alternateWebappResources).setDocBase(basePath);
((BaseDirContext) alternateWebappResources).allocate();
}
alternateDocBase.setResources(ContextsAdapterUtility.wrap(proxyDirContext));
} catch (Throwable t) {
if (log.isLoggable(Level.FINE)) {
String msg = MessageFormat.format(rb.getString(LogFacade.STARTING_RESOURCES_EXCEPTION), getName());
throw new LifecycleException(msg, t);
} else {
String msg = MessageFormat.format(rb.getString(LogFacade.STARTING_RESOURCE_EXCEPTION_MESSAGE), new Object[] { getName(), t.getMessage() });
throw new LifecycleException(msg);
}
}
}
}
use of javax.naming.directory.DirContext in project Payara by payara.
the class StandardContext method setResources.
/**
* Set the resources DirContext object with which this Container is
* associated.
*
* @param resources The newly associated DirContext
*/
@Override
public synchronized void setResources(DirContext resources) {
if (started) {
throw new IllegalStateException(rb.getString(LogFacade.RESOURCES_STARTED));
}
DirContext oldResources = this.webappResources;
if (oldResources == resources)
return;
if (resources instanceof BaseDirContext) {
BaseDirContext baseDirContext = (BaseDirContext) resources;
baseDirContext.setCached(isCachingAllowed());
baseDirContext.setCacheTTL(getCacheTTL());
baseDirContext.setCacheMaxSize(getCacheMaxSize());
}
if (resources instanceof FileDirContext) {
filesystemBased = true;
FileDirContext fileDirContext = (FileDirContext) resources;
fileDirContext.setCaseSensitive(isCaseSensitive());
fileDirContext.setAllowLinking(isAllowLinking());
}
this.webappResources = resources;
// The proxied resources will be refreshed on start
this.resources = null;
support.firePropertyChange("resources", oldResources, this.webappResources);
}
use of javax.naming.directory.DirContext in project Payara by payara.
the class ProxyDirContext method createSubcontext.
/**
* Creates and binds a new context, along with associated attributes.
* This method creates a new subcontext with the given name, binds it in
* the target context (that named by all but terminal atomic component of
* the name), and associates the supplied attributes with the newly
* created object. All intermediate and target contexts must already
* exist. If attrs is null, this method is equivalent to
* Context.createSubcontext().
*
* @param name the name of the context to create; may not be empty
* @param attrs the attributes to associate with the newly created context
* @return the newly created context
* @exception javax.naming.NameAlreadyBoundException if the name is already
* bound
* @exception javax.naming.directory.InvalidAttributesException if attrs
* does not contain all the mandatory attributes required for creation
* @exception NamingException if a naming exception is encountered
*/
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
DirContext context = dirContext.createSubcontext(parseName(name), attrs);
cacheUnload(name.toString());
return context;
}
Aggregations