@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(); } }
public String generateJavaClassString(GenerationContext generationContext, DataObject dataObject) throws Exception { VelocityContext vc = buildContext(generationContext); vc.put("currentDataObject", dataObject); return generateSubTemplateString(generationContext, "java_class2"); }
GenerationEngine { public String generateJavaClassString(GenerationContext generationContext, DataObject dataObject) throws Exception { VelocityContext vc = buildContext(generationContext); vc.put("currentDataObject", dataObject); return generateSubTemplateString(generationContext, "java_class2"); } }
GenerationEngine { public String generateJavaClassString(GenerationContext generationContext, DataObject dataObject) throws Exception { VelocityContext vc = buildContext(generationContext); vc.put("currentDataObject", dataObject); return generateSubTemplateString(generationContext, "java_class2"); }  }
GenerationEngine { public String generateJavaClassString(GenerationContext generationContext, DataObject dataObject) throws Exception { VelocityContext vc = buildContext(generationContext); vc.put("currentDataObject", dataObject); return generateSubTemplateString(generationContext, "java_class2"); }  static GenerationEngine getInstance(); void generate(GenerationContext generationContext); void generateAsset(GenerationContext generationContext, String template, String filePath); void generateConstructors(GenerationContext generationContext, String template); void generateAttribute(GenerationContext generationContext, ObjectProperty attribute, String template); void generateMethod( GenerationContext generationContext, Method method, String template); void generateNestedClass( GenerationContext generationContext, JavaClass nestedClass, String template); void generateSetterGetter(GenerationContext generationContext, ObjectProperty attribute, String template); void generateEquals(GenerationContext generationContext, String template); void generateHashCode(GenerationContext generationContext, String template); void generateTypeAnnotation(GenerationContext generationContext, Annotation annotation, String template); void generateFieldAnnotation(GenerationContext generationContext, Annotation annotation, String template); void generateSubTemplate(GenerationContext generationContext, String template); String generateDefaultConstructorString(GenerationContext generationContext, DataObject dataObject); String generateAllFieldsConstructorString(GenerationContext generationContext, DataObject dataObject); String generateKeyFieldsConstructorString(GenerationContext generationContext, DataObject dataObject); String generatePositionFieldsConstructorString(GenerationContext generationContext, DataObject dataObject); String generateAnnotationString(GenerationContext generationContext, Annotation annotation); String generateMethodString(GenerationContext generationContext, Method method, String indent); String generateMethodString(GenerationContext generationContext, Method method); String generateNestedClassString(GenerationContext generationContext, JavaClass javaClass, String indent); String generateNestedClassString(GenerationContext generationContext, JavaClass javaClass); String generateFieldString(GenerationContext generationContext, ObjectProperty attribute); String generateFieldGetterString(GenerationContext generationContext, ObjectProperty attribute); String generateFieldSetterString(GenerationContext generationContext, ObjectProperty attribute); String generateEqualsString(GenerationContext generationContext, DataObject dataObject, String indent); String generateEqualsString(GenerationContext generationContext, DataObject dataObject); String generateHashCodeString(GenerationContext generationContext, DataObject dataObject, String indent); String generateHashCodeString(GenerationContext generationContext, DataObject dataObject); String generateAllConstructorsString(GenerationContext generationContext, DataObject dataObject); String generateAllConstructorsString(GenerationContext generationContext, DataObject dataObject, String indent); String generateAllAnnotationsString(GenerationContext generationContext, HasAnnotations hasAnnotations); String generateAllAnnotationsString(GenerationContext generationContext, HasAnnotations hasAnnotations, String indent); String generateCompleteFieldString(GenerationContext generationContext, ObjectProperty attribute); String generateCompleteFieldString(GenerationContext generationContext, ObjectProperty attribute, String indent); String generateFieldGetterSetterString(GenerationContext generationContext, ObjectProperty attribute); String generateFieldGetterSetterString(GenerationContext generationContext, ObjectProperty attribute, String indent); String generateJavaClassString(GenerationContext generationContext, DataObject dataObject); String generateSubTemplateString(GenerationContext generationContext, String template); static String indentLines(String source, String indent); }
GenerationEngine { public String generateJavaClassString(GenerationContext generationContext, DataObject dataObject) throws Exception { VelocityContext vc = buildContext(generationContext); vc.put("currentDataObject", dataObject); return generateSubTemplateString(generationContext, "java_class2"); }  static GenerationEngine getInstance(); void generate(GenerationContext generationContext); void generateAsset(GenerationContext generationContext, String template, String filePath); void generateConstructors(GenerationContext generationContext, String template); void generateAttribute(GenerationContext generationContext, ObjectProperty attribute, String template); void generateMethod( GenerationContext generationContext, Method method, String template); void generateNestedClass( GenerationContext generationContext, JavaClass nestedClass, String template); void generateSetterGetter(GenerationContext generationContext, ObjectProperty attribute, String template); void generateEquals(GenerationContext generationContext, String template); void generateHashCode(GenerationContext generationContext, String template); void generateTypeAnnotation(GenerationContext generationContext, Annotation annotation, String template); void generateFieldAnnotation(GenerationContext generationContext, Annotation annotation, String template); void generateSubTemplate(GenerationContext generationContext, String template); String generateDefaultConstructorString(GenerationContext generationContext, DataObject dataObject); String generateAllFieldsConstructorString(GenerationContext generationContext, DataObject dataObject); String generateKeyFieldsConstructorString(GenerationContext generationContext, DataObject dataObject); String generatePositionFieldsConstructorString(GenerationContext generationContext, DataObject dataObject); String generateAnnotationString(GenerationContext generationContext, Annotation annotation); String generateMethodString(GenerationContext generationContext, Method method, String indent); String generateMethodString(GenerationContext generationContext, Method method); String generateNestedClassString(GenerationContext generationContext, JavaClass javaClass, String indent); String generateNestedClassString(GenerationContext generationContext, JavaClass javaClass); String generateFieldString(GenerationContext generationContext, ObjectProperty attribute); String generateFieldGetterString(GenerationContext generationContext, ObjectProperty attribute); String generateFieldSetterString(GenerationContext generationContext, ObjectProperty attribute); String generateEqualsString(GenerationContext generationContext, DataObject dataObject, String indent); String generateEqualsString(GenerationContext generationContext, DataObject dataObject); String generateHashCodeString(GenerationContext generationContext, DataObject dataObject, String indent); String generateHashCodeString(GenerationContext generationContext, DataObject dataObject); String generateAllConstructorsString(GenerationContext generationContext, DataObject dataObject); String generateAllConstructorsString(GenerationContext generationContext, DataObject dataObject, String indent); String generateAllAnnotationsString(GenerationContext generationContext, HasAnnotations hasAnnotations); String generateAllAnnotationsString(GenerationContext generationContext, HasAnnotations hasAnnotations, String indent); String generateCompleteFieldString(GenerationContext generationContext, ObjectProperty attribute); String generateCompleteFieldString(GenerationContext generationContext, ObjectProperty attribute, String indent); String generateFieldGetterSetterString(GenerationContext generationContext, ObjectProperty attribute); String generateFieldGetterSetterString(GenerationContext generationContext, ObjectProperty attribute, String indent); String generateJavaClassString(GenerationContext generationContext, DataObject dataObject); String generateSubTemplateString(GenerationContext generationContext, String template); static String indentLines(String source, String indent);  }