Exemplo n.º 1
0
 public String calculateDefaultStringValue(Property f) {
   if (f.getType() instanceof Enumeration) {
     OJEnum javaType = (OJEnum) findJavaClass((Classifier) f.getType());
     if (javaType.getLiterals().size() > 0) {
       return javaType.getLiterals().get(0).getName();
     } else {
       return javaType.getName() + ".has no literals!!!!";
     }
   } else if (EmfClassifierUtil.isSimpleType(f.getType())) {
     DataType baseType = (DataType) f.getType();
     if (EmfClassifierUtil.hasStrategy(baseType, ConfigurableDataStrategy.class)) {
       return EmfClassifierUtil.getStrategy(baseType, ConfigurableDataStrategy.class)
           .getDefaultStringValue();
     } else if (f.getType() instanceof PrimitiveType) {
       String calculateDefaultValue = calculateDefaultValue(f);
       if (calculateDefaultValue.startsWith("\"") && calculateDefaultValue.endsWith("\"")) {
         calculateDefaultValue =
             calculateDefaultValue.substring(1, calculateDefaultValue.length() - 1);
       }
       return calculateDefaultValue;
     } else {
       return "no ConfigurableDataStrategy strategy!!!";
     }
   }
   return "BLASDFASDFadsf";
 }
Exemplo n.º 2
0
 protected boolean isPersistent(Classifier c) {
   if (EmfClassifierUtil.isComplexStructure(c)) {
     return EmfClassifierUtil.isPersistent(c);
   } else {
     return false;
   }
 }
Exemplo n.º 3
0
 protected String calculateDefaultValue(OJAnnotatedClass test, OJBlock block, Property f) {
   String value = calculateDefaultValue(f);
   if (EmfClassifierUtil.isSimpleType(f.getType())) {
     DataType baseType = (DataType) f.getType();
     test.addToImports(ojUtil.classifierPathname(baseType));
     if (EmfClassifierUtil.hasStrategy(baseType, TestModelValueStrategy.class)) {}
   } else if (f.getType() instanceof Enumeration) {
     OJAnnotatedClass javaType = findJavaClass((Classifier) f.getType());
     test.addToImports(javaType.getPathName());
   } else if (getConcreteImplementations((Interface) f.getType()).size() > 0) {
     return lookup(test, f);
   }
   return value;
 }
Exemplo n.º 4
0
 @VisitBefore(matchSubclasses = true)
 public void class_Before(Class st) {
   if (isPersistent(st)) {
     Property composite = workspace.getOpaeumLibrary().getEndToComposite(st);
     if (composite != null) {
       if (!isPersistent((Classifier) composite.getType())) {
         getErrorMap().putError(st, CompositionValidationRule.PERSISTENT_CONTAINS_PERSISTENT);
       }
       if (EmfClassifierUtil.isCompositionParticipant(st)) {
         int composites = 0;
         for (Property f : workspace.getOpaeumLibrary().getEffectiveAttributes(st)) {
           if (f instanceof Property) {
             Property p = f;
             if (!EmfPropertyUtil.isDerived(p)
                 && p.getOtherEnd() != null
                 && p.getOtherEnd().isComposite()
                 && !EmfPropertyUtil.isDerived(p.getOtherEnd())) {
               composites++;
             }
           }
         }
         if (composites > 1) {
           getErrorMap()
               .putError(st, CompositionValidationRule.ENTITIES_HAVE_ONE_COMPOSITE_ONLY, "");
         }
       }
     }
   }
 }
 @Override
 public boolean select(Element e) {
   boolean isMapped =
       e.eResource().getResourceSet() instanceof IUIElementMapMap
           && ((IUIElementMapMap) e.eResource().getResourceSet()).getElementFor(e) != null;
   if (isMapped) {
     if (e instanceof TypedElement
         && e instanceof MultiplicityElement
         && ((TypedElement) e).getType() != null) {
       return EmfClassifierUtil.isPersistentComplexStructure(((TypedElement) e).getType());
     }
   }
   return false;
 }
Exemplo n.º 6
0
 public String calculateDefaultValue(Property f) {
   double value = Math.random() * 123456;
   if (EmfClassifierUtil.isSimpleType(f.getType())) {
     DataType baseType = (DataType) f.getType();
     if (EmfClassifierUtil.hasStrategy(baseType, TestModelValueStrategy.class)) {
       return EmfClassifierUtil.getStrategy(baseType, TestModelValueStrategy.class)
           .getDefaultStringValue(12341);
     } else if (workspace.getOpaeumLibrary().getDateType() != null
         && f.getType().conformsTo(workspace.getOpaeumLibrary().getDateType())) {
       String javaDate = ojUtil.classifierPathname(baseType).toJavaString();
       if (javaDate.equals("java.util.Date")) {
         return "new Date()";
       } else if (javaDate.equals("java.util.Calendar")) {
         return "Calendar.getInstance()";
       } else {
         return "new Date()";
       }
     } else if (f.getType() instanceof PrimitiveType) {
       PrimitiveType t = (PrimitiveType) f.getType();
       if (EmfClassifierUtil.comformsToLibraryType(t, "Integer")) {
         return "" + new Double(value).intValue();
       } else if (EmfClassifierUtil.comformsToLibraryType(t, "Real")) {
         return "" + new Double(value).floatValue();
       } else if (EmfClassifierUtil.comformsToLibraryType(t, "Boolean")) {
         return "" + ((Math.round(value) % 2) == 1);
       } else if (f.getName().equals("name")) {
         return "\"" + ((Classifier) f.getOwner()).getName() + value + "\"";
       } else {
         return "\"" + ((Classifier) f.getOwner()).getName() + "." + f.getName() + value + "\"";
       }
     }
     return "no TestValueStrategy found ";
   } else if (f.getType() instanceof Enumeration) {
     return f.getType().getName() + ".values()[0]";
   } else if (f.getType() instanceof Interface
       && getConcreteImplementations((Interface) f.getType()).size() > 0) {
     return lookup(f);
   } else {
     return "\""
         + ((Classifier) f.getOwner()).getName()
         + "::"
         + f.getName()
         + new Double(value).intValue()
         + "\"";
   }
 }
Exemplo n.º 7
0
 protected List<BehavioredClassifier> getConcreteImplementations(Interface i) {
   return new ArrayList<BehavioredClassifier>(
       EmfClassifierUtil.getConcreteEntityImplementationsOf(i, getModelInScope()));
 }
Exemplo n.º 8
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 public Collection<Classifier> getConcreteSubclassifiersOf(Classifier nakedBaseType) {
   return (Collection) EmfClassifierUtil.getAllSubClassifiers(nakedBaseType, getModelInScope());
 }