Package modTransf.rules.core

Source Code of modTransf.rules.core.TemplateDescriptorBase

//Source file: H:\\temp\\mdaTransf-v3\\mdaTransf\\src\\share\\modTransf\\rules\\core\\ConceptDescriptor.java

//Source file: H:\\temp\\generated\\modTransf\\rules\\core\\ConceptDescriptor.java

package modTransf.rules.core;

import modTransf.engine.EngineLifeCycle;
import modTransf.engine.RuleContext;
import modTransf.engine.Arguments;
import modTransf.engine.TransformationException;

import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import modTransf.model.ModelHelper;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.lang.reflect.InvocationTargetException;
import modTransf.model.ModelException;

/**
* Base implementation of descriptor.
* This base implementation provides common property (varName, type, propertyName)
* and associated methods.
* Concrete implementations should provide the {@link #getPropertyValue(Object parentBean, RuleContext request)} and
* {@link #setPropertyValue(Object parentBean, Object value, RuleContext request)}
* and {@link create(RuleContext)} methods.
*/
public abstract class TemplateDescriptorBase extends SimpleTemplateDescriptor implements TemplateDescriptor, EngineLifeCycle
{
  /**
   * Log for Transformation.
   * This log is used during rules development.
   * It logs rules processing.
   */
  protected static Log ruleLog = LogFactory.getLog("modTransf.engine.RuleLog");

   /** Name of the local variable associated to the concept, if any */
   protected String varName;

   /**
    * The name of the property that this descriptor describe.
    * The name is a name valid in the surrounding concept.
    */
   protected String propertyName;

   /**
    * The type that the concept should denote.
    * An enterGuard and an exitGuard is added.
    */
   protected String type;

   /**
    * The owner of this descriptor if any.
    * This property is set by the parent when this descriptor is register to the
    * parent.
    */
   private ComplexTemplateDescriptorBase parent;

   public TemplateDescriptorBase()
   {

   }

   /**
    * Access method for the varName property.
    *
    * @return   the current value of the varName property
    */
   public String getVarName()
   {
      return varName;
   }

   /**
    * Sets the value of the varName property.
    *
    * @param aVarName the new value of the varName property
    */
   public void setVarName(String aVarName)
   {
      varName = aVarName;
   }

   /**
    * Access method for the propertyName property.
    *
    * @return   the current value of the propertyName property
    */
   public String getPropertyName()
   {
      return propertyName;
   }

   /**
    * Sets the value of the propertyName property.
    * Not used for Domains (Should we remove this property from this class ?)
    *
    * @param aPropertyName the new value of the propertyName property
    */
   public void setPropertyName(String aPropertyName)
   {
      propertyName = aPropertyName;
   }

   /**
    * Access method for the type property.
    *
    * @return   the current value of the type property
    */
   public String getType()
   {
      return type;
   }

   /**
    * Sets the value of the type property.
    *
    * @param aType the new value of the type property
    */
   public void setType(String aType)
   {
      type = aType;
   }

   /**
    * Get the value of the property denoted by the concept.
    * Return the value if found, or null if not found.
    * @param parentBean The parent bean owning the property value.
    * @param request
    * @return Object
    */
   abstract public Object getPropertyValue(Object parentBean, RuleContext request)
     throws TransformationException;

   /**
    * Set the value of the property denoted by this descriptor.
    * @param parentBean The parent bean owning the property value.
    * @param value
    * @param request
    */
   abstract public void setPropertyValue(Object parentBean, Object value, RuleContext request)
     throws TransformationException;

   /**
    * Get the local value of the variable denoted by this descriptor.
    * @param request
    * @return Object
    */
   public Object getLocalValue(RuleContext request)
   {
     if( varName == null )
       return null;

    return request.getAttribute( varName, RuleContext.LOCAL_SCOPE);
   }

   /**
    * Set the value of the local variable denoted by this descriptor.
    * The property value is not synchronized.
    * @param value The value to put in the local variable denoted by this
    * descriptor.@param request
    */
   public void setLocalValue(Object value, RuleContext request)
   {
     if( varName == null )
       return;

     request.setAttribute( varName, value, RuleContext.LOCAL_SCOPE);
   }

   /**
    * Check if the specified value is of the type specified in the descriptor.
    * If no type is specified, return true.
    * @param value Object
    * @return boolean
    */
   protected boolean isOfSpecifiedType( Object value, RuleContext context )
    throws ModelException
  {
    if( type == null )
      return true;
    return getDomain().getModelHelper(context).isInstanceOf(value, type);
  }



   /**
    * Get the specified property value from the current "this" object.
    *
    * @param request RuleContext
    */
   public static Object getThisProperty(String propertyName, RuleContext request)
     throws TransformationException
   {
    Object value = null;
    try
    {
      return request.getTransformation().getModels().getProperty(request.getAttribute("this",
        request.LOCAL_SCOPE), propertyName);
    }
    catch(ModelException ex)
    {
      throw new TransformationException(ex);
    }
   }

   /**
    * Get the specified property value from the current "this" object.
    *
    * @param request RuleContext
    */
   public static void setThisProperty(String propertyName, Object value, RuleContext request)
     throws TransformationException
   {
     try
    {
      request.getTransformation().getModels().setProperty(request.getAttribute("this", request.LOCAL_SCOPE), propertyName, value);
    }
    catch(ModelException ex)
    {
      throw new TransformationException(ex);
    }
   }

   /**
    * create the concept described by the descriptor and return the value.
    * If the descriptor have a varName, check if a value already exist under
    * this varName. Use this value if not null.
    * If a new value is computed and a varName is specified, store the new value
    * under the varName.
    * @param request RuleContext
    * @return the value.
    */
   public abstract Object create( RuleContext request )
     throws TransformationException;


   /**
    * Get the domain to which this descriptor belong.
    * @return ModelHelper
    */
   public Domain getDomain()
   {
     return parent.getDomain();
   }
   /**
    * Get the surrounding descriptor owning this class.
    * The top parent is a Domain.
    * @return ConceptDescriptor
    */
   public ComplexTemplateDescriptorBase getParent()
   {
     return parent;
   }
   /**
    *
    * @param parent ConceptDescriptor
    */
   public void setParent(ComplexTemplateDescriptorBase parent)
  {
    this.parent = parent;
  }

}
TOP

Related Classes of modTransf.rules.core.TemplateDescriptorBase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.