Search in sources :

Example 1 with JNDIBinding

use of org.glassfish.api.naming.JNDIBinding in project Payara by payara.

the class GlassfishNamingManagerImpl method bindToComponentNamespace.

/**
 * This method enumerates the env properties, ejb and resource references
 * etc for a J2EE component and binds them in the component's java:comp
 * namespace.
 * @param appName
 * @param moduleName
 * @param componentId
 * @param bindings
 * @throws javax.naming.NamingException
 */
@Override
public void bindToComponentNamespace(String appName, String moduleName, String componentId, boolean treatComponentAsModule, Collection<? extends JNDIBinding> bindings) throws NamingException {
    // These are null in rare cases, e.g. default web app.
    if ((appName != null) && (moduleName != null)) {
        ComponentIdInfo info = new ComponentIdInfo();
        info.appName = appName;
        info.moduleName = moduleName;
        info.componentId = componentId;
        info.treatComponentAsModule = treatComponentAsModule;
        componentIdInfo.put(componentId, info);
    }
    for (JNDIBinding binding : bindings) {
        String logicalJndiName = binding.getName();
        Map namespace = null;
        if (treatComponentAsModule && logicalJndiName.startsWith("java:comp")) {
            logicalJndiName = logicalCompJndiNameToModule(logicalJndiName);
        }
        if (logicalJndiName.startsWith("java:comp")) {
            namespace = getComponentNamespace(componentId);
        } else if (logicalJndiName.startsWith("java:module")) {
            namespace = getModuleNamespace(new AppModuleKey(appName, moduleName));
        } else if (logicalJndiName.startsWith("java:app")) {
            namespace = getAppNamespace(appName);
        }
        if (namespace != null) {
            if (!existsInNamespace(namespace, logicalJndiName)) {
                bindToNamespace(namespace, logicalJndiName, binding.getValue());
            }
        }
    }
}
Also used : JNDIBinding(org.glassfish.api.naming.JNDIBinding) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with JNDIBinding

use of org.glassfish.api.naming.JNDIBinding in project Payara by payara.

the class ResourceNamingService method publishObject.

public void publishObject(GenericResourceInfo resourceInfo, String jndiName, Object object, boolean rebind) throws NamingException {
    String applicationName = resourceInfo.getApplicationName();
    String moduleName = resourceInfo.getModuleName();
    moduleName = org.glassfish.resourcebase.resources.util.ResourceUtil.getActualModuleName(moduleName);
    if (!isGlobalName(resourceInfo.getName()) && applicationName != null && moduleName != null) {
        Object alreadyBoundObject = null;
        if (rebind) {
            try {
                namingManager.unbindModuleObject(applicationName, moduleName, getModuleScopedName(jndiName));
            } catch (NameNotFoundException e) {
            // ignore
            }
        } else {
            try {
                alreadyBoundObject = namingManager.lookupFromModuleNamespace(applicationName, moduleName, getModuleScopedName(jndiName), null);
            } catch (NameNotFoundException e) {
            // ignore
            }
            if (alreadyBoundObject != null) {
                throw new NamingException("Object already bound for jndiName " + "[ " + jndiName + " ] of  module namespace [" + moduleName + "] " + "of application [" + applicationName + "] ");
            }
        }
        JNDIBinding bindings = new ModuleScopedResourceBinding(getModuleScopedName(jndiName), object);
        List<JNDIBinding> list = new ArrayList<JNDIBinding>();
        list.add(bindings);
        if (_logger.isLoggable(Level.FINEST)) {
            debug("application=" + applicationName + ", module name=" + moduleName + ", binding name=" + jndiName);
        }
        namingManager.bindToModuleNamespace(applicationName, moduleName, list);
    } else if (!isGlobalName(resourceInfo.getName()) && applicationName != null) {
        Object alreadyBoundObject = null;
        if (rebind) {
            try {
                namingManager.unbindAppObject(applicationName, getAppScopedName(jndiName));
            } catch (NameNotFoundException e) {
            // ignore
            }
        } else {
            try {
                alreadyBoundObject = namingManager.lookupFromAppNamespace(applicationName, getAppScopedName(jndiName), null);
            } catch (NameNotFoundException e) {
            // ignore
            }
            if (alreadyBoundObject != null) {
                throw new NamingException("Object already bound for jndiName " + "[ " + jndiName + " ] of application's namespace [" + applicationName + "]");
            }
        }
        JNDIBinding bindings = new ApplicationScopedResourceBinding(getAppScopedName(jndiName), object);
        List<JNDIBinding> list = new ArrayList<JNDIBinding>();
        list.add(bindings);
        if (_logger.isLoggable(Level.FINEST)) {
            debug("application=" + applicationName + ", binding name=" + jndiName);
        }
        namingManager.bindToAppNamespace(applicationName, list);
        bindAppScopedNameForAppclient(object, jndiName, applicationName);
    } else {
        namingManager.publishObject(jndiName, object, true);
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) JNDIBinding(org.glassfish.api.naming.JNDIBinding) ArrayList(java.util.ArrayList) NamingException(javax.naming.NamingException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with JNDIBinding

use of org.glassfish.api.naming.JNDIBinding in project Payara by payara.

the class ComponentEnvManagerImpl method unbindFromComponentNamespace.

public void unbindFromComponentNamespace(JndiNameEnvironment env) throws NamingException {
    // undeploy all descriptors
    undeployAllDescriptors(env);
    // Unpublish any global entries exported by this environment
    Collection<JNDIBinding> globalBindings = new ArrayList<JNDIBinding>();
    addJNDIBindings(env, ScopeType.GLOBAL, globalBindings);
    for (JNDIBinding next : globalBindings) {
        namingManager.unpublishObject(next.getName());
    }
    Application app = DOLUtils.getApplicationFromEnv(env);
    // undeploy data-sources & mail-sessions exposed by app-client descriptors.
    Set<ApplicationClientDescriptor> appClientDescs = app.getBundleDescriptors(ApplicationClientDescriptor.class);
    for (ApplicationClientDescriptor acd : appClientDescs) {
        undeployAllDescriptors(acd);
    }
    if (!(env instanceof ApplicationClientDescriptor) && (app.getBundleDescriptors(ApplicationClientDescriptor.class).size() > 0)) {
        Collection<JNDIBinding> appBindings = new ArrayList<JNDIBinding>();
        addJNDIBindings(env, ScopeType.APP, appBindings);
        for (JNDIBinding next : appBindings) {
            String internalGlobalJavaAppName = componentNamingUtil.composeInternalGlobalJavaAppName(app.getAppName(), next.getName());
            namingManager.unpublishObject(internalGlobalJavaAppName);
        }
    }
    if (env instanceof Application) {
        namingManager.unbindAppObjects(DOLUtils.getApplicationName(env));
    } else {
        // Unbind anything in the component namespace
        String compEnvId = getComponentEnvId(env);
        namingManager.unbindComponentObjects(compEnvId);
        this.unregister(compEnvId);
    }
}
Also used : JNDIBinding(org.glassfish.api.naming.JNDIBinding)

Example 4 with JNDIBinding

use of org.glassfish.api.naming.JNDIBinding in project Payara by payara.

the class ComponentEnvManagerImpl method bindToComponentNamespace.

public String bindToComponentNamespace(JndiNameEnvironment env) throws NamingException {
    String compEnvId = getComponentEnvId(env);
    Collection<JNDIBinding> bindings = new ArrayList<JNDIBinding>();
    // Add all java:comp, java:module, and java:app(except for app clients) dependencies
    // for the specified environment
    addJNDIBindings(env, ScopeType.COMPONENT, bindings);
    addJNDIBindings(env, ScopeType.MODULE, bindings);
    if (!(env instanceof ApplicationClientDescriptor)) {
        addJNDIBindings(env, ScopeType.APP, bindings);
    }
    if (env instanceof Application) {
        Application app = (Application) env;
        // those same entries will not be registered within the app client JVM itself.
        for (JndiNameEnvironment next : app.getBundleDescriptors(ApplicationClientDescriptor.class)) {
            addJNDIBindings(next, ScopeType.APP, bindings);
        }
        namingManager.bindToAppNamespace(DOLUtils.getApplicationName(env), bindings);
    } else {
        boolean treatComponentAsModule = DOLUtils.getTreatComponentAsModule(env);
        // Bind dependencies to the namespace for this component
        namingManager.bindToComponentNamespace(DOLUtils.getApplicationName(env), DOLUtils.getModuleName(env), compEnvId, treatComponentAsModule, bindings);
        compEnvId = getComponentEnvId(env);
    }
    if (!(env instanceof ApplicationClientDescriptor)) {
        // Publish any dependencies with java:global names defined by the current env
        // to the global namespace
        Collection<JNDIBinding> globalBindings = new ArrayList<JNDIBinding>();
        addJNDIBindings(env, ScopeType.GLOBAL, globalBindings);
        if (env instanceof Application) {
            Application app = (Application) env;
            // those same entries will not be registered within the app client JVM itself.
            for (JndiNameEnvironment next : app.getBundleDescriptors(ApplicationClientDescriptor.class)) {
                addJNDIBindings(next, ScopeType.GLOBAL, globalBindings);
            }
        }
        for (JNDIBinding next : globalBindings) {
            namingManager.publishObject(next.getName(), next.getValue(), true);
        }
    }
    // If the app contains any application client modules (and the given env isn't
    // an application client)  register any java:app dependencies under a well-known
    // internal portion of the global namespace based on the application name.  This
    // will allow app client access to application-wide objects within the server.
    Application app = DOLUtils.getApplicationFromEnv(env);
    if (!(env instanceof ApplicationClientDescriptor) && app.getBundleDescriptors(ApplicationClientDescriptor.class).size() > 0) {
        for (JNDIBinding next : bindings) {
            if (dependencyAppliesToScope(next.getName(), ScopeType.APP)) {
                String internalGlobalJavaAppName = componentNamingUtil.composeInternalGlobalJavaAppName(app.getAppName(), next.getName());
                namingManager.publishObject(internalGlobalJavaAppName, next.getValue(), true);
            }
        }
    }
    if (compEnvId != null) {
        if (_logger.isLoggable(Level.FINEST))
            _logger.finest("ComponentEnvManagerImpl: " + "register " + compEnvId + " is " + env.getClass());
        this.register(compEnvId, env);
    }
    return compEnvId;
}
Also used : JNDIBinding(org.glassfish.api.naming.JNDIBinding)

Example 5 with JNDIBinding

use of org.glassfish.api.naming.JNDIBinding in project Payara by payara.

the class GlassfishNamingManagerImpl method bindToModuleNamespace.

/**
 * @inheritDoc
 */
@Override
public void bindToModuleNamespace(String appName, String moduleName, Collection<? extends JNDIBinding> bindings) throws NamingException {
    AppModuleKey appModuleKey = new AppModuleKey(appName, moduleName);
    Map namespace = getModuleNamespace(appModuleKey);
    for (JNDIBinding binding : bindings) {
        String logicalJndiName = binding.getName();
        if (logicalJndiName.startsWith("java:module")) {
            bindToNamespace(namespace, binding.getName(), binding.getValue());
        }
    }
}
Also used : JNDIBinding(org.glassfish.api.naming.JNDIBinding) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JNDIBinding (org.glassfish.api.naming.JNDIBinding)5 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NameNotFoundException (javax.naming.NameNotFoundException)1 NamingException (javax.naming.NamingException)1