use of org.qi4j.runtime.service.ImportedServiceModel in project qi4j-sdk by Qi4j.
the class ImportedServiceAssemblyImpl method addImportedServiceModel.
@SuppressWarnings({ "raw", "unchecked" })
void addImportedServiceModel(List<ImportedServiceModel> serviceModels) {
try {
String id = identity;
if (id == null) {
id = generateId(serviceModels, serviceType);
}
ImportedServiceModel serviceModel = new ImportedServiceModel(serviceType, visibility, serviceProvider, id, importOnStartup, new MetaInfo(metaInfo).withAnnotations(serviceType), new ActivatorsModel(activators), moduleAssembly.name());
serviceModels.add(serviceModel);
} catch (Exception e) {
throw new InvalidApplicationException("Could not register " + serviceType.getName(), e);
}
}
use of org.qi4j.runtime.service.ImportedServiceModel in project qi4j-sdk by Qi4j.
the class ImportedServiceAssemblyImpl method generateId.
@SuppressWarnings("raw")
private String generateId(List<ImportedServiceModel> serviceModels, Class serviceType) {
// Find identity that is not yet used
int idx = 0;
String id = serviceType.getSimpleName();
boolean invalid;
do {
invalid = false;
for (ImportedServiceModel serviceModel : serviceModels) {
if (serviceModel.identity().equals(id)) {
idx++;
id = serviceType.getSimpleName() + "_" + idx;
invalid = true;
break;
}
}
} while (invalid);
return id;
}
use of org.qi4j.runtime.service.ImportedServiceModel 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;
}
Aggregations