org.hisrc.jsonix.definition.Modules Maven / Gradle / Ivy
package org.hisrc.jsonix.definition;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.Validate;
import org.hisrc.jsonix.configuration.AmbiguousPackageMappingException;
import org.hisrc.jsonix.context.JsonixContext;
import org.jvnet.jaxb2_commons.xml.bind.model.MModelInfo;
import org.slf4j.Logger;
public class Modules {
private final Logger logger;
private final Collection> modules;
private final Map packageMappingNameMap = new HashMap();
private final MModelInfo modelInfo;
public Modules(JsonixContext context, MModelInfo modelInfo,
Collection> modules) {
Validate.notNull(modelInfo);
Validate.noNullElements(modules);
this.logger = Validate.notNull(context).getLoggerFactory()
.getLogger(Modules.class.getName());
this.modelInfo = modelInfo;
this.modules = modules;
for (Module module : modules) {
for (Mapping mapping : module.getMappings()) {
final String packageName = mapping.getPackageName();
final String mappingName = mapping.getMappingName();
final String knownMappingName = packageMappingNameMap
.get(packageName);
if (knownMappingName == null) {
this.packageMappingNameMap.put(packageName, mappingName);
} else if (!knownMappingName.equals(mappingName)) {
logger.warn(MessageFormat
.format("Package [{0}] is mapped using at least two different mapping names [{1}] and [{2}]. Packages may be mapped by several mappings but they have to have equal names.",
packageName, knownMappingName, mappingName));
throw new AmbiguousPackageMappingException(packageName,
knownMappingName, mappingName);
}
}
}
}
public MModelInfo getModelInfo() {
return modelInfo;
}
public String getMappingName(String packageName) {
return this.packageMappingNameMap.get(packageName);
}
public Collection> getModules() {
return modules;
}
@Override
public String toString() {
return this.modules.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy