package com.ai.application.defaultpkg;

import com.ai.application.interfaces.RequestExecutionException;
import com.ai.application.utils.AppObjects;

/**
 * @author Satya
 * Provide aliases for classnames
 */
public class AliasedFactory3 extends FilterEnabledFactory2 {

    /**
     * Creates an object with no consideration of synchronization.
     * The calling methods are expected to provide the synchronization.
     * Only called by the getCreator() for now
     */
    private Object createCreator(String className)
      throws com.ai.application.interfaces.RequestExecutionException
    {
         try
         {
         	String realClassname = AppObjects.getValue("aspire.classalias." + className,className);
            AppObjects.info(this,"Creating the creator :" + className);
            Class classObj = Class.forName(className);
            Object creator = classObj.newInstance();
            return   creator;
         }
         catch(java.lang.ClassNotFoundException x)
         {
            throw new RequestExecutionException("Error: class not found",x);
         }
         catch (java.lang.InstantiationException x)
         {
            throw new RequestExecutionException("Error: class instantiation error",x);
         }
         catch(java.lang.IllegalAccessException x)
         {
            throw new RequestExecutionException("Error: Illeagal access",x);
         }
    }
}

Satya - Tuesday, January 04, 2005 11:30:02 AM

Examples of class alias definitions

aspire.classalias.dbr=com.ai.db.DBRequestExecutor2
aspire.classalias.mexec=com.ai.db.DBPreTranslateArgsMultiRequestExecutor
aspire.classalias.ifpart=com.ai.parts.IfPart
aspire.classalias.copyNames=com.ai.parts.CopyParametersPart
aspire.classalias.hds=com.ai.htmlgen.DBHashTableFormHandler1
aspire.classalias.sequentialHdsAdapter=com.ai.htmlgen.GenericTableHandler6

Satya - Tuesday, January 04, 2005 11:30:55 AM

Suggested property filename for class aliases

aspire-class-aliases.properties

Satya - Tuesday, January 04, 2005 11:34:01 AM

What is possible with these definitions

Consider the following definition

request.GetData.classname=com.ai.db.DBRequestExecutor2
request.GetData.db=your-db
request.GetData.stmt=your-select-statement

You can rewrite this as

request.GetData.classname=dbr
request.GetData.db=your-db
request.GetData.stmt=your-select-statement

Notice how "dbr" is used as an alias for "com.ai.db.DBRequestExecutor2". This approach has two benefits. You type less. You can also hide which version you are using to a single place.

Satya - Tuesday, January 04, 2005 11:37:16 AM

What should you watch out for when you are using this facility

1. In aspire.properties you have to use "AliasedFactory3" instead of FilterEnabledFactory2 as your factory

2. Make sure you don't have two aspire jar files in the path resulting in an older factory getting loaded

3. Make sure the alias names properties file is included in the aspire.properties as one of the properties files