示例#1
0
  public String getTableName(ENamedElement element) {
    String name = null;
    String typePrefix = null;

    if (element instanceof EClass) {
      typePrefix = TYPE_PREFIX_CLASS;
      name = DBAnnotation.TABLE_NAME.getValue(element);
      if (name == null) {
        name =
            isQualifiedNames()
                ? EMFUtil.getQualifiedName((EClass) element, NAME_SEPARATOR)
                : element.getName();
      }
    } else if (element instanceof EPackage) {
      typePrefix = TYPE_PREFIX_PACKAGE;
      name = DBAnnotation.TABLE_NAME.getValue(element);
      if (name == null) {
        name =
            isQualifiedNames()
                ? EMFUtil.getQualifiedName((EPackage) element, NAME_SEPARATOR)
                : element.getName();
      }
    } else {
      throw new ImplementationError("Unknown element: " + element); // $NON-NLS-1$
    }

    String prefix = getTableNamePrefix();
    if (prefix.length() != 0 && !prefix.endsWith(NAME_SEPARATOR)) {
      prefix += NAME_SEPARATOR;
    }

    return getName(prefix + name, typePrefix + getUniqueID(element), getMaxTableNameLength());
  }
 public void testCreatedErrors_06() {
   maxCallCount = 1;
   ImmutableList<ENamedElement> elements =
       ImmutableList.of(createEPackage(), createEDataType(), createEPackage());
   for (ENamedElement classifier : elements) {
     classifier.setName("Same");
   }
   helper.checkUniqueNames(Scopes.scopedElementsFor(elements), this, this);
   assertEquals(1, callCount);
 }
 public void testCreatedErrors_04() {
   maxCallCount = 0;
   ImmutableList<ENamedElement> elements =
       ImmutableList.of(createEClass(), createEDataType(), createEPackage(), createEPackage());
   for (ENamedElement classifier : elements) {
     classifier.setName("Same");
   }
   expected.addAll(elements);
   helper.checkUniqueNames(Scopes.scopedElementsFor(elements), this, this);
   assertEquals(elements.size(), callCount);
   assertTrue(expected.isEmpty());
 }
  @Override
  public String eURIFragmentSegment(EStructuralFeature eStructuralFeature, EObject eObject) {
    if (eObject instanceof ENamedElement) {
      ENamedElement eNamedElement = (ENamedElement) eObject;
      String name = eNamedElement.getName();
      if (name != null) {
        int count = 0;
        for (Object otherEObject : eContents()) {
          if (otherEObject == eObject) {
            break;
          }
          if (otherEObject instanceof ENamedElement) {
            ENamedElement otherENamedElement = (ENamedElement) otherEObject;
            if (name.equals(otherENamedElement.getName())) {
              ++count;
            }
          }
        }
        name = eEncodeValue(name);
        return count > 0 ? name + "." + count : name;
      }
    } else if (eObject instanceof EAnnotation) {
      EAnnotation eAnnotation = (EAnnotation) eObject;
      String source = eAnnotation.getSource();
      if (source != null) {
        int count = 0;
        for (Object otherEObject : eContents()) {
          if (otherEObject == eObject) {
            break;
          }
          if (otherEObject instanceof EAnnotation) {
            EAnnotation otherEAnnotation = (EAnnotation) otherEObject;
            if (source.equals(otherEAnnotation.getSource())) {
              ++count;
            }
          }
        }

        StringBuffer result = new StringBuffer(source.length() + 5);
        result.append('%');
        result.append(URI.encodeSegment(source, false));
        result.append('%');
        if (count > 0) {
          result.append('.');
          result.append(count);
        }
        return result.toString();
      }
    }
    return super.eURIFragmentSegment(eStructuralFeature, eObject);
  }
 public void testCreatedErrors_07() {
   maxCallCount = 0;
   ImmutableList<ENamedElement> elements =
       ImmutableList.of(
           createEPackage(), createEDataType(), EcoreFactory.eINSTANCE.createEEnumLiteral());
   for (ENamedElement classifier : elements) {
     classifier.setName("Same");
   }
   expected.add(elements.get(0));
   expected.add(elements.get(2));
   helper.checkUniqueNames(Scopes.scopedElementsFor(elements), this, this);
   assertEquals(elements.size(), callCount);
   assertTrue(expected.isEmpty());
 }
  private static StringBuffer qualifiedName(ENamedElement namedElement, StringBuffer buf) {
    if (buf == null) {
      buf = new StringBuffer();
    }
    EObject container = namedElement.eContainer();
    if (container instanceof ENamedElement) {
      ENamedElement owner = (ENamedElement) container;
      qualifiedName(owner, buf);
      buf.append("::"); // $NON-NLS-1$		
    }

    buf.append(namedElement.getName());
    return buf;
  }
 public String getLocalName(ENamedElement object) {
   String name = object != null ? object.getName() : null;
   return name != null ? name : "<???>";
 }
  /**
   * This method creates a {@link ReportingRecord} object with values from commodity , service
   * entity and attribute provided to it every hour.
   *
   * @param reportingExtension Extension object
   * @param vObj ServiceEntity object
   * @param attribute attribute reported on
   * @param commodityName Commodity named element
   * @param commodity {@link Commodity} object to get provider uuid
   * @param isNumProduces whether reporting on numProduces attribute
   * @return {@link ReportingRecord} object
   */
  private ReportingRecord createReportingRecord(
      ReportingExtension reportingExtension,
      VMTRootObject vObj,
      EStructuralFeature attribute,
      ENamedElement commodityName,
      Commodity commodity,
      boolean isNumProduces,
      long snapshotTime) {
    ReportingRecord record = ReportingFactory.eINSTANCE.createReportingRecord();
    try {
      // long snapshotTime = (System.currentTimeMillis() - (1000*60*60));
      if (reportingExtension.eClass()
          == ReportingExtensionsPackage.eINSTANCE.getCommodityReportingExt()) {
        CommodityReportingExt crExt = (CommodityReportingExt) reportingExtension;
        if (crExt.getMinUtilization() == -1d || crExt.getMaxUtilization() == -1d) {
          return null;
        }
        record.setTimeStamp(snapshotTime);
        record.setSeUuId(vObj.getUuid());
        record.setPropertyType(commodityName.getName());
        record.setPropertySubType(attribute.getName());
        record.setMinUtilization(crExt.getMinUtilization());
        record.setMaxUtilization(crExt.getMaxUtilization());
        record.setAvgUtilization(crExt.getAvgUtilization());
        record.setCapacity(crExt.getCapacity());
        record.setRelation(crExt.getRelation());

        if (crExt.getCommodityKey() != null) {
          String commodityKey = truncateString(crExt.getCommodityKey(), 80);
          record.setCommodityKey(commodityKey);
        }

        if (!commodity.getConsumes().isEmpty()
            && commodity.getConsumes().get(0).getSoldBy() != null) {
          record.setProviderUuId(commodity.getConsumes().get(0).getSoldBy().getUuid());
        }
        // record.setStdDev(0);
      } else if (reportingExtension.eClass()
          == ReportingExtensionsPackage.eINSTANCE.getServiceEntityReportingExt()) {
        ServiceEntityReportingExt seExt = (ServiceEntityReportingExt) reportingExtension;
        if (isNumProduces) {
          if (seExt.getMinNumProduces() == -1 || seExt.getMaxNumProduces() == -1) {
            return null;
          }
          record.setTimeStamp(snapshotTime);
          record.setSeUuId(vObj.getUuid());
          record.setPropertyType(attribute.getName());
          record.setPropertySubType(attribute.getName());
          record.setMinUtilization(seExt.getMinNumProduces());
          record.setMaxUtilization(seExt.getMaxNumProduces());
          record.setAvgUtilization(seExt.getAvgProduces());
          record.setRelation(-1);
          record.setCommodityKey(null);
          // record.setStdDev(0);
        } else {

          if (seExt.getMinPropValue() == -1d || seExt.getMaxPropValue() == -1d) {
            return null;
          }

          if (attribute == AnalysisPackage.eINSTANCE.getServiceEntity_PriceIndex()) {
            if ((seExt.getMinPropValue() < 0)
                || (seExt.getMaxPropValue() < 0)
                || (seExt.getAvgPropValue() < 0)) {
              if (logger.isDebugEnabled()) {
                logger.error(
                    "SE : "
                        + vObj.toVMTString()
                        + " has max, min and avg PriceIndex values of "
                        + seExt.getMaxPropValue()
                        + ", "
                        + seExt.getMinPropValue()
                        + " and "
                        + seExt.getAvgPropValue()
                        + " respectively");
              }
              return null;
            }
          }

          record.setTimeStamp(snapshotTime);
          record.setSeUuId(vObj.getUuid());
          record.setPropertyType(attribute.getName());
          record.setPropertySubType(attribute.getName());
          record.setRelation(-1);
          record.setCommodityKey(null);
          record.setMinUtilization(seExt.getMinPropValue());
          record.setMaxUtilization(seExt.getMaxPropValue());
          record.setAvgUtilization(seExt.getAvgPropValue());
        }
      }
    } catch (Exception e) {
      logger.error("Exception in creating record ", e);
    }
    return record;
  }
 public boolean isEnabled(EClass c, ENamedElement element) {
   return prefs.getBoolean(c.getName() + "." + element.getName(), true);
 }
 /** @generated */
 private static String getImageRegistryKey(ENamedElement element) {
   return element.getName();
 }
  @Override
  public EObject eObjectForURIFragmentSegment(String uriFragmentSegment) {
    int length = uriFragmentSegment.length();
    if (length > 0) {
      // Is the first character a special character, i.e., something other than '@'?
      //
      char firstCharacter = uriFragmentSegment.charAt(0);
      if (firstCharacter != '@') {
        // Is it the start of a source URI of an annotation?
        //
        if (firstCharacter == '%') {
          // Find the closing '%'
          //
          int index = uriFragmentSegment.lastIndexOf("%");
          boolean hasCount = false;
          if (index == length - 1 || (hasCount = uriFragmentSegment.charAt(index + 1) == '.')) {
            // Decode all encoded characters.
            //
            String source = URI.decode(uriFragmentSegment.substring(1, index));

            // Check for a count, i.e., a '.' followed by a number.
            //
            int count = 0;
            if (hasCount) {
              try {
                count = Integer.parseInt(uriFragmentSegment.substring(index + 2));
              } catch (NumberFormatException exception) {
                throw new WrappedException(exception);
              }
            }

            // Look for the annotation with the matching source.
            //
            for (Object object : eContents()) {
              if (object instanceof EAnnotation) {
                EAnnotation eAnnotation = (EAnnotation) object;
                if (source.equals(eAnnotation.getSource()) && count-- == 0) {
                  return eAnnotation;
                }
              }
            }
            return null;
          }
        }

        // Look for trailing count.
        //
        int index = uriFragmentSegment.lastIndexOf(".");
        String name = index == -1 ? uriFragmentSegment : uriFragmentSegment.substring(0, index);
        int count = 0;
        if (index != -1) {
          try {
            count = Integer.parseInt(uriFragmentSegment.substring(index + 1));
          } catch (NumberFormatException exception) {
            // Interpret it as part of the name.
            //
            name = uriFragmentSegment;
          }
        }

        name = URI.decode(name);

        // Look for a matching named element.
        //
        for (Object object : eContents()) {
          if (object instanceof ENamedElement) {
            ENamedElement eNamedElement = (ENamedElement) object;
            if (name.equals(eNamedElement.getName()) && count-- == 0) {
              return eNamedElement;
            }
          }
        }

        return null;
      }
    }

    return super.eObjectForURIFragmentSegment(uriFragmentSegment);
  }