public AdapterType adaptTo()

in src/main/java/org/apache/sling/resourcemerger/impl/CRUDMergedResource.java [72:100]


    public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {
        if (type == ModifiableValueMap.class) {
            final Iterator<@NotNull Resource> iter = this.picker.pickResources(this.getResourceResolver(), this.relativePath, null).iterator();
            Resource highestRsrc = null;
            while ( iter.hasNext() ) {
                highestRsrc = iter.next();
            }
            if ( ResourceUtil.isNonExistingResource(highestRsrc) ) {
                final String paths[] = (String[])this.getResourceMetadata().get(MergedResourceConstants.METADATA_RESOURCES);

                final Resource copyResource = this.getResourceResolver().getResource(paths[paths.length - 1]);
                try {
                    final @NotNull Resource newResource = ResourceUtil.getOrCreateResource(this.getResourceResolver(), highestRsrc.getPath(), copyResource.getResourceType(), null, false);
                    final ModifiableValueMap target = newResource.adaptTo(ModifiableValueMap.class);
                    if ( target != null ) {
                        return (AdapterType)new ModifiableProperties(this, target);
                    }
                } catch ( final PersistenceException pe) {
                    // we ignore this for now
                }
                return super.adaptTo(type);
            }
            final ModifiableValueMap target = highestRsrc.adaptTo(ModifiableValueMap.class);
            if ( target != null ) {
                return (AdapterType)new ModifiableProperties(this, target);
            }
        }
        return super.adaptTo(type);
    }