View Javadoc
1   /**
2    *    Copyright 2009-2015 the original author or authors.
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.apache.ibatis.mapping;
17  
18  import java.util.Collections;
19  import java.util.Map;
20  
21  import org.apache.ibatis.session.Configuration;
22  
23  /**
24   * @author Clinton Begin
25   */
26  public class Discriminator {
27  
28    private ResultMapping resultMapping;
29    private Map<String, String> discriminatorMap;
30  
31    Discriminator() {
32    }
33  
34    public static class Builder {
35      private Discriminator discriminator = new Discriminator();
36  
37      public Builder(Configuration configuration, ResultMapping resultMapping, Map<String, String> discriminatorMap) {
38        discriminator.resultMapping = resultMapping;
39        discriminator.discriminatorMap = discriminatorMap;
40      }
41  
42      public Discriminator build() {
43        assert discriminator.resultMapping != null;
44        assert discriminator.discriminatorMap != null;
45        assert !discriminator.discriminatorMap.isEmpty();
46        //lock down map
47        discriminator.discriminatorMap = Collections.unmodifiableMap(discriminator.discriminatorMap);
48        return discriminator;
49      }
50    }
51  
52    public ResultMapping getResultMapping() {
53      return resultMapping;
54    }
55  
56    public Map<String, String> getDiscriminatorMap() {
57      return discriminatorMap;
58    }
59  
60    public String getMapIdFor(String s) {
61      return discriminatorMap.get(s);
62    }
63  
64  }