taylor      2004/12/27 11:36:24

  Modified:    fusion   project.xml
  Added:       fusion/src/java/org/apache/jetspeed/cps
                        CPSInitializationException.java CommonService.java
                        BaseCommonService.java CPSConstants.java
                        CPSException.java CommonPortletServices.java
                        CPSTest.java
  Log:
  fusion was broken in october when the cps project was removed from j2
  this patch recovers the cps project from j2 cleanup-20041013 tag
  the cps project now exists inside of the fusion jar
  
  Revision  Changes    Path
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/cps/CPSInitializationException.java
  
  Index: CPSInitializationException.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.cps;
  
  import org.apache.fulcrum.InitializationException;
  
  /**
   * Services should throw this exception when an error occurs during service 
initialization. 
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: CPSInitializationException.java,v 1.1 2004/12/27 19:36:23 
taylor Exp $
   **/
  public class CPSInitializationException extends InitializationException
  {
      public CPSInitializationException(String error)
      {
          super(error);
      }
      
      public CPSInitializationException(String error, Throwable t)
      {
          super(error, t);
      }
      
  }
  
  
  
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/cps/CommonService.java
  
  Index: CommonService.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.cps;
  
  import org.apache.fulcrum.Service;
  
  /**
   * <P>Common Service</P>
   *
   * Marks a common service. Could be useful when we replace Fulcrum with 
another service manager.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: CommonService.java,v 1.1 2004/12/27 19:36:23 taylor Exp $
   * 
   */
  public interface CommonService extends Service
  {
      /**
       * Load an implementation class from the configuration.
       * 
       * @param configurationName
       * @return
       * @throws CPSInitializationException
       */
      public Class loadModelClass(String configurationName)
      throws CPSInitializationException;
      
      /**
       * Creates objects given the class. 
       * Throws exceptions if the class is not found in the default class path, 
       * or the class is not an instance of CmsObject.
       * 
       * @param classe the class of object
       * @return the newly created object
       * @throws ContentManagementException
       */    
      public Object createObject(Class classe);
      
  }
  
  
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/cps/BaseCommonService.java
  
  Index: BaseCommonService.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.cps;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.BaseService;
  
  /**
   * <P>Base Common Service</P>
   *
   * Marks a common service. Could be useful when we replace Fulcrum with 
another service manager.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: BaseCommonService.java,v 1.1 2004/12/27 19:36:23 taylor Exp $
   * 
   */
  public abstract class BaseCommonService extends BaseService implements 
CommonService
  {
      private static Map modelClasses = new HashMap();
      protected final static Log log = 
LogFactory.getLog(BaseCommonService.class);
  
      /**
       * Load an implementation class from the configuration.
       * 
       * @param configurationName
       * @return
       * @throws CPSInitializationException
       */
      public Class loadModelClass(String configurationName)
      throws CPSInitializationException
      {
          String className = getConfiguration().getString(configurationName, 
null);
          if (null == className)
          {
              throw new CPSInitializationException(configurationName + " 
implementation configuration not found.");
          }
  
          try
          {
              Class classe = (Class)modelClasses.get(className);
              if (null == classe)
              {
                  classe = Class.forName(className);
                  modelClasses.put(className, classe);
              }
              return classe;
              
          }
          catch (ClassNotFoundException e)
          {
              throw new CPSInitializationException("Could not preload " + 
className + " implementation class.", e);
          }            
      }
  
      /**
       * Creates objects given the class. 
       * Throws exceptions if the class is not found in the default class path, 
       * or the class is not an instance of CmsObject.
       * 
       * @param classe the class of object
       * @return the newly created object
       * @throws ContentManagementException
       */    
      public Object createObject(Class classe)
      {
          Object object = null;
          try
          {
              object = classe.newInstance();
          }
          catch (Exception e)
          {
              log.error("Factory failed to create object: " + classe.getName(), 
e);            
          }
          
          return object;        
      }
      
  }
  
  
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/cps/CPSConstants.java
  
  Index: CPSConstants.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.cps;
  
  /**
   * This interface contains all the constants for the CPS configuration.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: CPSConstants.java,v 1.1 2004/12/27 19:36:23 taylor Exp $
   */
  public interface CPSConstants
  {
      /**
       * <p>The prefix used to denote the namespace reserved for and
       * used by Jetspeed-specific configuration parameters (such as
       * those passed in via servlet container's config file
       * (<code>server.xml</code>), or the web app deployment descriptor
       * (<code>web.xml</code>).</p>
       *
       * <p>For example, a parameter in the Jetspeed namespace would be
       * <code>org.apache.jetspeed.loggingRoot</code>.</p>
       */
      public static final String CONFIG_NAMESPACE = "org.apache.jetspeed.cps";
  
      /** The key for the Log4J File */
      public static final String LOG4J_CONFIG_FILE = "log4j.file";
  
      /** The default value for the Log4J File */
      public static final String LOG4J_CONFIG_FILE_DEFAULT = 
"/WEB-INF/conf/cps-logging.properties";
  
      /** This is the default log file to be used for logging */
      public static final String DEFAULT_LOGGER = "cps";
      public static final String CONSOLE_LOGGER = "console";
      
      /** Default Value for the Logging Directory, relative to the webroot */
      public static final String LOGGING_ROOT_DEFAULT = "/logs";
      public static final String LOGGING_ROOT = "loggingRoot";
  
      public static final String CPS_PROPERTIES_KEY = "properties";
      public static final String CPS_PROPERTIES_DEFAULT = 
"/WEB-INF/conf/cps.properties";
      public static final String CPS_CONFIGURATION_KEY = "configuration";
      public static final String CPS_CONFIGURATION_DEFAULT = 
"/WEB-INF/conf/cps.xml";
  
      /** If this value is set as applicationRoot, then the webContext is used
       * as application root
       */
      public static final String WEB_CONTEXT = "webContext";
  
      /** Key for the Path to the cps.properties File */ 
      public static final String APPLICATION_ROOT_KEY = "applicationRoot";
  
      /** Default Value for the Path to the TurbineResources.properties File */ 
      public static final String APPLICATION_ROOT_DEFAULT = WEB_CONTEXT;
     
  
  }
  
  
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/cps/CPSException.java
  
  Index: CPSException.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.cps;
  
  import org.apache.commons.lang.exception.NestableException;
  
  /**
   * Occurs when anything unexpected happens within a CPS. 
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: CPSException.java,v 1.1 2004/12/27 19:36:23 taylor Exp $
   **/
  
  public class CPSException extends NestableException 
  {
  
      public CPSException() 
      {
          super();
      }
      
      public CPSException(String message) 
      {
          super(message);
      }
      
      public CPSException(Throwable nested)
      {
          super(nested);
      }
      
      public CPSException(String msg, Throwable nested)
      {
          super(msg, nested);
      }
  
  }
  
  
  
  
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/cps/CommonPortletServices.java
  
  Index: CommonPortletServices.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.cps;
  
  import java.util.Properties;
  import java.io.FileInputStream;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.commons.logging.impl.Log4jFactory;
  import org.apache.log4j.PropertyConfigurator;
  import org.apache.commons.configuration.Configuration;
  import org.apache.fulcrum.ServiceManager;
  import org.apache.fulcrum.BaseServiceBroker;
  
  /**
   * This is a singleton utility class that acts as a Services broker.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: CommonPortletServices.java,v 1.1 2004/12/27 19:36:23 taylor 
Exp $
   */
  public class CommonPortletServices extends BaseServiceBroker implements 
ServiceManager, CPSConstants
  {
      /** The single instance of this class. */
      private static CommonPortletServices instance = new 
CommonPortletServices();
  
      private static final Log log = 
LogFactory.getLog(CommonPortletServices.class);
  
      private boolean initialized = false;
      
      /**
       * This constructor is protected to force clients to use
       * getInstance() to access this class.
       */
      protected CommonPortletServices()
      {
          super();
      }
  
      /**
       * The method through which this class is accessed as a broker.
       *
       * @return The single instance of this class.
       */
      public static CommonPortletServices getInstance()
      {        
          return instance;
      }
  
      /**
       * 
       * <p>
       * init
       * </p>
       * Initializes th CPS with the <code>configuration</code>
       * and <code>applicationRoot provided</code>.
       * 
       * @param configuration Configuration to use to configure all CPS services
       * @param applicationRoot The application root of the system
       * @param initLog4j <code>true</code> means that CPS will attempt 
configure
       * Log4j, <code>false</code> Log4j will not be configured (used if the 
implementation
       * system already initializes Log4j)
       * @throws CPSInitializationException
       *
       */
      public void init(Configuration configuration, String applicationRoot, 
boolean initLog4j) throws CPSInitializationException
      {
          try
          {
              if (initialized)
              {
                  return;
              }
              
              //
              // bootstrap the initable services
              //
              this.setApplicationRoot(applicationRoot);
              this.setConfiguration(configuration);
  
              if (initLog4j)
              {
  
                  String log4jFile = configuration.getString(LOG4J_CONFIG_FILE, 
LOG4J_CONFIG_FILE_DEFAULT);
                  log4jFile = this.getRealPath(log4jFile);
                  Properties p = new Properties();
                  p.load(new FileInputStream(log4jFile));
                  p.setProperty(APPLICATION_ROOT_KEY, applicationRoot);
                  PropertyConfigurator.configure(p);
                  log.info("Configured log4j from " + log4jFile);
  
                  // Set up Commons Logging to use the Log4J Logging
                  
System.getProperties().setProperty(LogFactory.class.getName(), 
Log4jFactory.class.getName());
              }
              else
              {
                  log.info("Skipping Log4j configuration");
              }
  
              this.init();
          }
          catch (Throwable e)
          {
              e.printStackTrace();
              log.error(e.toString());
              throw new CPSInitializationException("CPS Initialization 
exception!", e);
          }
  
      }
  
      /**
       * 
       * <p>
       * init
       * </p>
       * Initializes th CPS with the <code>configuration</code>
       * and <code>applicationRoot provided</code>.  Will configure Log4j
       * by default.  This is the same acalling <code>init(Configuration, 
AppRoot, true)</code>
       * 
       * @param configuration
       * @param applicationRoot
       * @throws CPSInitializationException
       *
       */
      public void init(Configuration configuration, String applicationRoot) 
throws CPSInitializationException
      {
          init(configuration, applicationRoot, true);
      }
  
      public void shutdown() throws CPSException
      {
          getInstance().shutdownServices();
          System.gc();
      }
  
      /**
       * @param String name of the service.  For Fulcrum
       * services this is easily accessible from the Service's interface
       * via <code>SERVICE_NAME</code> field.
       * @return Object a service
       */
      public static CommonService getPortalService(String name)
      {
  
          Object service = getInstance().getService(name);
          if (service instanceof CommonService)
          {
              return (CommonService) service;
          }
          return null;
      }
      
  /*
      private void publishServices()
      throws CPSInitializationException
      {
          try
          {
              Hashtable env = new Hashtable();
               env.put(Context.INITIAL_CONTEXT_FACTORY,  
                  "com.sun.jndi.fscontext.FSContextFactory");
               env.put(Context.PROVIDER_URL, "file:/");
              env.put(Context.OBJECT_FACTORIES, "foo.bar.ObjFactory");
              env.put("foo", "bar");            
              Context ctx = new InitialContext(env);        
              ctx.bind("cps/services", this);
          }
          catch (NamingException e)
          {
              throw new CPSInitializationException(e.toString()); 
          }
      }
  */ 
      public boolean isInitialized()
      {
          return initialized;
      }
      
  }
  
  
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/cps/CPSTest.java
  
  Index: CPSTest.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.cps;
  
  import java.io.File;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.commons.configuration.Configuration;
  import org.apache.commons.configuration.PropertiesConfiguration;
  
  
  /**
   * Base class for CPS tests.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @since 2.0
   * @version $Id: CPSTest.java,v 1.1 2004/12/27 19:36:23 taylor Exp $
   */
  public abstract class CPSTest
      extends TestCase
      implements CPSConstants
  {
      Configuration configuration = null;
      
      /**
       * Creates a new instance.
       */
      public CPSTest(String testName) 
      {
          super(testName);
      }
  
      /**
       * Return the Test
       */
      public static Test suite() 
      {
          return new TestSuite(CPSTest.class);
      }
  
      protected CommonPortletServices cps = null;
  
      /**
       * Setup the test.
       */
      public void setUp() 
      {
          try
          {
              if (cps != null)
              {
                  return;
              }
              String propertiesFilename = getPropertiesFile();
              String applicationRoot = getApplicationRoot();
              configuration = (Configuration) 
                  new PropertiesConfiguration(propertiesFilename);
              
              configuration.setProperty(APPLICATION_ROOT_KEY, applicationRoot);
              //properties.setProperty(WEBAPP_ROOT_KEY, null);
  
              cps = CommonPortletServices.getInstance();
              cps.init(configuration, applicationRoot);
  
          }
          catch (Exception e)
          {
              e.printStackTrace();
              assertTrue(false);
          }
      }
     
      /**
       * Override to set your own properties file
       *
       */
      public String getPropertiesFile()
      {
          return getApplicationRoot() + "/WEB-INF/conf/cps.properties";
      }
  
      public Configuration getConfiguration()
      {
          return this.configuration;
      }
      
      /**
       * Override to set your own application root
       * If the default directory does not exist, then look in
       * the cps directory.  If the directory exist in the cps directory,
       * then return this directory.  Yes this is a hack, but it works.
       */
      public String getApplicationRoot()
      {
          String applicationRoot = "test";
          File testPath = new File(applicationRoot);
          if (!testPath.exists())
          {
              testPath = new File( "cps" + File.separator + applicationRoot);
              if (testPath.exists())
              {
                  applicationRoot = testPath.getAbsolutePath();
              }
          }
          return applicationRoot;
      }
  
      /**
       * Tear down the test.
       */
      public void tearDown() 
      {
          try
          {
              if (cps != null)
              {
                  cps.shutdown();
              }
          }
          catch (CPSException e)
          {
              e.printStackTrace();
          }
          finally
          {
              cps = null;
          }
      }
  
  }
  
  
  1.10      +7 -0      jakarta-jetspeed/fusion/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/fusion/project.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- project.xml       23 Nov 2004 07:25:19 -0000      1.9
  +++ project.xml       27 Dec 2004 19:36:24 -0000      1.10
  @@ -169,6 +169,13 @@
           <war.bundle>false</war.bundle>
         </properties>
       </dependency>    
  +    <dependency>
  +      <id>junit</id>
  +      <version>3.8.1</version>
  +      <properties>
  +        <war.bundle>false</war.bundle>
  +      </properties>
  +    </dependency>
     </dependencies>
     <build>
       <nagEmailAddress>[EMAIL PROTECTED]</nagEmailAddress>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to