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.meta.domain;
22  
23  import org.slf4j.*;
24  import org.synchronoss.cpo.meta.bean.CpoFunctionBean;
25  
26  import java.util.*;
27  
28  public class CpoFunction extends CpoFunctionBean {
29  
30    private static final Logger logger = LoggerFactory.getLogger(CpoFunction.class);
31    List<CpoArgument> arguments = new ArrayList<CpoArgument>();
32  
33    public CpoFunction() {
34    }
35  
36    public List<CpoArgument> getArguments() {
37      return arguments;
38    }
39  
40    public void addArgument(CpoArgument argument) {
41      if (argument != null) {
42        arguments.add(argument);
43      }
44    }
45  
46    public boolean removeArgument(CpoArgument argument) {
47      if (argument != null) {
48        return arguments.remove(argument);
49      }
50      return false;
51    }
52  
53    public boolean removeArgument(int index) {
54      if (index > 0 && index < arguments.size()) {
55        return (arguments.remove(index) != null);
56      }
57      return false;
58    }
59  
60    /**
61     * DOCUMENT ME!
62     *
63     * @param function DOCUMENT ME!
64     * @return DOCUMENT ME!
65     */
66    public String parameterToString(CpoFunction function) {
67      List<CpoArgument> args;
68      int j;
69      CpoArgument argument;
70      CpoAttribute attribute;
71      int type = 0;
72      Class<?> c;
73      StringBuilder sb = new StringBuilder("Parameter list for ");
74  
75      if (function == null) {
76        return " null function.";
77      }
78  
79      // TODO make uncomment the following line and make work
80  //    sb.append(jq.getName() + " " + jq.getType());
81      args = function.getArguments();
82  
83      for (j = 1; j <= args.size(); j++) {
84        argument = args.get(j - 1);
85  
86        if (argument != null) {
87          try {
88            attribute = argument.getAttribute();
89            c = attribute.getGetter().getReturnType();
90            // TODO make uncomment the following line and make work
91  //          type = attribute.getJavaSqlType();
92            if (c != null) {
93              sb.append(" col" + j + ":" + c.getName() + " type:"
94                      + type + " ");
95            } else {
96              sb.append(j + ":null type:" + type + " ");
97            }
98          } catch (Exception e) {
99            String msg = "parameterToString() Failed:";
100           logger.error(msg);
101         }
102       }
103     }
104 
105     return sb.toString();
106   }
107 
108   @Override
109   public String toString() {
110     return this.getName();
111   }
112 
113   public String toStringFull() {
114     return super.toString();
115   }
116 }