View Javadoc
1   /*
2   Copyright (c) 2011 James Ahlborn
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  
17  package com.healthmarketscience.jackcess.util;
18  
19  import java.io.File;
20  import java.io.IOException;
21  
22  import com.healthmarketscience.jackcess.Database;
23  import com.healthmarketscience.jackcess.DatabaseBuilder;
24  import com.healthmarketscience.jackcess.impl.DatabaseImpl;
25  
26  /**
27   * Resolver for linked databases.
28   *
29   * @author James Ahlborn
30   * @usage _intermediate_class_
31   */
32  @FunctionalInterface
33  public interface LinkResolver
34  {
35    /**
36     * default link resolver used if none provided
37     * @usage _general_field_
38     */
39    public static final LinkResolveril/LinkResolver.html#LinkResolver">LinkResolver DEFAULT = new LinkResolver() {
40        @Override
41        public Databasem/healthmarketscience/jackcess/Database.html#Database">Database resolveLinkedDatabase(Database linkerDb,
42                                              String linkeeFileName)
43          throws IOException
44        {
45          // if linker is read-only, open linkee read-only
46          boolean readOnly = ((linkerDb instanceof DatabaseImpl) ?
47                              ((DatabaseImpl)linkerDb).isReadOnly() : false);
48          return new DatabaseBuilder(new File(linkeeFileName))
49            .setReadOnly(readOnly).open();
50        }
51      };
52  
53    /**
54     * Returns the appropriate Database instance for the linkeeFileName from the
55     * given linkerDb.
56     */
57    public Databasem/healthmarketscience/jackcess/Database.html#Database">Database resolveLinkedDatabase(Database linkerDb, String linkeeFileName)
58      throws IOException;
59  }