Package aQute.bnd.differ
Class XmlRepoDiffer
- java.lang.Object
-
- aQute.bnd.differ.XmlRepoDiffer
-
public final class XmlRepoDiffer extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
XmlRepoDiffer.ComparatorKeyAttributeFinder
Used to find the comparator key attribute in thefilter
directiveprivate static class
XmlRepoDiffer.FilterVisitor
Used to prepare a map containing relevant informations from afilter
directive
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ATTRIBUTE_DIRECTIVE_DELIMITER
private static java.util.Map<java.lang.String,java.lang.Object>
COMPARATOR_ATTRIBUTES
private static java.lang.String
KEY_DELIMITER
-
Constructor Summary
Constructors Modifier Constructor Description private
XmlRepoDiffer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static org.osgi.resource.Capability
addMissingAttributes(org.osgi.resource.Capability capability, org.osgi.resource.Resource resource)
Adds the missing attributes to the specified capability of the specified resourceprivate static org.osgi.resource.Requirement
addPlaceholderAttributes(org.osgi.resource.Requirement requirement, org.osgi.resource.Resource resource)
Adds specific attributes to the specified requirement of the specified resourceprivate static java.util.List<Element>
createFilterElement(java.lang.String filter)
Creates list ofElement
s for the associated filterprivate static Element
extractElement(java.util.Map<java.lang.String,java.lang.Object> attributes, java.util.Map<java.lang.String,? extends java.lang.Object> directives, java.lang.String namespace, Type type, boolean expandFilter)
Creates a singleElement
comprising the specified attributes and directives which are associated with the specified namespace and differ typeprivate static java.lang.String
formatComparatorKey(java.util.Map<java.lang.String,java.lang.Object> attributes, java.lang.String namespace)
Returns the formatted comparator key for the specified attributes associating the specified namespacestatic java.util.List<Element>
mapToElements(java.util.Map<java.lang.String,? extends java.lang.Object> entries, Type type, boolean expandFilter)
Creates list ofElement
s associating the specified entriesprivate static java.util.Map<java.lang.String,? extends java.lang.Object>
removeKeyAttribute(java.util.Map<java.lang.String,? extends java.lang.Object> attributes, java.lang.String namespace)
Removes the attribute from the attributes list which has been used as comparator key for comparison.static Element
resource(java.io.File file)
Returns the differElement
for comparisonstatic Element
resource(java.io.File file, boolean expandFilter)
Returns the differElement
for comparisonprivate static java.util.Map<java.lang.String,? extends java.lang.Object>
validate(java.util.Map<java.lang.String,? extends java.lang.Object> entries)
Iterates over a map of entries and if any of entry has a value which is of typeList
, new entries get created for every element containing in the value.
-
-
-
Field Detail
-
KEY_DELIMITER
private static final java.lang.String KEY_DELIMITER
- See Also:
- Constant Field Values
-
ATTRIBUTE_DIRECTIVE_DELIMITER
private static final java.lang.String ATTRIBUTE_DIRECTIVE_DELIMITER
- See Also:
- Constant Field Values
-
COMPARATOR_ATTRIBUTES
private static final java.util.Map<java.lang.String,java.lang.Object> COMPARATOR_ATTRIBUTES
-
-
Method Detail
-
resource
public static Element resource(java.io.File file) throws java.lang.Exception
Returns the differElement
for comparisonNote that, the
filter
directives will not be expanded- Parameters:
file
- the XML resource repository- Returns:
- the differ
Element
- Throws:
java.lang.Exception
- for any discrepancy- See Also:
resource(File, boolean)
-
resource
public static Element resource(java.io.File file, boolean expandFilter) throws java.lang.Exception
Returns the differElement
for comparisonNote that, the
filter
directives will be expanded ifexpandFilter
is set totrue
- Parameters:
file
- the XML resource repositoryexpandFilter
- the flag to expandfilter
directives- Returns:
- the differ
Element
- Throws:
java.lang.Exception
- for any discrepancy- See Also:
resource(File)
-
formatComparatorKey
private static java.lang.String formatComparatorKey(java.util.Map<java.lang.String,java.lang.Object> attributes, java.lang.String namespace)
Returns the formatted comparator key for the specified attributes associating the specified namespace- Parameters:
attributes
- the attributesnamespace
- the namespace- Returns:
- the formatted comparator key
-
addPlaceholderAttributes
private static org.osgi.resource.Requirement addPlaceholderAttributes(org.osgi.resource.Requirement requirement, org.osgi.resource.Resource resource)
Adds specific attributes to the specified requirement of the specified resourceNote that, the attributes are added to ease the comparison between same resources in two XML resource repositories
Also note that, the
COMPARATOR_ATTRIBUTES
comprises the map of namespaces and attributes denoting which attribute of the namespace will be added as placeholders- Parameters:
requirement
- the requirementresource
- the resource- Returns:
- the updated requirement comprising the attributes as specified in
COMPARATOR_ATTRIBUTES
-
addMissingAttributes
private static org.osgi.resource.Capability addMissingAttributes(org.osgi.resource.Capability capability, org.osgi.resource.Resource resource)
Adds the missing attributes to the specified capability of the specified resourceFor example, the
osgi.wiring.package
namespace must include the following attributes which are, according to specification, mandatory butXMLResourceGenerator
does not add these attributes.- bundle-symbolic-name
- bundle-version
- Parameters:
capability
- the capabilityresource
- the resource- Returns:
- the updated capability comprising the missing attributes
-
extractElement
private static Element extractElement(java.util.Map<java.lang.String,java.lang.Object> attributes, java.util.Map<java.lang.String,? extends java.lang.Object> directives, java.lang.String namespace, Type type, boolean expandFilter)
Creates a singleElement
comprising the specified attributes and directives which are associated with the specified namespace and differ type- Parameters:
attributes
- the attributesdirectives
- the directivesnamespace
- the namespace to associatetype
- the differ type for comparisonexpandFilter
- the flag to expandfilter
directives- Returns:
- the
Element
-
mapToElements
public static java.util.List<Element> mapToElements(java.util.Map<java.lang.String,? extends java.lang.Object> entries, Type type, boolean expandFilter)
Creates list ofElement
s associating the specified entries- Parameters:
entries
- the entries to associatetype
- the type to use for comparisonexpandFilter
- the flag to expandfilter
directives- Returns:
- the list of
Element
s
-
validate
private static java.util.Map<java.lang.String,? extends java.lang.Object> validate(java.util.Map<java.lang.String,? extends java.lang.Object> entries)
Iterates over a map of entries and if any of entry has a value which is of typeList
, new entries get created for every element containing in the value. This is required for attributes and directive of typeList
- Parameters:
entries
- the map of entries (attributes or directives)- Returns:
- the new map of entries
-
removeKeyAttribute
private static java.util.Map<java.lang.String,? extends java.lang.Object> removeKeyAttribute(java.util.Map<java.lang.String,? extends java.lang.Object> attributes, java.lang.String namespace)
Removes the attribute from the attributes list which has been used as comparator key for comparison.- Parameters:
attributes
- the attributes from which the key attribute is removednamespace
- the namespace to check for the key attribute name- Returns:
- the final map of attributes without the key attribute
-
-