Refactoring
This commit is contained in:
parent
446adc09a1
commit
484690555a
|
@ -35,9 +35,4 @@ public class ClassInformation implements NodeInformation<Class<Element>> {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extraElaboration(Class<Element> t) {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,22 +8,28 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.discovery.ClassInformation;
|
||||
import org.gcube.informationsystem.discovery.Discovery;
|
||||
import org.gcube.informationsystem.discovery.RegistrationProvider;
|
||||
import org.gcube.informationsystem.serialization.ElementMappingAction;
|
||||
import org.gcube.informationsystem.tree.AddElementToTreeAction;
|
||||
import org.gcube.informationsystem.tree.Tree;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ModelKnowledge {
|
||||
|
||||
|
||||
public static ModelKnowledge getInstance() {
|
||||
return new ModelKnowledge();
|
||||
}
|
||||
|
||||
protected Map<AccessType, Tree<Class<Element>>> trees;
|
||||
|
||||
protected Map<AccessType, Tree<Type>> typesTree;
|
||||
protected Map<AccessType, Discovery<? extends Element>> discoveries;
|
||||
|
||||
public ModelKnowledge() {
|
||||
protected ModelKnowledge() {
|
||||
this.trees = new HashMap<>();
|
||||
this.discoveries = new HashMap<>();
|
||||
}
|
||||
|
@ -39,13 +45,18 @@ public class ModelKnowledge {
|
|||
allPackages.addAll(rp.getPackagesToRegister());
|
||||
}
|
||||
|
||||
ClassInformation classInformation = new ClassInformation();
|
||||
|
||||
for(AccessType accessType : modelTypes) {
|
||||
Class<Element> clz = accessType.getTypeClass();
|
||||
|
||||
Tree<Class<Element>> tree = new Tree<>(clz, null);
|
||||
Tree<Class<Element>> tree = new Tree<>(clz, classInformation);
|
||||
trees.put(accessType, tree);
|
||||
AddElementToTreeAction aetta = new AddElementToTreeAction(tree);
|
||||
|
||||
|
||||
|
||||
|
||||
Discovery<? extends Element> discovery = new Discovery<>(clz);
|
||||
discoveries.put(accessType, discovery);
|
||||
discovery.addPackages(allPackages);
|
||||
|
|
|
@ -63,19 +63,32 @@ public class Node<T> implements Comparable<Node<T>> {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return createTree(0).toString();
|
||||
return printTree(0).toString();
|
||||
}
|
||||
|
||||
private StringBuffer createTree(int level) {
|
||||
private StringBuffer printTree(int level) {
|
||||
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < level; ++i) {
|
||||
stringBuffer.append(Node.INDENTATION);
|
||||
}
|
||||
stringBuffer.append(tree.getNodeInformation().getIdentifier(t));
|
||||
for (Node<T> child : children) {
|
||||
stringBuffer.append("\n");
|
||||
stringBuffer.append(child.createTree(level+1));
|
||||
|
||||
NodeElaborator<T> nodeElaborator = new NodeElaborator<T>() {
|
||||
|
||||
@Override
|
||||
public void elaborate(Node<T> node, int level) throws Exception {
|
||||
for (int i = 0; i < level; ++i) {
|
||||
stringBuffer.append(Node.INDENTATION);
|
||||
}
|
||||
stringBuffer.append(tree.getNodeInformation().getIdentifier(t));
|
||||
stringBuffer.append("\n");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
try {
|
||||
elaborate(nodeElaborator, level);
|
||||
}catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,17 +8,4 @@ public interface NodeInformation<T> {
|
|||
|
||||
public abstract Set<String> getParentIdentifiers(T root, T t);
|
||||
|
||||
public abstract void extraElaboration(T t);
|
||||
|
||||
|
||||
// protected void createUsageKnowledge(Type type) {
|
||||
// if(type.getAccessType() != AccessType.RESOURCE) {
|
||||
// return;
|
||||
// }
|
||||
// ResourceType rt = (ResourceType) type;
|
||||
// UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
||||
// fk.addAll(rt.getFacets());
|
||||
// UsageKnowledge rk = UsageKnowledge.getResourceKnowledge();
|
||||
// rk.addAll(rt.getResources());
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ public class Tree<T> {
|
|||
}
|
||||
|
||||
this.locate.put(identifier, node);
|
||||
this.ni.extraElaboration(t);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.types.knowledge;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.discovery.DiscoveredElementAction;
|
||||
import org.gcube.informationsystem.tree.Tree;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class AddTypeToTreeAction implements DiscoveredElementAction<Element> {
|
||||
|
||||
protected Tree<Type> tree;
|
||||
|
||||
public AddTypeToTreeAction(Tree<Type> tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void analizeElement(Class<Element> e) throws Exception {
|
||||
Type type = TypeMapper.createTypeDefinition(e);
|
||||
tree.addNode(type);
|
||||
createUsageKnowledge(type);
|
||||
}
|
||||
|
||||
|
||||
protected void createUsageKnowledge(Type type) {
|
||||
if (type.getAccessType() != AccessType.RESOURCE) {
|
||||
return;
|
||||
}
|
||||
ResourceType rt = (ResourceType) type;
|
||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
||||
fk.addAll(rt.getFacets());
|
||||
UsageKnowledge rk = UsageKnowledge.getResourceKnowledge();
|
||||
rk.addAll(rt.getResources());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.types.knowledge.toBeRemoved;
|
||||
package org.gcube.informationsystem.types.knowledge;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
Loading…
Reference in New Issue