use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class FieldAnnotationValueChangeCommand method execute.
@Override
public void execute() {
Object oldValue = null;
Annotation annotation = field.getAnnotation(annotationClassName);
if (annotation != null) {
oldValue = annotation.getValue(valuePair);
if (newValue != null && !newValue.equals(oldValue)) {
// notify annotation value change
annotation.setValue(valuePair, newValue);
notifyFieldChange(ChangeType.FIELD_ANNOTATION_VALUE_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
} else if (newValue == null) {
if (removeAnnotationIfValueIsNull) {
field.removeAnnotation(annotationClassName);
// notify annotation removed
notifyFieldChange(ChangeType.FIELD_ANNOTATION_REMOVE_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
} else {
// annotations do not support nulls for the value paris, so just remove the value pair.
annotation.removeValue(valuePair);
// notify annotation value change
notifyFieldChange(ChangeType.FIELD_ANNOTATION_VALUE_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
}
}
} else if (newValue != null) {
annotation = new AnnotationImpl(context.getAnnotationDefinitions().get(annotationClassName));
annotation.setValue(valuePair, newValue);
field.addAnnotation(annotation);
// notify annotation added
notifyFieldChange(ChangeType.FIELD_ANNOTATION_ADD_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
}
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class AddPropertyCommand method execute.
@Override
public void execute() {
// extra check
boolean multiple = isMultiple && !getContext().getHelper().isPrimitiveType(propertyType);
property = new ObjectPropertyImpl(propertyName, propertyType, multiple);
if (propertyLabel != null && !"".equals(propertyLabel)) {
Annotation annotation = new AnnotationImpl(getContext().getAnnotationDefinitions().get(MainDomainAnnotations.LABEL_ANNOTATION));
annotation.setValue(MainDomainAnnotations.VALUE_PARAM, propertyLabel);
property.addAnnotation(annotation);
}
dataObject.addProperty(property);
if (!property.isBaseType()) {
getContext().getHelper().dataObjectReferenced(property.getClassName(), dataObject.getClassName());
}
notifyChange(new DataObjectFieldCreatedEvent(getContext().getContextId(), getSource(), getDataObject(), property));
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class DataObjectAddAnnotationCommand method execute.
@Override
public void execute() {
if (annotation == null) {
annotation = new AnnotationImpl(context.getAnnotationDefinition(annotationClassName));
if (valuePairs != null) {
for (ValuePair valuePair : valuePairs) {
annotation.setValue(valuePair.getName(), valuePair.getValue());
}
}
}
dataObject.addAnnotation(annotation);
notifyObjectChange(ChangeType.TYPE_ANNOTATION_ADD_CHANGE, context, source, dataObject, annotation.getClassName(), null, null, null);
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class DataObjectAddOrRemoveAnnotationCommand method execute.
@Override
public void execute() {
if (doAdd && dataObject.getAnnotation(annotationClassName) == null) {
dataObject.addAnnotation(new AnnotationImpl(context.getAnnotationDefinition(annotationClassName)));
notifyObjectChange(ChangeType.TYPE_ANNOTATION_ADD_CHANGE, context, source, dataObject, annotationClassName, null, null, null);
} else if (!doAdd && dataObject.getAnnotation(annotationClassName) != null) {
dataObject.removeAnnotation(annotationClassName);
notifyObjectChange(ChangeType.TYPE_ANNOTATION_REMOVE_CHANGE, context, source, dataObject, annotationClassName, null, null, null);
}
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class GenerationEngineTest method testJavaClassStringGeneration.
@Test
public void testJavaClassStringGeneration() {
DataModel dataModel = dataModelOracleDriver.createModel();
DataObject object1 = dataModel.addDataObject("com.test.Object1");
DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
Annotation label = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Label.class.getName()));
label.setValue("value", "Object1 Label");
object1.addAnnotation(label);
Annotation classReactive = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.ClassReactive.class.getName()));
object1.addAnnotation(classReactive);
Annotation propReactive = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.PropertyReactive.class.getName()));
object1.addAnnotation(propReactive);
Annotation role = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Role.class.getName()));
role.setValue("value", org.kie.api.definition.type.Role.Type.EVENT.name());
object1.addAnnotation(role);
ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
ObjectProperty prop2 = object1.addProperty("attribute2", "java.lang.Boolean");
ObjectProperty prop3 = object1.addProperty("attribute3", object2.getClassName());
ObjectProperty prop4 = object1.addProperty("attribute4", "long");
Annotation key = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Key.class.getName()));
Annotation position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "0");
prop4.addAnnotation(key);
prop4.addAnnotation(position);
position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "1");
prop1.addAnnotation(key);
prop1.addAnnotation(position);
position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "2");
prop2.addAnnotation(key);
prop2.addAnnotation(position);
position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "3");
prop3.addAnnotation(position);
GenerationContext generationContext = new GenerationContext(dataModel);
try {
String result = engine.generateJavaClassString(generationContext, object1);
logger.debug(result);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations