use of org.jboss.modules.ModuleDependencySpecBuilder in project jboss-modules by jboss-modules.
the class ModuleXmlParser method parseModuleDependency.
private static void parseModuleDependency(final XmlPullParser reader, final ArrayList<DependencySpec> dependencies) throws XmlPullParserException, IOException {
String name = null;
String slot = null;
boolean export = false;
boolean optional = false;
boolean noSlots = atLeast1_6(reader);
String services = D_NONE;
final Set<String> required = new HashSet<>(LIST_A_NAME);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
validateAttributeNamespace(reader, i);
final String attribute = reader.getAttributeName(i);
required.remove(attribute);
switch(attribute) {
case A_NAME:
name = reader.getAttributeValue(i);
break;
case A_SLOT:
if (noSlots)
throw unknownAttribute(reader, i);
else
slot = reader.getAttributeValue(i);
break;
case A_EXPORT:
export = Boolean.parseBoolean(reader.getAttributeValue(i));
break;
case A_OPTIONAL:
optional = Boolean.parseBoolean(reader.getAttributeValue(i));
break;
case A_SERVICES:
{
services = reader.getAttributeValue(i);
switch(services) {
case D_NONE:
case D_IMPORT:
case D_EXPORT:
break;
default:
throw unknownAttributeValue(reader, i);
}
break;
}
default:
throw unknownAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingAttributes(reader, required);
}
final MultiplePathFilterBuilder importBuilder = PathFilters.multiplePathFilterBuilder(true);
final MultiplePathFilterBuilder exportBuilder = PathFilters.multiplePathFilterBuilder(export);
int eventType;
for (; ; ) {
eventType = reader.nextTag();
switch(eventType) {
case END_TAG:
{
assert services.equals(D_NONE) || services.equals(D_EXPORT) || services.equals(D_IMPORT);
if (services.equals(D_EXPORT)) {
// If services are to be re-exported, add META-INF/services -> true near the end of the list
exportBuilder.addFilter(PathFilters.getMetaInfServicesFilter(), true);
}
if (export) {
// If re-exported, add META-INF/** -> false at the end of the list (require explicit override)
exportBuilder.addFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
exportBuilder.addFilter(PathFilters.getMetaInfFilter(), false);
}
final PathFilter exportFilter = exportBuilder.create();
final PathFilter importFilter;
if (importBuilder.isEmpty()) {
importFilter = services.equals(D_NONE) ? PathFilters.getDefaultImportFilter() : PathFilters.getDefaultImportFilterWithServices();
} else {
if (!services.equals(D_NONE)) {
importBuilder.addFilter(PathFilters.getMetaInfServicesFilter(), true);
}
importBuilder.addFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
importBuilder.addFilter(PathFilters.getMetaInfFilter(), false);
importFilter = importBuilder.create();
}
dependencies.add(new ModuleDependencySpecBuilder().setImportFilter(importFilter).setExportFilter(exportFilter).setName(noSlots ? name : ModuleIdentifier.create(name, slot).toString()).setOptional(optional).build());
return;
}
case START_TAG:
{
validateNamespace(reader);
switch(reader.getName()) {
case E_EXPORTS:
parseFilterList(reader, exportBuilder);
break;
case E_IMPORTS:
parseFilterList(reader, importBuilder);
break;
default:
throw unexpectedContent(reader);
}
break;
}
default:
{
throw unexpectedContent(reader);
}
}
}
}
Aggregations