[jboss-cvs] system2/src/tests/org/jboss/test/profileservice/support ...

Scott Stark scott.stark at jboss.com
Fri Jul 14 00:27:24 EDT 2006


  User: starksm 
  Date: 06/07/14 00:27:24

  Added:       src/tests/org/jboss/test/profileservice/support     
                        ProfileServiceBootstrap.java
                        ProfileServiceKernelConfig.java
                        Simple1PSBootstrap.java Simple2PSBootstrap.java
                        SecurityActions.java
  Log:
  Move profileservice tests to the server module
  
  Revision  Changes    Path
  1.1      date: 2006/07/14 04:27:24;  author: starksm;  state: Exp;system2/src/tests/org/jboss/test/profileservice/support/ProfileServiceBootstrap.java
  
  Index: ProfileServiceBootstrap.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2005, JBoss Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.jboss.test.profileservice.support;
  
  import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
  
  /**
   * 
   * @author Scott.Stark at jboss.org
   * @version $Revision$
   */
  public class ProfileServiceBootstrap extends BasicBootstrap
  {
     private String profileName;
  
     public ProfileServiceBootstrap()
     {
        this("default");
     }
     public ProfileServiceBootstrap(String name)
     {
        this.profileName = name;
     }
  
     protected void bootstrap() throws Throwable
     {
        // Bootstrap the core kernel
        super.bootstrap();
        // Load the profile beans
        loadProfile(profileName);
     }
  
     /**
      * Load the beans associated with the named profile. Should be overriden
      * to do something meaningful.
      * @param name
      * @throws Throwable
      */
     protected void loadProfile(String name) throws Throwable
     {
        
     }
  }
  
  
  
  1.1      date: 2006/07/14 04:27:24;  author: starksm;  state: Exp;system2/src/tests/org/jboss/test/profileservice/support/ProfileServiceKernelConfig.java
  
  Index: ProfileServiceKernelConfig.java
  ===================================================================
  /*
    * JBoss, Home of Professional Open Source
    * Copyright 2005, JBoss Inc., and individual contributors as indicated
    * by the @authors tag. See the copyright.txt in the distribution for a
    * full listing of individual contributors.
    *
    * This is free software; you can redistribute it and/or modify it
    * under the terms of the GNU Lesser General Public License as
    * published by the Free Software Foundation; either version 2.1 of
    * the License, or (at your option) any later version.
    *
    * This software is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    * Lesser General Public License for more details.
    *
    * You should have received a copy of the GNU Lesser General Public
    * License along with this software; if not, write to the Free
    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    */
  
  package org.jboss.test.profileservice.support;
  
  /**
   * @author Scott.Stark at jboss.org
   * @version $Revision$
   */
  
  public class ProfileServiceKernelConfig
  {
  }
  
  
  
  1.1      date: 2006/07/14 04:27:24;  author: starksm;  state: Exp;system2/src/tests/org/jboss/test/profileservice/support/Simple1PSBootstrap.java
  
  Index: Simple1PSBootstrap.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2005, JBoss Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.jboss.test.profileservice.support;
  
  import java.util.ArrayList;
  import java.io.IOException;
  import java.net.URL;
  
  import org.jboss.deployers.spi.Deployment;
  import org.jboss.profileservice.spi.Profile;
  import org.jboss.profileservice.spi.ProfileKey;
  import org.jboss.profileservice.spi.ProfileService;
  import org.jboss.test.profileservice.simple1.ProfileServiceImpl;
  import org.jboss.test.profileservice.support.ProfileServiceBootstrap;
  import org.jboss.vfs.VFSClassLoader;
  import org.jboss.vfs.VFSFactory;
  import org.jboss.vfs.VFSFactoryLocator;
  import org.jboss.vfs.spi.ReadOnlyVFS;
  import org.jboss.kernel.plugins.deployment.BasicKernelDeployer;
  import org.jboss.kernel.plugins.deployment.AbstractKernelDeployment;
  import org.jboss.beans.metadata.plugins.AbstractClassLoaderMetaData;
  import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
  import org.jboss.beans.metadata.spi.BeanMetaData;
  
  public class Simple1PSBootstrap extends ProfileServiceBootstrap
  {
     private BasicKernelDeployer deployer;
     protected ProfileService profileService;
  
     public Simple1PSBootstrap() throws IOException
     {
        this("default");
     }
  
     public Simple1PSBootstrap(String name) throws IOException
     {
        super(name);
        profileService = new ProfileServiceImpl();
     }
  
  
     public ProfileService getProfileService()
     {
        return profileService;
     }
  
     /**
      * Get the named profile from the profile service
      * TODO: who owns the VFS configuration
      */
     protected void loadProfile(String name) throws Throwable
     {
        deployer = new BasicKernelDeployer(super.getKernel());
  
        // Load the named profile
        ProfileKey key = new ProfileKey(name);
        Profile profile = profileService.getProfile(key);
        Deployment[] profileDeployments = profile.getDeployments();
        for(Deployment d : profileDeployments)
        {
           log.debug("Deploying: "+d);
           AbstractKernelDeployment kernelDeployment = new AbstractKernelDeployment();
           kernelDeployment.setName(d.getName());
  
           // Setup the class loader from the deployment root URL/files
           URL rootURL = d.getRootURL();
           VFSFactory factory = VFSFactoryLocator.getFactory(rootURL);
           ReadOnlyVFS vfs = factory.getVFS(rootURL);
           String[] searchCtxts = d.getFiles();
           VFSClassLoader cl = new VFSClassLoader(searchCtxts, vfs);
           AbstractClassLoaderMetaData clMD = new AbstractClassLoaderMetaData();
           AbstractValueMetaData value = new AbstractValueMetaData(cl);
           clMD.setClassLoader(value);
           /*
           DeploymentBean<BeanMetaData>[] beans = d.getBeans();
           ArrayList<BeanMetaData> beanFactories = new ArrayList<BeanMetaData>();
           for(DeploymentBean<BeanMetaData> db: beans)
           {
              log.debug("Adding bean: "+db);
              String beanName = db.getName();
              BeanMetaData kbean = db.getBeanMetaData();
              // TODO: what other metdata settings need to be set at this level?
              kbean.setClassLoader(clMD);
              beanFactories.add(kbean);
           }
           kernelDeployment.setBeans(beanFactories); // TODO ????
           */
  
           deployer.deploy(kernelDeployment);
        }
  
     }
  
  }
  
  
  
  1.1      date: 2006/07/14 04:27:24;  author: starksm;  state: Exp;system2/src/tests/org/jboss/test/profileservice/support/Simple2PSBootstrap.java
  
  Index: Simple2PSBootstrap.java
  ===================================================================
  package org.jboss.test.profileservice.support;
  
  import org.jboss.test.profileservice.simple1.ProfileServiceImpl2;
  
  import java.io.IOException;
  
  public class Simple2PSBootstrap extends Simple1PSBootstrap
  {
     public Simple2PSBootstrap(String name) throws IOException
     {
        super(name);
        profileService = new ProfileServiceImpl2();
     }
  
  }
  
  
  
  1.1      date: 2006/07/14 04:27:24;  author: starksm;  state: Exp;system2/src/tests/org/jboss/test/profileservice/support/SecurityActions.java
  
  Index: SecurityActions.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2005, JBoss Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.jboss.test.profileservice.support;
  
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.security.PrivilegedAction;
  import java.security.AccessController;
  
  /**
   * Package priviledged actions
   * 
   * @author Scott.Stark at jboss.org
   * @version $Revision$
   */
  class SecurityActions
  {
     interface ClassLoaderActions
     {
        ClassLoaderActions PRIVILEGED = new ClassLoaderActions()
        {
           public URLClassLoader newClassLoader(final URL[] urls)
           {
              PrivilegedAction action = new PrivilegedAction()
              {
                 public Object run()
                 {
                    return new URLClassLoader(urls);
                 }
              };
              return (URLClassLoader) AccessController.doPrivileged(action);
           }
        };
  
        ClassLoaderActions NON_PRIVILEGED = new ClassLoaderActions()
        {
           public URLClassLoader newClassLoader(URL[] urls)
           {
              return new URLClassLoader(urls);
           }
        };
  
        URLClassLoader newClassLoader(URL[] urls);
     }
  
     static URLClassLoader newClassLoader(URL[] urls)
     {
        if(System.getSecurityManager() == null)
        {
           return ClassLoaderActions.NON_PRIVILEGED.newClassLoader(urls);
        }
        else
        {
           return ClassLoaderActions.PRIVILEGED.newClassLoader(urls);
        }
     }
  
     static String getSystemProperty(final String name)
     {
        PrivilegedAction action = new PrivilegedAction()
        {
           public Object run()
           {
              return System.getProperty(name);
           }
        };
        return (String) AccessController.doPrivileged(action);
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list