/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. */ package org.schemarepo; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; /** * Base class for all delegating repositories. Implements decorator pattern. */ public abstract class DelegatingRepository extends BaseRepository { protected final Repository repo; protected DelegatingRepository(final Repository delegate) { if (delegate == null) { throw new IllegalArgumentException("Delegate repository required"); } this.repo = delegate; } @Override public void isValid() { if (repo instanceof BaseRepository) { ((BaseRepository)repo).isValid(); } } @Override public Subject register(final String subjectName, final SubjectConfig config) { return repo.register(subjectName, config); } @Override public Subject lookup(final String subjectName) { return repo.lookup(subjectName); } @Override public Iterable<Subject> subjects() { return repo.subjects(); } @Override public void close() throws IOException { repo.close(); } @Override protected Map<String, String> exposeConfiguration() { final Map<String, String> properties = new LinkedHashMap<String, String>(super.exposeConfiguration()); properties.put("DELEGATE", repo.toString()); return properties; } }