net.sf.nakeduml.validation.namegeneration.AbstractPersistentNameGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metamodel Show documentation
Show all versions of metamodel Show documentation
A uml code generator and execution engine
The newest version!
package net.sf.nakeduml.validation.namegeneration;
import net.sf.nakeduml.metamodel.activities.INakedActivityNode;
import net.sf.nakeduml.metamodel.core.INakedAssociation;
import net.sf.nakeduml.metamodel.core.INakedComplexStructure;
import net.sf.nakeduml.metamodel.core.INakedElement;
import net.sf.nakeduml.metamodel.core.INakedEnumerationLiteral;
import net.sf.nakeduml.metamodel.core.INakedTypedElement;
import net.sf.nakeduml.metamodel.core.INakedValueSpecification;
import net.sf.nakeduml.metamodel.name.NameWrapper;
import net.sf.nakeduml.metamodel.name.SingularNameWrapper;
import net.sf.nakeduml.metamodel.statemachines.INakedState;
import net.sf.nakeduml.name.NameConverter;
public abstract class AbstractPersistentNameGenerator extends AbstractNameGenerator {
protected final String generateQualifiedPersistentName(INakedElement nme) {
if (nme instanceof INakedState) {
INakedState state = (INakedState) nme;
if (state.hasEnclosingState()) {
return generateQualifiedPersistentName(state.getEnclosingState()) + "/"
+ state.getMappingInfo().getPersistentName();
} else {
String asIs = state.getMappingInfo().getPersistentName().getAsIs();
return asIs;
}
} else if (nme instanceof INakedActivityNode) {
INakedActivityNode node = (INakedActivityNode) nme;
if (node.getInStructuredNode() != null) {
return generateQualifiedPersistentName(node.getInStructuredNode()) + "/"
+ node.getMappingInfo().getPersistentName();
} else {
return node.getMappingInfo().getPersistentName().getAsIs();
}
} else if (nme.getOwnerElement() instanceof INakedElement) {
INakedElement owner = (INakedElement) nme.getOwnerElement();
return owner.getMappingInfo().getPersistentName().getAsIs() + "."
+ nme.getMappingInfo().getPersistentName().getAsIs();
} else {
return nme.getMappingInfo().getPersistentName().getAsIs();
}
}
protected final NameWrapper generateSqlName(INakedElement nme) {
String generatedName = null;
INakedValueSpecification existingSqlName = getTaggedValue(nme, "persistentName", "persistenceType");
if (existingSqlName != null) {
generatedName = existingSqlName.stringValue();
} else if (nme instanceof INakedAssociation) {
// Name is generated by UmlNameGenerator
INakedAssociation ass = (INakedAssociation) nme;
generatedName = NameConverter.toUnderscoreStyle(ass.getName());
} else if (nme instanceof INakedTypedElement) {
INakedTypedElement tew = (INakedTypedElement) nme;
if (tew.getNakedBaseType() instanceof INakedComplexStructure) {
// foreign key
// TODO re-evaluate the _id thing
generatedName = NameConverter.toUnderscoreStyle(tew.getName()) + "_id";
} else {
generatedName = NameConverter.toUnderscoreStyle(tew.getName());
}
} else if (nme instanceof INakedEnumerationLiteral) {
INakedEnumerationLiteral nakedLiteral = ((INakedEnumerationLiteral) nme);
generatedName = nakedLiteral.getName();
} else {
// TODO actions within StructuredACtivityNodes
generatedName = NameConverter.toUnderscoreStyle(nme.getName());
}
return new SingularNameWrapper(generatedName.toLowerCase(), null);
}
}