Пример #1
0
 /**
  * Get the value of the named AD parameter for the activity as a string. Works with several types,
  * not just strings -- enums, for example.
  *
  * @param element
  * @param parameterName
  * @return null if the parameter is not found
  */
 public static String getParameterString(EPlanElement element, String parameterName) {
   EObject data = element.getData();
   if (data == null) return null;
   EStructuralFeature feature;
   try {
     feature = getParameterFeature(data, parameterName);
   } catch (UndefinedParameterException e) {
     return null;
   }
   Object object = data.eGet(feature);
   if (object instanceof EEnumLiteral) {
     EEnumLiteral literal = (EEnumLiteral) object;
     return literal.getName();
   }
   EClassifier type = feature.getEType();
   if (type instanceof EDataType) {
     EDataType dataType = (EDataType) type;
     EPackage typePackage = dataType.getEPackage();
     EFactory factory = typePackage.getEFactoryInstance();
     String string = factory.convertToString(dataType, object);
     return string;
   }
   LogUtil.warnOnce("feature type '" + type + "'is not EDataType: " + parameterName);
   return String.valueOf(object);
 }
Пример #2
0
 /**
  * Get the value of the named AD parameter for the activity
  *
  * @param element
  * @param parameterName
  * @return
  * @throws UndefinedParameterException
  */
 @SuppressWarnings("unchecked")
 public static <T> T getParameterObject(EPlanElement element, String parameterName)
     throws UndefinedParameterException {
   EObject data = element.getData();
   if (data == null)
     throw new UndefinedParameterException("Null data for plan element " + element);
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   return (T) data.eGet(feature);
 }
Пример #3
0
 /**
  * Returns whether activity contains AD parameter of given type
  *
  * @param element
  * @param parameterType
  * @return
  */
 @SuppressWarnings("unchecked")
 public static boolean isParameterForType(EPlanElement element, EClass parameterType) {
   EObject data = element.getData();
   EList<EStructuralFeature> structuralFeatures = data.eClass().getEStructuralFeatures();
   for (int i = 0; i < structuralFeatures.size(); i++) {
     final EStructuralFeature feature = structuralFeatures.get(i);
     if (parameterType == feature.getEType()) return true;
   }
   return false;
 }
Пример #4
0
 /**
  * Get the value of the AD parameter by type for the activity
  *
  * @param element
  * @param parameterType
  * @return
  */
 @SuppressWarnings("unchecked")
 public static <T> Option<T> getParameterObjectByType(EPlanElement element, EClass parameterType) {
   EObject data = element.getData();
   EList<EStructuralFeature> structuralFeatures = data.eClass().getEStructuralFeatures();
   for (int i = 0; i < structuralFeatures.size(); i++) {
     final EStructuralFeature feature = structuralFeatures.get(i);
     if (parameterType == feature.getEType()) return Option.fromNull((T) data.eGet(feature));
   }
   return Option.none();
 }
Пример #5
0
  public static List getReferences(EPlanElement element, String attribute)
      throws UndefinedParameterException {
    EObject data = element.getData();
    if (data == null) {
      return null;
    }

    EStructuralFeature feature = getParameterFeature(data, attribute);
    List groupReferences = (List) data.eGet(feature);
    return groupReferences;
  }
Пример #6
0
 public static String addParameterStringToListCaseInsensitive(
     EPlanElement element, String parameterName, String newValue)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   EClassifier type = feature.getEType();
   if (type instanceof EEnum) {
     EEnum enumType = (EEnum) type;
     EEnumLiteral literal = getCaseInsensitiveValue(enumType, newValue);
     addParameterObjectToList(element, parameterName, literal);
     return literal == null ? null : literal.getLiteral();
   } else {
     addParameterStringToList(element, parameterName, newValue);
     return newValue;
   }
 }
Пример #7
0
 @SuppressWarnings("unchecked")
 public static void addParameterObjectToList(
     EPlanElement element, String parameterName, Object object)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   Object value = data.eGet(feature);
   if (!(value instanceof EList)) {
     Logger logger = Logger.getLogger(ADParameterUtils.class);
     logger.warn("feature value '" + value + "' is not EList: " + parameterName);
     return;
   }
   EList list = (EList) value;
   if (object != null && !list.contains(object)) {
     list.add(object);
   }
 }
Пример #8
0
  /**
   * Add a reference to a named AD
   *
   * @param element
   * @param referenceURI
   * @param referenceID
   * @param attribute
   */
  @SuppressWarnings("unchecked")
  public static void addReference(
      EPlanElement element, URI referenceURI, String referenceID, String attribute) {
    if (referenceURI != null) {
      EObject data = element.getData();
      EStructuralFeature feature = data.eClass().getEStructuralFeature(attribute);
      EClass referenceClass = (EClass) feature.getEType();
      List groupReferences = (List) data.eGet(data.eClass().getEStructuralFeature(attribute));

      URI uri = referenceURI.appendFragment(referenceID);
      EObject groupObject =
          ActivityDictionary.getInstance().getEFactoryInstance().create(referenceClass);
      ((BasicEObjectImpl) groupObject).eSetProxyURI(uri);
      if (!groupReferences.contains(groupObject)) {
        groupReferences.add(groupObject);
      }
    }
  }
Пример #9
0
 /**
  * Add a value to a named AD multi-select EEnum parameter for the activity
  *
  * @param element
  * @param parameterName
  * @param newValue
  * @throws UndefinedParameterException
  */
 @SuppressWarnings("unchecked")
 public static void addParameterStringToList(
     EPlanElement element, String parameterName, String newValue)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   EClassifier type = feature.getEType();
   Object object;
   if (type instanceof EEnum) {
     EEnum enumType = (EEnum) type;
     object = enumType.getEEnumLiteral(newValue);
   } else if (type instanceof EDataType) {
     EDataType dataType = (EDataType) type;
     EPackage typePackage = dataType.getEPackage();
     EFactory factory = typePackage.getEFactoryInstance();
     object = factory.createFromString(dataType, newValue);
   } else {
     Logger logger = Logger.getLogger(ADParameterUtils.class);
     logger.warn("feature type '" + type + "'is not EDataType: " + parameterName);
     object = newValue;
   }
   addParameterObjectToList(element, parameterName, object);
 }
Пример #10
0
 /**
  * Get the feature for the named parameter
  *
  * @param element
  * @param name
  * @return
  * @throws UndefinedParameterException
  */
 public static EStructuralFeature getParameterFeature(EPlanElement element, String name)
     throws UndefinedParameterException {
   EObject data = element.getData();
   return getParameterFeature(data, name);
 }
Пример #11
0
 /**
  * Set the value of the named AD parameter for the activity
  *
  * @param element
  * @param parameterName
  * @param object
  * @throws UndefinedParameterException
  */
 public static void setParameterString(EPlanElement element, String parameterName, String newValue)
     throws UndefinedParameterException {
   setParameterStringInData(element.getData(), parameterName, newValue);
 }
Пример #12
0
 /**
  * Set the value of the named AD parameter for the activity
  *
  * @param element
  * @param parameterName
  * @param object
  * @throws UndefinedParameterException
  */
 public static void setParameterObject(EPlanElement element, String parameterName, Object newValue)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   data.eSet(feature, newValue);
 }