private void addTmpIdToFromJson(OJAnnotatedClass annotatedClass) { OJAnnotatedOperation fromJson = annotatedClass.findOperation("fromJsonDataTypeAndComposite", new OJPathName("java.util.Map")); OJIfStatement ifStatement = new OJIfStatement("propertyMap.containsKey(\"tmpId\")"); OJIfStatement ifStatement1 = new OJIfStatement("propertyMap.get(\"tmpId\") != null"); ifStatement.addToThenPart(ifStatement1); ifStatement1.addToThenPart("this.tmpId = (String)propertyMap.get(\"tmpId\")"); ifStatement1.addToThenPart(UmlgGenerationUtil.UmlgTmpIdManager.getLast() + ".INSTANCE.put(this.tmpId, getId())"); annotatedClass.addToImports(UmlgGenerationUtil.UmlgTmpIdManager); ifStatement1.addToElsePart("this.tmpId = null"); fromJson.getBody().addToStatements(ifStatement); }
public void copyDeepInfoInto(OJIfStatement copy) { super.copyDeepInfoInto(copy); copy.setCondition(getCondition()); if (getThenPart() != null) { copy.setThenPart(getThenPart().getDeepCopy()); } if (getElsePart() != null) { copy.setElsePart(getElsePart().getDeepCopy()); } }
public OJIfStatement getDeepCopy() { OJIfStatement copy = new OJIfStatement(); copyDeepInfoInto(copy); return copy; }
public OJIfStatement(String condition, String thenPart, String elsePart) { super(); this.setThenPart(new OJBlock()); this.setCondition(condition); this.addToThenPart(thenPart); this.addToElsePart(elsePart); }
public void renameAll(Set<OJPathName> renamePathNames, String suffix) { setCondition(replaceAll(getCondition(), renamePathNames, suffix)); if (getThenPart() != null) { getThenPart().renameAll(renamePathNames, suffix); } if (getElsePart() != null) { getElsePart().renameAll(renamePathNames, suffix); } }
OJIfStatement ifInsert = new OJIfStatement("o != null"); OJIfStatement ifArrayForInsert = new OJIfStatement("o instanceof ArrayList"); OJIfStatement ifEmpty = new OJIfStatement("!((List)o).isEmpty()"); ifArrayForInsert.addToThenPart(ifEmpty); annotatedClass.addToImports("java.util.List"); ifEmpty.addToThenPart("throw new IllegalStateException(\"Adding an association class happens from the association member end!\")"); ifArrayForInsert.addToElsePart("throw new IllegalStateException(\"Adding an association class happens from the association member end!\")"); ifInsert.addToThenPart(ifArrayForInsert); ojTryStatement.getTryPart().addToStatements(ifInsert); OJIfStatement ifDelete = new OJIfStatement("o != null"); OJIfStatement ifArrayForDelete = new OJIfStatement("o instanceof ArrayList"); ifEmpty = new OJIfStatement("!((List)o).isEmpty()"); ifArrayForDelete.addToThenPart(ifEmpty); ifEmpty.addToThenPart("throw new IllegalStateException(\"Deleting an association class happens from the association member end!\")"); ifArrayForDelete.addToElsePart("throw new IllegalStateException(\"Deleting an association class happens from the association member end!\")"); ifDelete.addToThenPart(ifArrayForDelete); ojTryStatement.getTryPart().addToStatements(ifDelete); OJIfStatement ifUpdate = new OJIfStatement("o != null"); OJIfStatement ifArrayForUpdate = new OJIfStatement("o instanceof ArrayList"); OJPathName genericsForArray = new OJPathName("java.util.Map").addToGenerics("String").addToGenerics("Object"); OJField array = new OJField("array", new OJPathName("java.util.ArrayList").addToGenerics(genericsForArray)); array.setInitExp("(ArrayList<Map<String, Object>>)o"); ifArrayForUpdate.getThenPart().addToLocals(array); ifUpdate.addToThenPart(ifArrayForUpdate); ojTryStatement.getTryPart().addToStatements(ifUpdate); ifArrayForUpdate.addToThenPart(forArray);
OJIfStatement ifNotNull = new OJIfStatement(propertyWrapper.fieldname() + " != null"); ifNotNull.addToThenPart(ojBlock1); ifNotNull.addToThenPart(ojBlock2); OJIfStatement ifExist = new OJIfStatement("!this." + propertyWrapper.fieldname() + ".isEmpty()"); ifExist.addToThenPart("throw new RuntimeException(\"Property " + propertyWrapper.getQualifiedName() + " is a one and already has a value!\")"); ojBlock1.addToStatements(ifExist); } else { OJIfStatement ifAlreadySet = new OJIfStatement("!this." + propertyWrapper.fieldname() + ".isEmpty()"); ifAlreadySet.addToThenPart("throw new RuntimeException(\"Property is a one and already has value, first clear it before adding!\")"); singleAdder.getBody().addToStatements(ifAlreadySet); OJIfStatement ifNotNull = new OJIfStatement(propertyWrapper.fieldname() + " != null"); ifNotNull.getThenPart().addToLocals(failedConstraints); OJIfStatement ifValidated = new OJIfStatement("violations.isEmpty()"); ifValidated.addToThenPart("this." + propertyWrapper.fieldname() + ".add(" + propertyWrapper.fieldname() + ")"); ifNotNull.addToThenPart(ifValidated); ifValidated.addToElsePart("throw new UmlgConstraintViolationException(violations)"); owner.addToImports(UmlgGenerationUtil.UmlgConstraintViolationException);
OJIfStatement ifInsert = new OJIfStatement("o != null"); OJIfStatement ifArrayForInsert = new OJIfStatement("o instanceof ArrayList"); OJPathName genericsForArray = new OJPathName("java.util.Map").addToGenerics("String").addToGenerics("Object"); OJField array = new OJField("array", new OJPathName("java.util.ArrayList").addToGenerics(genericsForArray)); array.setInitExp("(ArrayList<Map<String, Object>>)o"); ifArrayForInsert.getThenPart().addToLocals(array); ifInsert.addToThenPart(ifArrayForInsert); ifArrayForInsert.addToThenPart(forArray); forArray.getBody().addToStatements("add(parentResource, map)"); ifArrayForInsert.setElsePart(new OJBlock()); ifArrayForInsert.getElsePart().addToLocals(map); ifArrayForInsert.getElsePart().addToStatements("add(parentResource, map)"); OJIfStatement ifDelete = new OJIfStatement("o != null"); OJIfStatement ifArrayForDelete = new OJIfStatement("o instanceof ArrayList"); genericsForArray = new OJPathName("java.util.Map").addToGenerics("String").addToGenerics("Object"); array = new OJField("array", new OJPathName("java.util.ArrayList").addToGenerics(genericsForArray)); array.setInitExp("(ArrayList<Map<String, Object>>)o"); ifArrayForDelete.getThenPart().addToLocals(array); ifDelete.addToThenPart(ifArrayForDelete); ojTryStatement.getTryPart().addToStatements(ifDelete); forArray = new OJForStatement("map", new OJPathName("java.util.Map").addToGenerics(new OJPathName("String")).addToGenerics( new OJPathName("Object")), "array"); ifArrayForDelete.addToThenPart(forArray); if (pWrap.isComposite()) { forArray.getBody().addToStatements("delete(map)");
protected void commitOrRollback(OJTryStatement ojTryStatement) { OJIfStatement ifTransactionNeedsCommitOrRollback = new OJIfStatement("!(getQueryValue(\"" + UmlgGenerationUtil.rollback+ "\") != null && Boolean.valueOf(getQueryValue(\"" + UmlgGenerationUtil.rollback + "\")))"); ifTransactionNeedsCommitOrRollback.addToThenPart(UmlgGenerationUtil.UMLGAccess + ".commit()"); ojTryStatement.getTryPart().addToStatements(ifTransactionNeedsCommitOrRollback); ojTryStatement.getFinallyPart().addToStatements(UmlgGenerationUtil.UMLGAccess + ".rollback()"); }
private void addConstraints(OJAnnotatedClass annotatedClass, Class clazz) { List<Constraint> constraints = ModelLoader.INSTANCE.getConstraints(clazz); for (Constraint constraint : constraints) { ConstraintWrapper constraintWrapper = new ConstraintWrapper(constraint); OJAnnotatedOperation checkClassConstraint = new OJAnnotatedOperation(UmlgClassOperations.checkClassConstraintName(constraint)); checkClassConstraint.setReturnType(new OJPathName("java.util.List").addToGenerics(UmlgGenerationUtil.UmlgConstraintViolation)); OJField result = new OJField("result", new OJPathName("java.util.List").addToGenerics(UmlgGenerationUtil.UmlgConstraintViolation)); result.setInitExp("new ArrayList<" + UmlgGenerationUtil.UmlgConstraintViolation.getLast() + ">()"); OJIfStatement ifConstraintFails = new OJIfStatement(); String ocl = constraintWrapper.getConstraintOclAsString(); checkClassConstraint.setComment(String.format("Implements the ocl statement for constraint '%s'\n<pre>\n%s\n</pre>", constraintWrapper.getName(), ocl)); OCLExpression<Classifier> oclExp = UmlgOcl2Parser.INSTANCE.parseOcl(ocl); ifConstraintFails.setCondition("(" + UmlgOcl2Java.oclToJava(clazz, annotatedClass, oclExp) + ") == false"); ifConstraintFails.addToThenPart("result.add(new " + UmlgGenerationUtil.UmlgConstraintViolation.getLast() + "(\"" + constraintWrapper.getName() + "\", \"" + clazz.getQualifiedName() + "\", \"ocl\\n" + ocl.replace("\n", "\\n") + "\\nfails!\"))"); checkClassConstraint.getBody().addToStatements(ifConstraintFails); checkClassConstraint.getBody().addToLocals(result); checkClassConstraint.getBody().addToStatements("return result"); annotatedClass.addToOperations(checkClassConstraint); } }
OJIfStatement ifOneInstanceOf = new OJIfStatement("parentResource." + pWrap.getter() + "() != null && parentResource." + pWrap.getter() + "().getClass() == " + UmlgClassOperations.getPathName(concreteClassifierTo).getLast() + ".class"); ifOneInstanceOf.addToThenPart("json.append(" + UmlgGenerationUtil.ToJsonUtil.getLast() + ".toJsonWithoutCompositeParent(parentResource." + pWrap.getter() + "()))"); ifOneInstanceOf.addToElsePart("json.append(\"null\")"); block.addToStatements(ifOneInstanceOf); } else { OJIfStatement ifOneInstanceOf = new OJIfStatement("parentResource." + pWrap.getter() + "() != null && parentResource." + pWrap.associationClassGetter() + "().getClass() == " + UmlgClassOperations.getPathName(concreteClassifierTo).getLast() + ".class"); ifOneInstanceOf.addToThenPart("json.append(" + UmlgGenerationUtil.ToJsonUtil.getLast() + ".toJsonWithoutCompositeParent(parentResource." + pWrap.associationClassGetter() + "()))"); ifOneInstanceOf.addToElsePart("json.append(\"null\")"); block.addToStatements(ifOneInstanceOf); OJIfStatement ifStatementFrom = new OJIfStatement(); for (Classifier concreteClassifierFrom : concreteImplementationsFrom) { OJBlock conditionBlockFrom = new OJBlock(); String condition = "parentResource.getClass() == " + UmlgClassOperations.getPathName(concreteClassifierFrom).getLast() + ".class"; if (countFrom == 1) { ifStatementFrom.setCondition(condition); ifStatementFrom.setThenPart(conditionBlockFrom); } else if (countFrom == concreteImplementationsFrom.size()) { ifStatementFrom.setElsePart(conditionBlockFrom); } else { conditionBlockFrom = ifStatementFrom.addToElseIfCondition(condition, "");
for (PropertyWrapper qualifier : qualifiers) { OJIfStatement ifHasNotNull = new OJIfStatement(); ifHasNotNull.setCondition(qualifier.fieldname() + " != null"); ifHasNotNull.addToThenPart("graphTraversal.has(" + "\"" + qualifier.getQualifierCorrespondingQualifierStereotypedProperty().getPersistentName() + "\", " + ojClass.addToImports(UmlgGenerationUtil.tinkerDirection); ojClass.addToImports("java.util.Iterator"); OJIfStatement ifHasNext = new OJIfStatement("graphTraversal.hasNext()"); OJSimpleStatement ojSimpleStatement; ojSimpleStatement = new OJSimpleStatement("return new " ojSimpleStatement.setExpression(ojSimpleStatement.getExpression() + "(graphTraversal, " + qualified.getTumlRuntimePropertyEnum() + ")"); ojClass.addToImports(qualified.javaClosableIteratorTypePath()); ifHasNext.addToThenPart(ojSimpleStatement); ifHasNext.addToElsePart("return " + qualified.emptyCollection()); ojClass.addToImports(UmlgGenerationUtil.umlgUmlgCollections);
OJIfStatement ifStatementFrom = new OJIfStatement(); for (Classifier concreteClassifierFrom : concreteImplementationsFrom) { OJBlock conditionBlockFrom = new OJBlock(); String condition = "parentResource.getClass() == " + UmlgClassOperations.getPathName(concreteClassifierFrom).getLast() + ".class"; if (countFrom == 1) { ifStatementFrom.setCondition(condition); ifStatementFrom.setThenPart(conditionBlockFrom); } else if (countFrom == concreteImplementationsFrom.size()) { ifStatementFrom.setElsePart(conditionBlockFrom); } else { conditionBlockFrom = ifStatementFrom.addToElseIfCondition(condition, "");
OJIfStatement isInverse = new OJIfStatement("!inverse"); isInverse.setThenPart(new OJBlock()); isInverse.setElsePart(new OJBlock()); isInverse.getThenPart().addToStatements("runtimeProperty = (" + UmlgClassOperations.propertyEnumName(clazz) + ".fromQualifiedName(tumlRuntimeProperty.getQualifiedName()))"); isInverse.getElsePart().addToStatements("runtimeProperty = (" + UmlgClassOperations.propertyEnumName(clazz) + ".fromQualifiedName(tumlRuntimeProperty.getInverseQualifiedName()))"); OJIfStatement ifResultNull = new OJIfStatement("result == null"); ifResultNull.setThenPart(new OJBlock()); getCollectionFor.getBody().addToStatements(ifResultNull); ifResultNull.getThenPart().addToLocals(runtimeProperty); ifResultNull.getThenPart().addToStatements(isInverse); OJIfStatement ifRuntimeNull = new OJIfStatement("runtimeProperty != null"); ifResultNull.getThenPart().addToStatements(ifRuntimeNull); ifRuntimeNull.getThenPart().addToStatements(ojSwitchStatement); for (Property p : UmlgClassOperations.getAllOwnedProperties(clazz)) { PropertyWrapper pWrap = new PropertyWrapper(p);
public OJIfStatement(String condition, String thenPart) { super(); this.setThenPart(new OJBlock()); this.setCondition(condition); this.addToThenPart(thenPart); }
public String toJavaString() { StringBuilder sb = new StringBuilder(); if(!getComment().equals("")){ addJavaDocComment(sb); } String result = sb.toString(); result += "if ( " + getCondition() + " ) {\n"; result = result + JavaStringHelpers.indent(getThenPart().toJavaString(), 1) + "\n}"; int count = 0; for (OJBlock elseIf : this.elseIfPart) { result = result + " else if ( " + this.elseIfCondition.get(count) + " ) {\n" + JavaStringHelpers.indent(elseIf.toJavaString(), 1) + "\n}"; count++; } if (getElsePart() != null) { result = result + " else {\n" + JavaStringHelpers.indent(getElsePart().toJavaString(), 1) + "\n}"; } return result; }
annotatedClass.addToImports(pWrap.javaTumlMemoryTypePath()); annotatedClass.addToImports(new OJPathName("java.util.Collection")); OJIfStatement ifInMap = new OJIfStatement("propertyMap.containsKey(\"" + pWrap.fieldname() + "\")"); fromJson.getBody().addToStatements(ifInMap); OJIfStatement ifNotNull = new OJIfStatement("propertyMap.get(\"" + pWrap.fieldname() + "\") != null"); ifInMap.addToThenPart(ifNotNull); ifNotNull.getThenPart().addToLocals(field); ifNotNull.addToThenPart(pWrap.clearer() + "()"); OJForStatement ojForStatement = new OJForStatement("row", new OJPathName("Map<String,Integer>"), pWrap.fieldname() + "Map"); ifNotNull.addToThenPart(ojForStatement); OJSimpleStatement ojSimpleStatementConstructor = new OJSimpleStatement(pWrap.javaBaseTypePath().getLast() + " " + pWrap.fieldname() + " = " + UmlgGenerationUtil.UMLGAccess + "." + UmlgGenerationUtil.getEntity + "(row.get(\"id\"))");
/** Copies all attributes and associations of this instance into 'copy'. True parts, i.e. associations marked 'aggregate' or 'composite', and attributes, are copied as well. References to other objects, i.e. associations not marked 'aggregate' or 'composite', will not be copied. The 'copy' will refer to the same objects as the original (this) instance. * * @param copy */ public void copyInfoInto(OJIfStatement copy) { super.copyInfoInto(copy); copy.setCondition(getCondition()); if ( getThenPart() != null ) { copy.setThenPart(getThenPart()); } if ( getElsePart() != null ) { copy.setElsePart(getElsePart()); } }
OJIfStatement ifConstraintFails = new OJIfStatement(); ifConstraintFails.setCondition("!violation" + c.getName() + ".isEmpty()"); ifConstraintFails.getThenPart().addToStatements("iter.remove()"); ojWhileStatement.getBody().addToStatements(ifConstraintFails);
/** Returns a copy of this instance. True parts, i.e. associations marked 'aggregate' or 'composite', and attributes, are copied as well. References to other objects, i.e. associations not marked 'aggregate' or 'composite', will not be copied. The returned copy will refer to the same objects as the original (this) instance. */ public OJElement getCopy() { OJIfStatement result = new OJIfStatement(); this.copyInfoInto(result); return result; }