|
|
|
@ -22,16 +22,22 @@ public class TreeGenerator extends Generator {
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(TreeGenerator.class);
|
|
|
|
|
|
|
|
|
|
public static final String IS_MODEL_FILENAME = "is-model.rst";
|
|
|
|
|
public static final String PROPERTIES_FILENAME = "properties.rst";
|
|
|
|
|
public static final String ENTITIES_FILENAME = "entities.rst";
|
|
|
|
|
public static final String RELATIONS_FILENAME = "relations.rst";
|
|
|
|
|
public static final String EXTENSION = ".rst";
|
|
|
|
|
|
|
|
|
|
protected RegistrationProvider rp;
|
|
|
|
|
|
|
|
|
|
protected boolean splittedFiles;
|
|
|
|
|
|
|
|
|
|
public TreeGenerator(RegistrationProvider rp) {
|
|
|
|
|
super();
|
|
|
|
|
this.rp = rp;
|
|
|
|
|
this.splittedFiles = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSplittedFiles(boolean splittedFiles) {
|
|
|
|
|
if(rp instanceof ISModelRegistrationProvider && splittedFiles) {
|
|
|
|
|
throw new RuntimeException(rp.getModelName() + " documentation can be only produced in a single file");
|
|
|
|
|
}
|
|
|
|
|
this.splittedFiles = splittedFiles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void elaborateTree(final AccessType at, Tree<Class<Element>> tree, File file, RegistrationProvider rp) throws Exception {
|
|
|
|
@ -66,45 +72,58 @@ public class TreeGenerator extends Generator {
|
|
|
|
|
tree.elaborate(documentationNE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected String getFileName(AccessType accessType) {
|
|
|
|
|
String modelName = rp.getModelName();
|
|
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
|
stringBuffer.append(modelName.toLowerCase().replaceAll(" ", "_"));
|
|
|
|
|
if(accessType!=null && splittedFiles) {
|
|
|
|
|
stringBuffer.append("_");
|
|
|
|
|
stringBuffer.append(accessType.getName().toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
stringBuffer.append(EXTENSION);
|
|
|
|
|
return stringBuffer.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void generate() throws Exception {
|
|
|
|
|
|
|
|
|
|
modelKnowledge.addRegistrationProvider(rp);
|
|
|
|
|
modelKnowledge.createKnowledge();
|
|
|
|
|
|
|
|
|
|
File is = getFile(IS_MODEL_FILENAME, true);
|
|
|
|
|
File file = null;
|
|
|
|
|
|
|
|
|
|
if(!splittedFiles) {
|
|
|
|
|
file = getFile(getFileName(null), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(AccessType at : AccessType.getModelTypes()) {
|
|
|
|
|
|
|
|
|
|
if(splittedFiles) {
|
|
|
|
|
file = getFile(getFileName(at), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (at) {
|
|
|
|
|
case PROPERTY:
|
|
|
|
|
file = getFile(PROPERTIES_FILENAME, true);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RESOURCE:
|
|
|
|
|
file = getFile(ENTITIES_FILENAME, true);
|
|
|
|
|
Type type = TypeMapper.createTypeDefinition(AccessType.ENTITY.getTypeClass());
|
|
|
|
|
writeTypeToFile(type, is);
|
|
|
|
|
if(rp instanceof ISModelRegistrationProvider) {
|
|
|
|
|
Type type = TypeMapper.createTypeDefinition(AccessType.ENTITY.getTypeClass());
|
|
|
|
|
writeTypeToFile(type, file);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IS_RELATED_TO:
|
|
|
|
|
file = getFile(RELATIONS_FILENAME, true);
|
|
|
|
|
type = TypeMapper.createTypeDefinition(AccessType.RELATION.getTypeClass());
|
|
|
|
|
writeTypeToFile(type, is);
|
|
|
|
|
if(rp instanceof ISModelRegistrationProvider) {
|
|
|
|
|
Type type = TypeMapper.createTypeDefinition(AccessType.RELATION.getTypeClass());
|
|
|
|
|
writeTypeToFile(type, file);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Type type = TypeMapper.createTypeDefinition(at.getTypeClass());
|
|
|
|
|
writeTypeToFile(type, is);
|
|
|
|
|
|
|
|
|
|
Tree<Class<Element>> tree = modelKnowledge.getClassesTree(at);
|
|
|
|
|
|
|
|
|
|
if(!(rp instanceof ISModelRegistrationProvider)) {
|
|
|
|
|
elaborateTree(at, tree, file, rp);
|
|
|
|
|
}
|
|
|
|
|
elaborateTree(at, tree, file, rp);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|