use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.
the class ModuleAssemblyImpl method assembleModule.
ModuleModel assembleModule(AssemblyHelper helper) throws AssemblyException {
List<TransientModel> transientModels = new ArrayList<>();
List<ObjectModel> objectModels = new ArrayList<>();
List<ValueModel> valueModels = new ArrayList<>();
List<ServiceModel> serviceModels = new ArrayList<>();
List<ImportedServiceModel> importedServiceModels = new ArrayList<>();
if (name == null) {
throw new AssemblyException("Module must have name set");
}
for (TransientAssemblyImpl compositeDeclaration : transientAssemblies.values()) {
transientModels.add(compositeDeclaration.newTransientModel(metaInfoDeclaration, helper));
}
for (ValueAssemblyImpl valueDeclaration : valueAssemblies.values()) {
valueModels.add(valueDeclaration.newValueModel(metaInfoDeclaration, helper));
}
List<EntityModel> entityModels = new ArrayList<>();
for (EntityAssemblyImpl entityDeclaration : entityAssemblies.values()) {
entityModels.add(entityDeclaration.newEntityModel(metaInfoDeclaration, metaInfoDeclaration, metaInfoDeclaration, metaInfoDeclaration, helper));
}
for (ObjectAssemblyImpl objectDeclaration : objectAssemblies.values()) {
objectDeclaration.addObjectModel(objectModels);
}
for (ServiceAssemblyImpl serviceDeclaration : serviceAssemblies) {
if (serviceDeclaration.identity == null) {
serviceDeclaration.identity = generateId(serviceDeclaration.types());
}
serviceModels.add(serviceDeclaration.newServiceModel(metaInfoDeclaration, helper));
}
for (ImportedServiceAssemblyImpl importedServiceDeclaration : importedServiceAssemblies.values()) {
importedServiceDeclaration.addImportedServiceModel(importedServiceModels);
}
ModuleModel moduleModel = new ModuleModel(name, metaInfo, new ActivatorsModel<>(activators), new TransientsModel(transientModels), new EntitiesModel(entityModels), new ObjectsModel(objectModels), new ValuesModel(valueModels), new ServicesModel(serviceModels), new ImportedServicesModel(importedServiceModels));
// Check for duplicate service identities
Set<String> identities = new HashSet<>();
for (ServiceModel serviceModel : serviceModels) {
String identity = serviceModel.identity();
if (identities.contains(identity)) {
throw new DuplicateServiceIdentityException("Duplicated service identity: " + identity + " in module " + moduleModel.name());
}
identities.add(identity);
}
for (ImportedServiceModel serviceModel : importedServiceModels) {
String identity = serviceModel.identity();
if (identities.contains(identity)) {
throw new DuplicateServiceIdentityException("Duplicated service identity: " + identity + " in module " + moduleModel.name());
}
identities.add(identity);
}
for (ImportedServiceModel importedServiceModel : importedServiceModels) {
boolean found = false;
for (ObjectModel objectModel : objectModels) {
if (first(objectModel.types()).equals(importedServiceModel.serviceImporter())) {
found = true;
break;
}
}
if (!found) {
@SuppressWarnings("raw") Class<? extends ServiceImporter> serviceFactoryType = importedServiceModel.serviceImporter();
ObjectModel objectModel = new ObjectModel(serviceFactoryType, Visibility.module, new MetaInfo());
objectModels.add(objectModel);
}
}
return moduleModel;
}
use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.
the class ApplicationModel method newInstance.
@Override
public ApplicationInstance newInstance(Qi4j runtime, Object... importedServiceInstances) throws InvalidApplicationException {
MetaInfo instanceMetaInfo = new MetaInfo(metaInfo);
for (Object importedServiceInstance : importedServiceInstances) {
instanceMetaInfo.set(importedServiceInstance);
}
ApplicationInstance applicationInstance = new ApplicationInstance(this, (Qi4jRuntime) runtime, instanceMetaInfo);
// Create layer instances
Map<LayerModel, LayerInstance> layerInstanceMap = new HashMap<>();
Map<LayerModel, List<LayerInstance>> usedLayers = new HashMap<>();
for (LayerModel layer : layers) {
List<LayerInstance> usedLayerInstances = new ArrayList<>();
usedLayers.put(layer, usedLayerInstances);
UsedLayersInstance usedLayersInstance = layer.usedLayers().newInstance(usedLayerInstances);
LayerInstance layerInstance = layer.newInstance(applicationInstance, usedLayersInstance);
applicationInstance.addLayer(layerInstance);
layerInstanceMap.put(layer, layerInstance);
}
// Resolve used layer instances
for (LayerModel layer : layers) {
List<LayerInstance> usedLayerInstances = usedLayers.get(layer);
for (LayerModel usedLayer : layer.usedLayers().layers()) {
LayerInstance layerInstance = layerInstanceMap.get(usedLayer);
if (layerInstance == null) {
throw new InvalidApplicationException("Could not find used layer:" + usedLayer.name());
}
usedLayerInstances.add(layerInstance);
}
}
return applicationInstance;
}
use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.
the class ValueAssemblyImpl method newAssociationModel.
public AssociationModel newAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
boolean optional = first(filter(isType(Optional.class), annotations)) != null;
// Constraints for Association references
ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericAssociationInfo.associationTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance valueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
valueConstraintsInstance = valueConstraintsModel.newInstance();
}
// Constraints for the Association itself
valueConstraintsModel = constraintsFor(annotations, Association.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance associationValueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
associationValueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
AssociationModel associationModel = new AssociationModel(accessor, valueConstraintsInstance, associationValueConstraintsInstance, metaInfo);
return associationModel;
}
use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.
the class ValueAssemblyImpl method newNamedAssociationModel.
public NamedAssociationModel newNamedAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
boolean optional = first(filter(isType(Optional.class), annotations)) != null;
// Constraints for entities in NamedAssociation
ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericAssociationInfo.associationTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance valueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
valueConstraintsInstance = valueConstraintsModel.newInstance();
}
// Constraints for the NamedAssociation itself
valueConstraintsModel = constraintsFor(annotations, NamedAssociation.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance namedValueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
namedValueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
NamedAssociationModel associationModel = new NamedAssociationModel(accessor, valueConstraintsInstance, namedValueConstraintsInstance, metaInfo);
return associationModel;
}
use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.
the class ValueAssemblyImpl method newPropertyModel.
@Override
protected PropertyModel newPropertyModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
boolean optional = first(filter(isType(Optional.class), annotations)) != null;
ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericPropertyInfo.propertyTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance valueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
valueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
boolean useDefaults = metaInfo.get(UseDefaults.class) != null || stateDeclarations.useDefaults(accessor);
Object initialValue = stateDeclarations.initialValueOf(accessor);
return new PropertyModel(accessor, true, useDefaults, valueConstraintsInstance, metaInfo, initialValue);
}
Aggregations