View Javadoc
1   /*
2    * Copyright 2011 FatWire Corporation. All Rights Reserved.
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 com.fatwire.gst.foundation.mapping;
17  
18  /**
19   * Object to hold the CSElement or Template mapping value and mapping type.
20   * 
21   * @author Dolf Dijkstra
22   * @since Apr 13, 2011
23   */
24  public final class MappingValue {
25  
26      /**
27       * Enum for the mapping type.
28       */
29      public enum Type {
30          asset, assettype, assetname, tname
31      }
32  
33      private final Type type;
34      private final String value;
35      private String[] parts;
36  
37      /**
38       * @param type mapping type
39       * @param value mapping value
40       */
41      public MappingValue(final Type type, final String value) {
42          super();
43          this.type = type;
44          this.value = value;
45          switch (type) {
46              case asset:
47              case assetname:
48                  parts = value.split(":");
49                  break;
50              default:
51                  break;
52          }
53      }
54  
55      /**
56       * @return the left hand side of the value
57       */
58      public String getLeft() {
59          if (parts == null) {
60              return value;
61          }
62          return parts[0];
63      }
64  
65      /**
66       * @return the right hand side of the value.
67       */
68      public String getRight() {
69          if (parts == null) {
70              return value;
71          }
72          return parts[1];
73      }
74  
75      /**
76       * @return the type
77       */
78      public Type getType() {
79          return type;
80      }
81  
82      /**
83       * @return the value
84       */
85      public String getValue() {
86          return value;
87      }
88  }