All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joinedworkz.common.java.DtoCartridge Maven / Gradle / Ivy

There is a newer version: 1.3.46
Show newest version
package org.joinedworkz.common.java;

import java.util.List;
import java.util.Properties;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.xtext.xbase.lib.Extension;
import org.joinedworkz.common.helper.CmnModelHelper;
import org.joinedworkz.common.java.generator.DtoClassGenerator;
import org.joinedworkz.common.java.generator.EnumerationClassGenerator;
import org.joinedworkz.core.facility.AbstractCartridge;
import org.joinedworkz.core.facility.Outlet;
import org.joinedworkz.core.facility.Outlets;
import org.joinedworkz.core.model.CmnEnumeration;
import org.joinedworkz.core.model.CmnFieldContainer;
import org.joinedworkz.core.model.CmnModel;
import org.joinedworkz.core.model.CmnObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Singleton
@SuppressWarnings("all")
public class DtoCartridge extends AbstractCartridge {
  private static final Logger log = LoggerFactory.getLogger(DtoCartridge.class);

  @Inject
  @Extension
  protected CmnModelHelper cmnModelHelper;

  @Inject
  protected DtoClassGenerator dtoClassGenerator;

  @Inject
  protected EnumerationClassGenerator enumerationClassGenerator;

  @Override
  public void apply(final CmnObject cmnObj, final Outlets outlets) {
    this.apply(cmnObj, outlets, null);
  }

  @Override
  public void apply(final CmnObject obj, final Outlets outlets, final Properties joinedWorkzProperties) {
    final Outlet generatedJavaSourceSlot = outlets.get("generatedJavaSource");
    if ((obj instanceof CmnModel)) {
      DtoCartridge.log.info("Invoke generator \'{}\' on model \'{}\'", this.dtoClassGenerator.getClass().getCanonicalName(), ((CmnModel)obj).getNamespace());
      List _modelElements = ((CmnModel)obj).getModelElements();
      for (final CmnObject modelElement : _modelElements) {
        this.generateModelElement(modelElement, generatedJavaSourceSlot, joinedWorkzProperties);
      }
    }
  }

  public void generateModelElement(final CmnObject obj, final Outlet outlet, final Properties joinedWorkzProperties) {
    boolean _isDtoObject = this.cmnModelHelper.isDtoObject(obj);
    if (_isDtoObject) {
      this.dtoClassGenerator.generateClass(this.createGeneratorContext(((CmnFieldContainer) obj), outlet, joinedWorkzProperties));
    } else {
      if ((obj instanceof CmnEnumeration)) {
        this.enumerationClassGenerator.generateClass(this.createGeneratorContext(((CmnEnumeration)obj), outlet, joinedWorkzProperties));
      }
    }
  }

  public  ClassGeneratorContext createGeneratorContext(final T classObject, final Outlet outlet, final Properties joinedWorkzProperties) {
    return new ClassGeneratorContext(classObject, outlet, joinedWorkzProperties);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy