View Javadoc

1   /*
2    * Copyright (C) 2003-2012 David E. Berry
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not, write to the Free Software
16   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17   *
18   * A copy of the GNU Lesser General Public License may also be found at
19   * http://www.gnu.org/licenses/lgpl.txt
20   */
21  package org.synchronoss.cpo;
22  
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  import org.synchronoss.cpo.meta.domain.CpoAttribute;
26  
27  /**
28   *
29   * @author dberry
30   */
31  public abstract class AbstractCpoData implements CpoData{
32    
33    private static final Logger logger = LoggerFactory.getLogger(AbstractCpoData.class);
34    private CpoAttribute cpoAttribute = null;
35    
36    public AbstractCpoData(CpoAttribute cpoAttribute) {
37      this.cpoAttribute = cpoAttribute;
38    }
39  
40    public CpoAttribute getCpoAttribute() {
41      return cpoAttribute;
42    }
43  
44    public void setCpoAttribute(CpoAttribute cpoAttribute) {
45      this.cpoAttribute = cpoAttribute;
46    }
47  
48    @Override
49    public Object transformIn(Object datasourceObject) throws CpoException {
50      Object retObj = datasourceObject;
51  
52      if (cpoAttribute.getCpoTransform() != null) {
53        retObj = cpoAttribute.getCpoTransform().transformIn(datasourceObject);
54      }
55      return retObj;
56    }
57  
58    @Override
59    public Object transformOut(Object attributeObject) throws CpoException {
60      Object retObj = attributeObject;
61  
62      if (cpoAttribute.getCpoTransform() != null) {
63        retObj = cpoAttribute.getCpoTransform().transformOut(attributeObject);
64      }
65      return retObj;
66    }
67  
68    @Override
69    public Object invokeGetter() throws CpoException {
70      throw new UnsupportedOperationException("Not supported yet.");
71    }
72  
73    @Override
74    public void invokeSetter(Object instanceObject) throws CpoException {
75      throw new UnsupportedOperationException("Not supported yet.");
76    }
77    
78    public Class getDataGetterReturnType() {
79      Class returnClass = cpoAttribute.getSetterParamType();
80      if (cpoAttribute.getCpoTransform()!=null){
81        returnClass=cpoAttribute.getTransformInMethod().getParameterTypes()[0];
82      }
83      return returnClass;
84    }
85    
86    public Class getDataSetterParamType() {
87      Class returnClass = cpoAttribute.getGetterReturnType();
88      if (cpoAttribute.getCpoTransform()!=null){
89        returnClass=cpoAttribute.getTransformOutMethod().getReturnType();
90      }
91      return returnClass;
92    }
93  
94  }