
org.nuiton.topia.templates.ObserveEntityTransformer Maven / Gradle / Ivy
package org.nuiton.topia.templates;
/*
* #%L
* ObServe Toolkit :: ToPIA Templates Extension
* %%
* Copyright (C) 2008 - 2017 IRD, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.nuiton.eugene.java.JavaGeneratorUtil;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
import org.nuiton.eugene.models.object.ObjectModelPackage;
import org.nuiton.topia.persistence.TopiaEntity;
/**
* A template to generate all the {@link TopiaEntity} api for all classifier
* with a {@code entity} stereotype.
*
* For example, given a {@code House} entity, it will generates :
*
* - {@code House} : contract of entity
* - {@code AbstractHouse} : default abstract implementation of entity
* - {@code HouseImpl} : default impl of abstract entity
*
*
* Note: The impl will ony be generated in these cases :
*
* - There is no abstract method
* - There is no already defined such class in class-path
*
*
* @author Tony Chemit - [email protected]
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.templates.ObserveEntityTransformer"
* @since 2.3.4
*/
public class ObserveEntityTransformer extends EntityTransformer {
/**
* Generate properties from {@code attributes}. Generate
* constant, attribute and operations for each property.
*
* @param attributes Input attributes
* @param aClass FIXME
* @param aPackage FIXME
*/
protected void generateProperties(Collection attributes, ObjectModelClassifier aClass, ObjectModelPackage aPackage) {
if (!((ObjectModelClass) aClass).isAbstract()) {
List navigableAttributes = attributes.stream().filter(ObjectModelAttribute::isNavigable).collect(Collectors.toList());
addGettersMethod(outputAbstract, outputInterface.getName(), navigableAttributes, true, true);
addSettersMethod(outputAbstract, outputInterface.getName(), navigableAttributes, true, true, e -> {
String attrType = getPropertyType(e, aClass, aPackage);
addImport(outputAbstract, attrType);
attrType = JavaGeneratorUtil.getSimpleName(attrType);
String collectionType = getCollectionType(e);
if (collectionType != null) {
addImport(outputAbstract, collectionType);
attrType = JavaGeneratorUtil.getSimpleName(collectionType) + "<" + attrType + ">";
}
return attrType;
});
}
super.generateProperties(attributes, aClass, aPackage);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy