use of org.qi4j.api.structure.ModuleDescriptor in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method constructApplicationInfo.
private ApplicationInfo constructApplicationInfo(Boolean setQNameTableNameToNull) throws SQLException {
final ApplicationInfo appInfo = new ApplicationInfo();
final List<CompositeDescriptorInfo> valueDescriptors = new ArrayList<>();
final Deque<Object> currentPath = new ArrayDeque<>();
_app.descriptor().accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {
@Override
public boolean visitEnter(Object visited) throws RuntimeException {
if (visited instanceof LayerDescriptor || visited instanceof ModuleDescriptor) {
currentPath.push(visited);
}
if (visited instanceof EntityDescriptor || visited instanceof ValueDescriptor) {
// TODO filter non-visible descriptors away.
if (visited instanceof EntityDescriptor) {
EntityDescriptor entityDescriptor = (EntityDescriptor) visited;
if (entityDescriptor.queryable()) {
LOGGER.debug("THIS ONE WORKS: {}", entityDescriptor);
appInfo.entityDescriptors.put(first(entityDescriptor.types()).getName(), entityDescriptor);
}
} else {
valueDescriptors.add(new CompositeDescriptorInfo((LayerDescriptor) Iterables.first(Iterables.skip(1, currentPath)), (ModuleDescriptor) Iterables.first(currentPath), (CompositeDescriptor) visited));
}
return false;
}
return true;
}
@Override
public boolean visitLeave(Object visited) {
if (visited instanceof LayerDescriptor || visited instanceof ModuleDescriptor) {
currentPath.pop();
}
return true;
}
});
for (EntityDescriptor descriptor : appInfo.entityDescriptors.values()) {
Set<QualifiedName> newQNames = new HashSet<>();
this.extractPropertyQNames(descriptor, this._state.qNameInfos().get(), newQNames, valueDescriptors, appInfo.enumValues, setQNameTableNameToNull);
this.extractAssociationQNames(descriptor, this._state.qNameInfos().get(), newQNames, setQNameTableNameToNull);
this.extractManyAssociationQNames(descriptor, this._state.qNameInfos().get(), newQNames, setQNameTableNameToNull);
this._state.entityUsedQNames().get().put(descriptor, newQNames);
}
appInfo.usedValueComposites.addAll(valueDescriptors);
return appInfo;
}
use of org.qi4j.api.structure.ModuleDescriptor in project qi4j-sdk by Qi4j.
the class ApplicationVisitor method visitEnter.
@Override
public boolean visitEnter(Object visited) throws RuntimeException {
if (visited instanceof ApplicationDescriptor) {
ApplicationDescriptor applicationDescriptor = (ApplicationDescriptor) visited;
appUri = context.createApplicationUri(applicationDescriptor.name());
context.setNameAndType(appUri, applicationDescriptor.name(), Qi4jRdf.TYPE_APPLICATION);
}
if (visited instanceof LayerDescriptor) {
LayerDescriptor layerDescriptor = (LayerDescriptor) visited;
layerUri = context.createLayerUri(appUri, layerDescriptor.name());
context.setNameAndType(layerUri, layerDescriptor.name(), Qi4jRdf.TYPE_LAYER);
context.addRelationship(appUri, Qi4jRdf.RELATIONSHIP_LAYER, layerUri);
}
if (visited instanceof ModuleDescriptor) {
ModuleDescriptor moduleDescriptor = (ModuleDescriptor) visited;
moduleUri = context.createModuleUri(layerUri, moduleDescriptor.name());
context.setNameAndType(layerUri, moduleDescriptor.name(), Qi4jRdf.TYPE_MODULE);
context.addRelationship(layerUri, Qi4jRdf.RELATIONSHIP_MODULE, moduleUri);
}
if (visited instanceof TransientDescriptor) {
TransientDescriptor transientDescriptor = (TransientDescriptor) visited;
compositeUri = context.createCompositeUri(moduleUri, first(transientDescriptor.types()));
context.addType(compositeUri, Qi4jRdf.TYPE_COMPOSITE);
context.addRelationship(moduleUri, Qi4jRdf.RELATIONSHIP_COMPOSITE, compositeUri);
}
if (visited instanceof EntityDescriptor) {
EntityDescriptor entityDescriptor = (EntityDescriptor) visited;
compositeUri = context.createCompositeUri(moduleUri, first(entityDescriptor.types()));
context.addType(compositeUri, Qi4jRdf.TYPE_ENTITY);
context.addRelationship(moduleUri, Qi4jRdf.RELATIONSHIP_ENTITY, compositeUri);
}
if (visited instanceof ObjectDescriptor) {
ObjectDescriptor objectDescriptor = (ObjectDescriptor) visited;
compositeUri = context.createCompositeUri(moduleUri, first(objectDescriptor.types()));
context.addType(compositeUri, Qi4jRdf.TYPE_OBJECT);
context.addRelationship(moduleUri, Qi4jRdf.RELATIONSHIP_OBJECT, compositeUri);
}
if (visited instanceof MethodDescriptor) {
MethodDescriptor compositeMethodDescriptor = (MethodDescriptor) visited;
String compositeMethodUri = context.createCompositeMethodUri(compositeUri, compositeMethodDescriptor.method());
context.addType(compositeMethodUri, Qi4jRdf.TYPE_METHOD);
context.addRelationship(compositeUri, Qi4jRdf.RELATIONSHIP_METHOD, compositeMethodUri);
}
return true;
}
use of org.qi4j.api.structure.ModuleDescriptor in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method stringToCompositeDescriptor.
protected static <TCompositeDescriptor extends CompositeDescriptor> TCompositeDescriptor stringToCompositeDescriptor(final Class<TCompositeDescriptor> descriptorClass, ApplicationDescriptor appDesc, String str) {
Matcher matcher = DESCRIPTOR_TEXTUAL_REGEXP.matcher(str);
if (!matcher.matches()) {
throw new IllegalArgumentException("Descriptor textual description " + str + " was invalid.");
}
final String layerName = matcher.group(1);
final String moduleName = matcher.group(2);
final Set<String> classNames = new HashSet<>();
Matcher typesMatcher = DESCRIPTOR_TYPES_REGEXP.matcher(matcher.group(3));
while (typesMatcher.find()) {
classNames.add(typesMatcher.group(0));
}
final CompositeDescriptor[] result = new CompositeDescriptor[1];
appDesc.accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {
@Override
public boolean visitEnter(Object visited) {
boolean thisResult = true;
if (visited instanceof LayerDescriptor) {
thisResult = ((LayerDescriptor) visited).name().equals(layerName);
} else if (visited instanceof ModuleDescriptor) {
thisResult = ((ModuleDescriptor) visited).name().equals(moduleName);
} else if (descriptorClass.isAssignableFrom(visited.getClass())) {
CompositeDescriptor desc = (CompositeDescriptor) visited;
if (classNames.equals(new HashSet<>(Iterables.toList(Iterables.map(new Function<Class<?>, String>() {
@Override
public String map(Class<?> from) {
return from.getName();
}
}, desc.types()))))) {
result[0] = desc;
thisResult = false;
}
}
return thisResult;
}
@Override
public boolean visitLeave(Object visited) {
return result[0] == null;
}
});
return (TCompositeDescriptor) result[0];
}
use of org.qi4j.api.structure.ModuleDescriptor in project qi4j-sdk by Qi4j.
the class Model2XML method map.
@Override
public Document map(ApplicationDescriptor Application) {
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
final Document document = builder.newDocument();
final Stack<Node> current = new Stack<Node>();
current.push(document);
Application.accept(new HierarchicalVisitor<Object, Object, DOMException>() {
@Override
public boolean visitEnter(Object visited) throws DOMException {
String mapping = simpleMappings.get(visited.getClass().getSimpleName());
if (mapping != null) {
Node node = document.createElement("mapping");
current.push(node);
} else if (visited instanceof ApplicationDescriptor) {
ApplicationDescriptor applicationDescriptor = (ApplicationDescriptor) visited;
Node application = document.createElement("application");
addAttribute("name", applicationDescriptor.name(), application);
current.push(application);
} else if (visited instanceof LayerDescriptor) {
LayerDescriptor layerDescriptor = (LayerDescriptor) visited;
Node layer = document.createElement("layer");
addAttribute("name", layerDescriptor.name(), layer);
current.push(layer);
} else if (visited instanceof ModuleDescriptor) {
ModuleDescriptor moduleDescriptor = (ModuleDescriptor) visited;
Node module = document.createElement("module");
addAttribute("name", moduleDescriptor.name(), module);
current.push(module);
} else if (visited instanceof TransientDescriptor) {
TransientDescriptor descriptor = (TransientDescriptor) visited;
Node node = document.createElement("transient");
addAttribute("type", first(descriptor.types()).getName(), node);
addAttribute("visibility", descriptor.visibility().name(), node);
current.push(node);
} else if (visited instanceof MethodDescriptor) {
MethodDescriptor descriptor = (MethodDescriptor) visited;
Node node = document.createElement("method");
addAttribute("name", descriptor.method().getName(), node);
current.push(node);
} else if (visited instanceof MixinDescriptor) {
MixinDescriptor descriptor = (MixinDescriptor) visited;
Node node = document.createElement("mixin");
addAttribute("class", descriptor.mixinClass().getName(), node);
current.push(node);
} else if (visited instanceof DependencyDescriptor) {
DependencyDescriptor descriptor = (DependencyDescriptor) visited;
Node node = document.createElement("dependency");
addAttribute("annotation", descriptor.injectionAnnotation().toString(), node);
addAttribute("injection", descriptor.injectionType().toString(), node);
addAttribute("optional", Boolean.toString(descriptor.optional()), node);
current.push(node);
} else {
Element element = document.createElement(visited.getClass().getSimpleName());
current.push(element);
}
return true;
}
@Override
public boolean visitLeave(Object visited) throws DOMException {
Node node = current.pop();
if (node.getChildNodes().getLength() == 0 && node.getAttributes().getLength() == 0) {
return true;
}
current.peek().appendChild(node);
return true;
}
@Override
public boolean visit(Object visited) throws DOMException {
Element element;
if (visited instanceof DependencyDescriptor) {
DependencyDescriptor descriptor = (DependencyDescriptor) visited;
element = document.createElement("dependency");
addAttribute("annotation", descriptor.injectionAnnotation().toString(), element);
addAttribute("injection", descriptor.injectionType().toString(), element);
addAttribute("optional", Boolean.toString(descriptor.optional()), element);
} else {
element = document.createElement(visited.getClass().getSimpleName());
}
current.peek().appendChild(element);
return true;
}
private void addAttribute(String name, String value, Node node) {
Attr attr = document.createAttribute(name);
attr.setValue(value);
((Element) node).setAttributeNode(attr);
}
});
return document;
} catch (Exception exception) {
throw new IllegalArgumentException(exception);
}
}
Aggregations