LocalMetadataWrapper.java

  1. /*
  2.  * Copyright (c) 2007-2024 MetaSolutions AB
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */

  16. package org.entrystore.impl;

  17. import org.eclipse.rdf4j.model.Model;
  18. import org.eclipse.rdf4j.model.impl.LinkedHashModel;
  19. import org.entrystore.Entry;
  20. import org.entrystore.Metadata;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;

  23. import java.net.URI;


  24. public class LocalMetadataWrapper implements Metadata {

  25.     Logger log = LoggerFactory.getLogger(LocalMetadataWrapper.class);

  26.     Entry entry;

  27.     URI refEntryURI;

  28.     public LocalMetadataWrapper(Entry entry) {
  29.         this.entry = entry;
  30.         Entry e = entry.getRepositoryManager().getContextManager().getEntry(entry.getExternalMetadataURI());
  31.         if (e != null) {
  32.             refEntryURI = e.getEntryURI();
  33.         } else {
  34.             log.warn("Could not find Entry with external MD URI: " + entry.getExternalMetadataURI());
  35.         }
  36.     }

  37.     public Model getGraph() {
  38.         Entry e = null;
  39.         if (refEntryURI != null) {
  40.             e = ((ContextImpl) entry.getContext()).getSoftCache().getByEntryURI(refEntryURI);
  41.         }
  42.         if (e == null) {
  43.             e = entry.getRepositoryManager().getContextManager().getEntry(entry.getExternalMetadataURI());
  44.         }
  45.         if (e != null && e.getLocalMetadata() != null) {
  46.             return e.getLocalMetadata().getGraph();
  47.         } else {
  48.             log.warn("Entry is null, returning an empty graph");
  49.             return new LinkedHashModel();
  50.         }
  51.     }

  52.     public URI getResourceURI() {
  53.         return entry.getResourceURI();
  54.     }

  55.     public URI getURI() {
  56.         return entry.getExternalMetadataURI();
  57.     }

  58.     public boolean isCached() {
  59.         return true;
  60.     }

  61.     public void setGraph(Model graph) {
  62.         throw new UnsupportedOperationException();
  63.     }

  64. }