Class XmlRepoDiffer


  • public final class XmlRepoDiffer
    extends java.lang.Object
    • 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 resource
      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 resource
      private static java.util.List<Element> createFilterElement​(java.lang.String filter)
      Creates list of Elements for the associated filter
      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 single Element comprising the specified attributes and directives which are associated with the specified namespace and differ type
      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
      static java.util.List<Element> mapToElements​(java.util.Map<java.lang.String,​? extends java.lang.Object> entries, Type type, boolean expandFilter)
      Creates list of Elements associating the specified entries
      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.
      static Element resource​(java.io.File file)
      Returns the differ Element for comparison
      static Element resource​(java.io.File file, boolean expandFilter)
      Returns the differ Element for comparison
      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 type List, new entries get created for every element containing in the value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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
    • Constructor Detail

      • XmlRepoDiffer

        private XmlRepoDiffer()
    • Method Detail

      • resource

        public static Element resource​(java.io.File file)
                                throws java.lang.Exception
        Returns the differ Element for comparison

        Note 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 differ Element for comparison

        Note that, the filter directives will be expanded if expandFilter is set to true

        Parameters:
        file - the XML resource repository
        expandFilter - the flag to expand filter 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 attributes
        namespace - 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 resource

        Note 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 requirement
        resource - 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 resource

        For example, the osgi.wiring.package namespace must include the following attributes which are, according to specification, mandatory but XMLResourceGenerator does not add these attributes.

        • bundle-symbolic-name
        • bundle-version
        Parameters:
        capability - the capability
        resource - 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 single Element comprising the specified attributes and directives which are associated with the specified namespace and differ type
        Parameters:
        attributes - the attributes
        directives - the directives
        namespace - the namespace to associate
        type - the differ type for comparison
        expandFilter - the flag to expand filter 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 of Elements associating the specified entries
        Parameters:
        entries - the entries to associate
        type - the type to use for comparison
        expandFilter - the flag to expand filter directives
        Returns:
        the list of Elements
      • 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 type List, new entries get created for every element containing in the value. This is required for attributes and directive of type List
        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 removed
        namespace - the namespace to check for the key attribute name
        Returns:
        the final map of attributes without the key attribute
      • createFilterElement

        private static java.util.List<Element> createFilterElement​(java.lang.String filter)
        Creates list of Elements for the associated filter
        Parameters:
        filter - the filter
        Returns:
        the list of Element