ConditionProxyImpl.java :  » Workflow-Engines » osbl-1_0 » newprocess » impl » Java Open Source

Java Open Source » Workflow Engines » osbl 1_0 
osbl 1_0 » newprocess » impl » ConditionProxyImpl.java
/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package newprocess.impl;

import java.util.Collection;
import java.util.Iterator;

import newprocess.Condition;
import newprocess.ConditionProxy;
import newprocess.ConditionTerm;
import newprocess.NewprocessPackage;
import newprocess.validation.ConditionProxyValidator;
import newprocess.validation.ConditionProxyValidatorImpl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Condition Proxy</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link newprocess.impl.ConditionProxyImpl#getCondition <em>Condition</em>}</li>
 *   <li>{@link newprocess.impl.ConditionProxyImpl#isInverted <em>Inverted</em>}</li>
 *   <li>{@link newprocess.impl.ConditionProxyImpl#getProxyName <em>Proxy Name</em>}</li>
 *   <li>{@link newprocess.impl.ConditionProxyImpl#getConditionTerm <em>Condition Term</em>}</li>
 * </ul>
 * </p>
 *
 * @generated NOT
 * @author sh
 */
public class ConditionProxyImpl extends EObjectImpl 
  implements ConditionProxy, ConditionProxyValidator {
  
  /**
   * The cached value of the '{@link #getCondition() <em>Condition</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getCondition()
   * @generated
   * @ordered
   */
  protected Condition condition = null;

  /**
   * The default value of the '{@link #isInverted() <em>Inverted</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isInverted()
   * @generated
   * @ordered
   */
  protected static final boolean INVERTED_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isInverted() <em>Inverted</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isInverted()
   * @generated
   * @ordered
   */
  protected boolean inverted = INVERTED_EDEFAULT;

  /**
   * The default value of the '{@link #getProxyName() <em>Proxy Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getProxyName()
   * @generated
   * @ordered
   */
  protected static final String PROXY_NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getProxyName() <em>Proxy Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getProxyName()
   * @generated
   * @ordered
   */
  protected String proxyName = PROXY_NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getConditionTerm() <em>Condition Term</em>}' reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getConditionTerm()
   * @generated
   * @ordered
   */
  protected EList<ConditionTerm> conditionTerm = null;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ConditionProxyImpl() {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass() {
    return NewprocessPackage.Literals.CONDITION_PROXY;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Condition getCondition() {
    if (condition != null && condition.eIsProxy()) {
      InternalEObject oldCondition = (InternalEObject)condition;
      condition = (Condition)eResolveProxy(oldCondition);
      if (condition != oldCondition) {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, NewprocessPackage.CONDITION_PROXY__CONDITION, oldCondition, condition));
      }
    }
    return condition;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Condition basicGetCondition() {
    return condition;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setCondition(Condition newCondition) {
    Condition oldCondition = condition;
    condition = newCondition;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, NewprocessPackage.CONDITION_PROXY__CONDITION, oldCondition, condition));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isInverted() {
    return inverted;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setInverted(boolean newInverted) {
    boolean oldInverted = inverted;
    inverted = newInverted;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, NewprocessPackage.CONDITION_PROXY__INVERTED, oldInverted, inverted));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getProxyName() {
    return proxyName;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setProxyName(String newProxyName) {
    String oldProxyName = proxyName;
    proxyName = newProxyName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, NewprocessPackage.CONDITION_PROXY__PROXY_NAME, oldProxyName, proxyName));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<ConditionTerm> getConditionTerm() {
    if (conditionTerm == null) {
      conditionTerm = new EObjectWithInverseResolvingEList<ConditionTerm>(ConditionTerm.class, this, NewprocessPackage.CONDITION_PROXY__CONDITION_TERM, NewprocessPackage.CONDITION_TERM__CONDITION_PROXY);
    }
    return conditionTerm;
  }

  /**
   * <!-- begin-user-doc -->
   *  do a name update an propagate it to all reference
   * <!-- end-user-doc -->
   * @generated NOT
   * @author sh
   */
  public void performUpdate() {
    updateName();
    Iterator<ConditionTerm> it = getConditionTerm().iterator();
    while (it.hasNext()) {
      it.next().performUpdate();
    }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated NOT
   * @author sh
   */
  public void updateName() {
    // update the name 
    if(getCondition() != null)
      setProxyName(getCondition().getName());
    else setProxyName(null);
        
    if(getCondition() == null) {    
      // if the proxy is inverted and has a name
      if(isInverted() && getProxyName() != null 
         && getProxyName() != "" 
         && getProxyName().startsWith("!") == false)
        setProxyName("! ".concat(getProxyName()));  
         
      // if the proxy isn't inverted and has a name
      else if(!isInverted() && getProxyName() != null 
        && getProxyName() != "" 
        && getProxyName().startsWith("!")) {
         String name = getProxyName().substring(2);
             setProxyName(name);
      }  
    }
    else{
      String newName = getCondition().getName();
      if (isInverted()&& newName != null 
        && newName != "") {  
        if(getProxyName() == null) setProxyName("! ".concat(newName));
        else if(getProxyName() != null &&
           getProxyName().startsWith("!") == false)
           setProxyName("! ".concat(newName));
      }  
      else if(!isInverted() 
        && newName != "")
        if(getProxyName() != newName)
           setProxyName(newName);
    }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void a() {
    // TODO: implement this method
    // Ensure that you remove @generated or mark it @generated NOT
    throw new UnsupportedOperationException();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID) {
      case NewprocessPackage.CONDITION_PROXY__CONDITION_TERM:
        return ((InternalEList<InternalEObject>)(InternalEList<?>)getConditionTerm()).basicAdd(otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID) {
      case NewprocessPackage.CONDITION_PROXY__CONDITION_TERM:
        return ((InternalEList<?>)getConditionTerm()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID) {
      case NewprocessPackage.CONDITION_PROXY__CONDITION:
        if (resolve) return getCondition();
        return basicGetCondition();
      case NewprocessPackage.CONDITION_PROXY__INVERTED:
        return isInverted() ? Boolean.TRUE : Boolean.FALSE;
      case NewprocessPackage.CONDITION_PROXY__PROXY_NAME:
        return getProxyName();
      case NewprocessPackage.CONDITION_PROXY__CONDITION_TERM:
        return getConditionTerm();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue) {
    switch (featureID) {
      case NewprocessPackage.CONDITION_PROXY__CONDITION:
        setCondition((Condition)newValue);
        return;
      case NewprocessPackage.CONDITION_PROXY__INVERTED:
        setInverted(((Boolean)newValue).booleanValue());
        return;
      case NewprocessPackage.CONDITION_PROXY__PROXY_NAME:
        setProxyName((String)newValue);
        return;
      case NewprocessPackage.CONDITION_PROXY__CONDITION_TERM:
        getConditionTerm().clear();
        getConditionTerm().addAll((Collection<? extends ConditionTerm>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID) {
    switch (featureID) {
      case NewprocessPackage.CONDITION_PROXY__CONDITION:
        setCondition((Condition)null);
        return;
      case NewprocessPackage.CONDITION_PROXY__INVERTED:
        setInverted(INVERTED_EDEFAULT);
        return;
      case NewprocessPackage.CONDITION_PROXY__PROXY_NAME:
        setProxyName(PROXY_NAME_EDEFAULT);
        return;
      case NewprocessPackage.CONDITION_PROXY__CONDITION_TERM:
        getConditionTerm().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID) {
    switch (featureID) {
      case NewprocessPackage.CONDITION_PROXY__CONDITION:
        return condition != null;
      case NewprocessPackage.CONDITION_PROXY__INVERTED:
        return inverted != INVERTED_EDEFAULT;
      case NewprocessPackage.CONDITION_PROXY__PROXY_NAME:
        return PROXY_NAME_EDEFAULT == null ? proxyName != null : !PROXY_NAME_EDEFAULT.equals(proxyName);
      case NewprocessPackage.CONDITION_PROXY__CONDITION_TERM:
        return conditionTerm != null && !conditionTerm.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString() {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (inverted: ");
    result.append(inverted);
    result.append(", proxyName: ");
    result.append(proxyName);
    result.append(')');
    return result.toString();
  }

  /**
   * Validates the condition of the Proxy
   * @author sh
   */
  public boolean validateCondition(ConditionProxy value) {
    return ConditionProxyValidatorImpl.INSTANCE.validateCondition(value);
  }
} //ConditionProxyImpl
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.