Java 类org.apache.catalina.deploy.ContextEnvironment 实例源码

项目:tomcat7    文件:NamingResourcesMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = 
                        ((NamingResources)this.resource).findEnvironments();
    ArrayList<String> results = new ArrayList<String>();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);

}
项目:tomcat7    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:tomcat7    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
public static void destroyMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
项目:tomcat7    文件:TestNamingContextListener.java   
/**
 * Test JNDI is available to ServletContextListeners.
 */
@Test
public void testBug49132() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    org.apache.catalina.Context ctx = tomcat.addContext("", null);

    // Enable JNDI - it is disabled by default
    tomcat.enableNaming();

    ContextEnvironment environment = new ContextEnvironment();
    environment.setType(BUG49132_VALUE.getClass().getName());
    environment.setName(BUG49132_NAME);
    environment.setValue(BUG49132_VALUE);
    ctx.getNamingResources().addEnvironment(environment);

    ctx.addApplicationListener(Bug49132Listener.class.getName());

    tomcat.start();

    assertEquals(LifecycleState.STARTED, ctx.getState());
}
项目:tomcat7    文件:TestNamingContext.java   
@Test
public void testBug53465() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    org.apache.catalina.Context ctxt =
            tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug53465.jsp", bc, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("<p>10</p>"));

    ContextEnvironment ce =
            ctxt.getNamingResources().findEnvironment("bug53465");
    Assert.assertEquals("Bug53465MappedName", ce.getProperty("mappedName"));
}
项目:lams    文件:NamingResourcesMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = 
                        ((NamingResources)this.resource).findEnvironments();
    ArrayList results = new ArrayList();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return ((String[]) results.toArray(new String[results.size()]));

}
项目:lams    文件:StandardContextMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = getNamingResources().findEnvironments();
    ArrayList results = new ArrayList();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return ((String[]) results.toArray(new String[results.size()]));

}
项目:lams    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:lams    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
static void destroyMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
项目:jerrydog    文件:NamingResourcesMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = 
                        ((NamingResources)this.resource).findEnvironments();
    ArrayList results = new ArrayList();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
        }
    }
    return ((String[]) results.toArray(new String[results.size()]));

}
项目:jerrydog    文件:StandardContextMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = getNamingResources().findEnvironments();
    ArrayList results = new ArrayList();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
        }
    }
    return ((String[]) results.toArray(new String[results.size()]));

}
项目:jerrydog    文件:DefaultContextMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = getNamingResources().findEnvironments();
    ArrayList results = new ArrayList();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
        }
    }
    return ((String[]) results.toArray(new String[results.size()]));

}
项目:jerrydog    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static ModelMBean createMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:jerrydog    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
public static void destroyMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, environment);
    mserver.unregisterMBean(oname);

}
项目:apache-tomcat-7.0.73-with-comment    文件:NamingResourcesMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = 
                        ((NamingResources)this.resource).findEnvironments();
    ArrayList<String> results = new ArrayList<String>();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);

}
项目:apache-tomcat-7.0.73-with-comment    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:apache-tomcat-7.0.73-with-comment    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
public static void destroyMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
项目:apache-tomcat-7.0.73-with-comment    文件:TestNamingContextListener.java   
/**
 * Test JNDI is available to ServletContextListeners.
 */
@Test
public void testBug49132() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    org.apache.catalina.Context ctx = tomcat.addContext("", null);

    // Enable JNDI - it is disabled by default
    tomcat.enableNaming();

    ContextEnvironment environment = new ContextEnvironment();
    environment.setType(BUG49132_VALUE.getClass().getName());
    environment.setName(BUG49132_NAME);
    environment.setValue(BUG49132_VALUE);
    ctx.getNamingResources().addEnvironment(environment);

    ctx.addApplicationListener(Bug49132Listener.class.getName());

    tomcat.start();

    assertEquals(LifecycleState.STARTED, ctx.getState());
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestNamingContext.java   
@Test
public void testBug53465() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    org.apache.catalina.Context ctxt =
            tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug53465.jsp", bc, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("<p>10</p>"));

    ContextEnvironment ce =
            ctxt.getNamingResources().findEnvironment("bug53465");
    Assert.assertEquals("Bug53465MappedName", ce.getProperty("mappedName"));
}
项目:lazycat    文件:NamingResourcesMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for this
 * web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = ((NamingResources) this.resource).findEnvironments();
    ArrayList<String> results = new ArrayList<String>();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException(
                    "Cannot create object name for environment " + envs[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);

}
项目:lazycat    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment
 *            The ContextEnvironment to be managed
 *
 * @exception Exception
 *                if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextEnvironment environment) throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:lazycat    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this <code>ContextEnvironment</code> object.
 *
 * @param environment
 *            The ContextEnvironment to be managed
 *
 * @exception Exception
 *                if an MBean cannot be deregistered
 */
public static void destroyMBean(ContextEnvironment environment) throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, environment);
    if (mserver.isRegistered(oname))
        mserver.unregisterMBean(oname);

}
项目:class-guard    文件:NamingResourcesMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = 
                        ((NamingResources)this.resource).findEnvironments();
    ArrayList<String> results = new ArrayList<String>();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);

}
项目:class-guard    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:class-guard    文件:MBeanUtils.java   
/**
 * Create an <code>ObjectName</code> for this
 * <code>Service</code> object.
 *
 * @param domain Domain in which this name is to be created
 * @param environment The ContextEnvironment to be named
 *
 * @exception MalformedObjectNameException if a name cannot be created
 */
public static ObjectName createObjectName(String domain,
                                          ContextEnvironment environment)
    throws MalformedObjectNameException {

    ObjectName name = null;
    Object container = 
            environment.getNamingResources().getContainer();
    if (container instanceof Server) {
        name = new ObjectName(domain + ":type=Environment" + 
                    ",resourcetype=Global,name=" + environment.getName());
    } else if (container instanceof Context) {        
        Context context = ((Context)container);
        ContextName cn = new ContextName(context.getName(), false);
        Container host = context.getParent();
        name = new ObjectName(domain + ":type=Environment" + 
                    ",resourcetype=Context,context=" + cn.getDisplayName() + 
                    ",host=" + host.getName() +
                    ",name=" + environment.getName());
    }        
    return (name);

}
项目:class-guard    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
public static void destroyMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
项目:class-guard    文件:TestNamingContextListener.java   
/**
 * Test JNDI is available to ServletContextListeners.
 */
@Test
public void testBug49132() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Must have a real docBase - just use temp
    org.apache.catalina.Context ctx =
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));

    // Enable JNDI - it is disabled by default
    tomcat.enableNaming();

    ContextEnvironment environment = new ContextEnvironment();
    environment.setType(BUG49132_VALUE.getClass().getName());
    environment.setName(BUG49132_NAME);
    environment.setValue(BUG49132_VALUE);
    ctx.getNamingResources().addEnvironment(environment);

    ctx.addApplicationListener(new ApplicationListener(
            Bug49132Listener.class.getName(), false));

    tomcat.start();

    assertEquals(LifecycleState.STARTED, ctx.getState());
}
项目:class-guard    文件:TestNamingContext.java   
@Test
public void testBug53465() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    org.apache.catalina.Context ctxt =
            tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug53465.jsp", bc, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("<p>10</p>"));

    ContextEnvironment ce =
            ctxt.getNamingResources().findEnvironment("bug53465");
    Assert.assertEquals("Bug53465MappedName", ce.getProperty("mappedName"));
}
项目:apache-tomcat-7.0.57    文件:NamingResourcesMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = 
                        ((NamingResources)this.resource).findEnvironments();
    ArrayList<String> results = new ArrayList<String>();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);

}
项目:apache-tomcat-7.0.57    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:apache-tomcat-7.0.57    文件:MBeanUtils.java   
/**
 * Create an <code>ObjectName</code> for this
 * <code>Service</code> object.
 *
 * @param domain Domain in which this name is to be created
 * @param environment The ContextEnvironment to be named
 *
 * @exception MalformedObjectNameException if a name cannot be created
 */
public static ObjectName createObjectName(String domain,
                                          ContextEnvironment environment)
    throws MalformedObjectNameException {

    ObjectName name = null;
    Object container = 
            environment.getNamingResources().getContainer();
    if (container instanceof Server) {
        name = new ObjectName(domain + ":type=Environment" + 
                    ",resourcetype=Global,name=" + environment.getName());
    } else if (container instanceof Context) {        
        Context context = ((Context)container);
        ContextName cn = new ContextName(context.getName(), false);
        Container host = context.getParent();
        name = new ObjectName(domain + ":type=Environment" + 
                    ",resourcetype=Context,context=" + cn.getDisplayName() + 
                    ",host=" + host.getName() +
                    ",name=" + environment.getName());
    }        
    return (name);

}
项目:apache-tomcat-7.0.57    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
public static void destroyMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
项目:apache-tomcat-7.0.57    文件:TestNamingContextListener.java   
/**
 * Test JNDI is available to ServletContextListeners.
 */
@Test
public void testBug49132() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Must have a real docBase - just use temp
    org.apache.catalina.Context ctx =
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));

    // Enable JNDI - it is disabled by default
    tomcat.enableNaming();

    ContextEnvironment environment = new ContextEnvironment();
    environment.setType(BUG49132_VALUE.getClass().getName());
    environment.setName(BUG49132_NAME);
    environment.setValue(BUG49132_VALUE);
    ctx.getNamingResources().addEnvironment(environment);

    ctx.addApplicationListener(Bug49132Listener.class.getName());

    tomcat.start();

    assertEquals(LifecycleState.STARTED, ctx.getState());
}
项目:apache-tomcat-7.0.57    文件:TestNamingContext.java   
@Test
public void testBug53465() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    org.apache.catalina.Context ctxt =
            tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug53465.jsp", bc, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("<p>10</p>"));

    ContextEnvironment ce =
            ctxt.getNamingResources().findEnvironment("bug53465");
    Assert.assertEquals("Bug53465MappedName", ce.getProperty("mappedName"));
}
项目:apache-tomcat-7.0.57    文件:TestNamingContextListener.java   
/**
 * Test JNDI is available to ServletContextListeners.
 */
@Test
public void testBug49132() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Must have a real docBase - just use temp
    org.apache.catalina.Context ctx =
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));

    // Enable JNDI - it is disabled by default
    tomcat.enableNaming();

    ContextEnvironment environment = new ContextEnvironment();
    environment.setType(BUG49132_VALUE.getClass().getName());
    environment.setName(BUG49132_NAME);
    environment.setValue(BUG49132_VALUE);
    ctx.getNamingResources().addEnvironment(environment);

    ctx.addApplicationListener(Bug49132Listener.class.getName());

    tomcat.start();

    assertEquals(LifecycleState.STARTED, ctx.getState());
}
项目:apache-tomcat-7.0.57    文件:TestNamingContext.java   
@Test
public void testBug53465() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    org.apache.catalina.Context ctxt =
            tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug53465.jsp", bc, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("<p>10</p>"));

    ContextEnvironment ce =
            ctxt.getNamingResources().findEnvironment("bug53465");
    Assert.assertEquals("Bug53465MappedName", ce.getProperty("mappedName"));
}
项目:apache-tomcat-7.0.57    文件:NamingResourcesMBean.java   
/**
 * Return the MBean Names of the set of defined environment entries for  
 * this web application
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = 
                        ((NamingResources)this.resource).findEnvironments();
    ArrayList<String> results = new ArrayList<String>();
    for (int i = 0; i < envs.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for environment " + envs[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);

}
项目:apache-tomcat-7.0.57    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:apache-tomcat-7.0.57    文件:MBeanUtils.java   
/**
 * Create an <code>ObjectName</code> for this
 * <code>Service</code> object.
 *
 * @param domain Domain in which this name is to be created
 * @param environment The ContextEnvironment to be named
 *
 * @exception MalformedObjectNameException if a name cannot be created
 */
public static ObjectName createObjectName(String domain,
                                          ContextEnvironment environment)
    throws MalformedObjectNameException {

    ObjectName name = null;
    Object container = 
            environment.getNamingResources().getContainer();
    if (container instanceof Server) {
        name = new ObjectName(domain + ":type=Environment" + 
                    ",resourcetype=Global,name=" + environment.getName());
    } else if (container instanceof Context) {        
        Context context = ((Context)container);
        ContextName cn = new ContextName(context.getName(), false);
        Container host = context.getParent();
        name = new ObjectName(domain + ":type=Environment" + 
                    ",resourcetype=Context,context=" + cn.getDisplayName() + 
                    ",host=" + host.getName() +
                    ",name=" + environment.getName());
    }        
    return (name);

}
项目:apache-tomcat-7.0.57    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
public static void destroyMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}