View Javadoc
1   package org.synchronoss.cpo.core;
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 org.synchronoss.cpo.core.meta.domain.CpoAttribute;
26  
27  /**
28   * Base {@link CpoData} implementation that owns the {@link CpoAttribute} being bound and handles
29   * the transform half of the contract ({@link #transformIn(Object)}/{@link #transformOut(Object)}).
30   * Datastore-specific subclasses supply the actual reflective getter/setter invocation.
31   *
32   * @author dberry
33   */
34  public abstract class AbstractCpoData implements CpoData {
35  
36    private CpoAttribute cpoAttribute = null;
37  
38    /**
39     * Creates an instance bound to the given attribute.
40     *
41     * @param cpoAttribute the attribute this instance moves data for
42     */
43    public AbstractCpoData(CpoAttribute cpoAttribute) {
44      this.cpoAttribute = cpoAttribute;
45    }
46  
47    /**
48     * Gets the attribute this instance moves data for.
49     *
50     * @return the bound attribute
51     */
52    public CpoAttribute getCpoAttribute() {
53      return cpoAttribute;
54    }
55  
56    /**
57     * Sets the attribute this instance moves data for.
58     *
59     * @param cpoAttribute the attribute to bind
60     */
61    public void setCpoAttribute(CpoAttribute cpoAttribute) {
62      this.cpoAttribute = cpoAttribute;
63    }
64  
65    /**
66     * {@inheritDoc}
67     *
68     * <p>Applies the attribute's configured {@code CpoTransform}, if any; otherwise returns the value
69     * unchanged.
70     */
71    @Override
72    public Object transformIn(Object datasourceObject) throws CpoException {
73      Object retObj = datasourceObject;
74  
75      if (cpoAttribute.getCpoTransform() != null) {
76        retObj = cpoAttribute.getCpoTransform().transformIn(datasourceObject);
77      }
78      return retObj;
79    }
80  
81    /**
82     * {@inheritDoc}
83     *
84     * <p>Applies the attribute's configured {@code CpoTransform}, if any; otherwise returns the value
85     * unchanged.
86     */
87    @Override
88    public Object transformOut(Object attributeObject) throws CpoException {
89      Object retObj = attributeObject;
90  
91      if (cpoAttribute.getCpoTransform() != null) {
92        retObj = cpoAttribute.getCpoTransform().transformOut(attributeObject);
93      }
94      return retObj;
95    }
96  
97    /**
98     * {@inheritDoc}
99     *
100    * <p>Not implemented by this base class; subclasses that support reflective getter invocation
101    * must override this method.
102    *
103    * @throws UnsupportedOperationException always, unless overridden by a subclass
104    */
105   @Override
106   public Object invokeGetter() throws CpoException {
107     throw new UnsupportedOperationException("Not supported yet.");
108   }
109 
110   /**
111    * {@inheritDoc}
112    *
113    * <p>Not implemented by this base class; subclasses that support reflective setter invocation
114    * must override this method.
115    *
116    * @throws UnsupportedOperationException always, unless overridden by a subclass
117    */
118   @Override
119   public void invokeSetter(Object instanceObject) throws CpoException {
120     throw new UnsupportedOperationException("Not supported yet.");
121   }
122 
123   /**
124    * Gets the type that the datastore-side value should be coerced to before being handed to the
125    * bean's setter: the setter's own parameter type, or the transform's input type if the attribute
126    * has a configured {@code CpoTransform}.
127    *
128    * @return the expected type of the raw datastore value
129    */
130   public Class<?> getDataGetterReturnType() {
131     Class<?> returnClass = cpoAttribute.getSetterParamType();
132     if (cpoAttribute.getCpoTransform() != null) {
133       returnClass = cpoAttribute.getTransformInParamType();
134     }
135     return returnClass;
136   }
137 
138   /**
139    * Gets the type that the bean attribute's value is coerced to before being bound to the
140    * datastore: the getter's own return type, or the transform's output type if the attribute has a
141    * configured {@code CpoTransform}.
142    *
143    * @return the expected type of the value to bind to the datastore
144    */
145   public Class<?> getDataSetterParamType() {
146     Class<?> returnClass = cpoAttribute.getGetterReturnType();
147     if (cpoAttribute.getCpoTransform() != null) {
148       returnClass = cpoAttribute.getTransformOutMethod().getReturnType();
149     }
150     return returnClass;
151   }
152 }