/** * Performs the actual copy operation on a single metadata instance. * This method is invoked by all public {@code copy(…)} method with the root {@code metadata} * object in argument, then is invoked recursively for all properties in that metadata object. * If a metadata property is a collection, then this method is invoked for each element in the collection. * * <p>Subclasses can override this method if they need some control on the copy process.</p> * * @param type the interface of the metadata object to copy, or {@code null} if unspecified. * @param metadata the metadata object to copy, or {@code null}. * @return a copy of the given metadata object, or {@code null} if the given argument is {@code null}. * @throws UnsupportedOperationException if there is no implementation class for a metadata to copy, * or an implementation class does not provide a public default constructor. */ protected Object copyRecursively(final Class<?> type, final Object metadata) { if (metadata != null) { MetadataStandard std = standard; if (metadata instanceof AbstractMetadata) { std = ((AbstractMetadata) metadata).getStandard(); } if (std != null) { final Object result = walk(std, type, metadata, false); if (result != null) { return result; } } } return metadata; }