Search in sources :

Example 6 with ValueModel

use of org.qi4j.runtime.value.ValueModel in project qi4j-sdk by Qi4j.

the class ModuleAssemblyImpl method assembleModule.

ModuleModel assembleModule(AssemblyHelper helper) throws AssemblyException {
    List<TransientModel> transientModels = new ArrayList<TransientModel>();
    List<ObjectModel> objectModels = new ArrayList<ObjectModel>();
    List<ValueModel> valueModels = new ArrayList<ValueModel>();
    List<ServiceModel> serviceModels = new ArrayList<ServiceModel>();
    List<ImportedServiceModel> importedServiceModels = new ArrayList<ImportedServiceModel>();
    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<EntityModel>();
    for (EntityAssemblyImpl entityDeclaration : entityAssemblies.values()) {
        entityModels.add(entityDeclaration.newEntityModel(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<Module>(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<String>();
    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) {
            Class<? extends ServiceImporter> serviceFactoryType = importedServiceModel.serviceImporter();
            ObjectModel objectModel = new ObjectModel(serviceFactoryType, Visibility.module, new MetaInfo());
            objectModels.add(objectModel);
        }
    }
    return moduleModel;
}
Also used : ObjectModel(org.qi4j.runtime.object.ObjectModel) ValueModel(org.qi4j.runtime.value.ValueModel) ImportedServiceModel(org.qi4j.runtime.service.ImportedServiceModel) ArrayList(java.util.ArrayList) ImportedServicesModel(org.qi4j.runtime.service.ImportedServicesModel) MetaInfo(org.qi4j.api.common.MetaInfo) ObjectsModel(org.qi4j.runtime.object.ObjectsModel) ModuleModel(org.qi4j.runtime.structure.ModuleModel) EntitiesModel(org.qi4j.runtime.entity.EntitiesModel) AssemblyException(org.qi4j.bootstrap.AssemblyException) ServiceModel(org.qi4j.runtime.service.ServiceModel) ImportedServiceModel(org.qi4j.runtime.service.ImportedServiceModel) HashSet(java.util.HashSet) ImportedServicesModel(org.qi4j.runtime.service.ImportedServicesModel) ServicesModel(org.qi4j.runtime.service.ServicesModel) EntityModel(org.qi4j.runtime.entity.EntityModel) DuplicateServiceIdentityException(org.qi4j.api.service.DuplicateServiceIdentityException) ValuesModel(org.qi4j.runtime.value.ValuesModel) TransientModel(org.qi4j.runtime.composite.TransientModel) TransientsModel(org.qi4j.runtime.composite.TransientsModel) Module(org.qi4j.api.structure.Module)

Example 7 with ValueModel

use of org.qi4j.runtime.value.ValueModel in project qi4j-sdk by Qi4j.

the class ValueAssemblyImpl method newValueModel.

ValueModel newValueModel(StateDeclarations stateDeclarations, AssemblyHelper helper) {
    try {
        associationsModel = new AssociationsModel();
        manyAssociationsModel = new ManyAssociationsModel();
        buildComposite(helper, stateDeclarations);
        ValueModel valueModel = new ValueModel(types, visibility, metaInfo, mixinsModel, (ValueStateModel) stateModel, compositeMethodsModel);
        return valueModel;
    } catch (Exception e) {
        throw new InvalidApplicationException("Could not register " + types, e);
    }
}
Also used : ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) ValueModel(org.qi4j.runtime.value.ValueModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) AssociationsModel(org.qi4j.runtime.association.AssociationsModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Aggregations

ValueModel (org.qi4j.runtime.value.ValueModel)7 NoSuchValueException (org.qi4j.api.value.NoSuchValueException)4 InvalidApplicationException (org.qi4j.api.common.InvalidApplicationException)2 MetaInfo (org.qi4j.api.common.MetaInfo)2 ValueComposite (org.qi4j.api.value.ValueComposite)2 AssociationsModel (org.qi4j.runtime.association.AssociationsModel)2 ManyAssociationsModel (org.qi4j.runtime.association.ManyAssociationsModel)2 FunctionStateResolver (org.qi4j.runtime.composite.FunctionStateResolver)2 StateResolver (org.qi4j.runtime.composite.StateResolver)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 TypeVariable (java.lang.reflect.TypeVariable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ConstructionException (org.qi4j.api.common.ConstructionException)1 Composite (org.qi4j.api.composite.Composite)1 EntityComposite (org.qi4j.api.entity.EntityComposite)1 DuplicateServiceIdentityException (org.qi4j.api.service.DuplicateServiceIdentityException)1 Module (org.qi4j.api.structure.Module)1 CollectionType (org.qi4j.api.type.CollectionType)1