1 package org.synchronoss.cpo.core.meta;
2
3 /*-
4 * [[
5 * core
6 * ==
7 * Copyright (C) 2003 - 2026 Exaxis LLC, Synchronoss Technologies Inc
8 * ==
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * ]]
23 */
24
25 import java.io.Serializable;
26 import java.util.HashMap;
27 import java.util.Map;
28 import org.synchronoss.cpo.core.CpoException;
29
30 /**
31 * MethodMapper maps java classes to the datastore-specific getter and setter methods used to bind
32 * them. Each datastore implementation registers its own entries.
33 *
34 * @param <T> the concrete {@link MethodMapEntry} type registered by the datastore implementation
35 * @author david berry
36 */
37 public class MethodMapper<T extends MethodMapEntry<?, ?>> implements Serializable, Cloneable {
38
39 /** Version Id for this class. */
40 private static final long serialVersionUID = 1L;
41
42 /** Registered entries, keyed by the Java class they move values for. */
43 private Map<Class<?>, T> dataMethodMap = new HashMap<>();
44
45 /** Creates an empty mapper with no registered entries. */
46 public MethodMapper() {}
47
48 /**
49 * Gets the method map entry registered for the given Java class.
50 *
51 * @param c the Java class to look up
52 * @return the entry registered for {@code c}, or {@code null} if none is registered
53 * @throws CpoException if the entry cannot be retrieved
54 */
55 public T getDataMethodMapEntry(Class<?> c) throws CpoException {
56 return dataMethodMap.get(c);
57 }
58
59 /**
60 * Registers a method map entry, keyed by its {@link MethodMapEntry#getJavaClass()}.
61 *
62 * @param dataMethodMapEntry the entry to register
63 */
64 public void addMethodMapEntry(T dataMethodMapEntry) {
65 dataMethodMap.put(dataMethodMapEntry.getJavaClass(), dataMethodMapEntry);
66 }
67 }