Class NilObjectHandler

java.lang.Object
org.apache.sis.xml.NilObjectHandler
All Implemented Interfaces:
InvocationHandler

final class NilObjectHandler extends Object implements InvocationHandler
The handler for an object where all methods returns null or empty collections, except a few methods related to object identity. This handler is used only when no concrete definition were found for a XML element identified by xlink or uuidref attributes.
Implementation note: The same handler could be used for every proxy having the same XLink. For now, it doesn't seem worth to cache the handlers.
Since:
0.3
Version:
1.3
  • Field Details

    • attribute

      private final Object attribute
      The identifiers as an IdentifierMapAdapter object, or the nilReason attribute as a NilReason object. We don't use separated fields because those attributes are exclusive, and some operations like toString(), hashCode() and equals(Object) are the same for both types.
  • Constructor Details

    • NilObjectHandler

      NilObjectHandler(org.opengis.metadata.Identifier[] identifiers)
      Creates a new handler for an object identified by the given identifiers. The identifiers are wrapped in a mutable list, so users can add, remove or modify identifiers.
    • NilObjectHandler

      NilObjectHandler(NilReason nilReason)
      Creates a new handler for an object which is nil for the given reason.
  • Method Details

    • isIgnoredInterface

      static boolean isIgnoredInterface(Class<?> type)
      Returns true if the given type is one of the interfaces ignored by getInterface(Object).
    • getInterface

      private static Class<?> getInterface(Object proxy)
      Returns the interface implemented by the given proxy.
    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Processes a method invocation. For any invocation of a getter method, there is a choice:
      • If the invoked method is getIdentifiers(), returns the identifiers given at construction time.
      • If the invoked method is getIdentifierMap(), returns a view over the identifiers given at construction time.
      • If the invoked method is any other kind of getter, returns null except if:
        • the return type is a collection, in which case an empty collection is returned;
        • the return type is a primitive, in which case the nil value for that primitive type is returned.
      • If the invoked method is a setter method, throw a UnsupportedOperationException since the proxy instance is assumed unmodifiable.
      • If the invoked method is one of the Object method, delegate to the attribute.
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable
    • equals

      private boolean equals(Object proxy, Object other, ComparisonMode mode) throws Throwable
      Compares the given objects to the given level of strictness. The first object shall be the proxy, and the second object an arbitrary implementation. This method returns true if the given arbitrary implementation contains only null or empty attributes.
      Throws:
      Throwable