01: /*
02: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package org.mandarax.examples.crm;
20:
21: import org.mandarax.examples.crm.domainmodel.*;
22: import org.mandarax.kernel.*;
23: import org.mandarax.kernel.meta.JFunction;
24: import org.mandarax.util.*;
25:
26: /**
27: * Factory for predicates and functions used in this example.
28: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
29: * @version 3.4 <7 March 05>
30: * @since 3.4
31: */
32: public class PredicatesAndFunctions {
33: private static LogicFactorySupport lfs = new LogicFactorySupport();
34:
35: /**
36: * Constructor.
37: */
38: public PredicatesAndFunctions() {
39: super ();
40: }
41:
42: /**
43: * Get the "get turnover" function
44: * @return a function
45: */
46: public static Function getFunctionTurnover() {
47: try {
48: Class[] par = { Integer.TYPE };
49:
50: return new JFunction(Customer.class.getMethod(
51: "getTurnover", par), "turnover");
52: } catch (NoSuchMethodException x) {
53: x.printStackTrace(System.err);
54: }
55:
56: return null;
57: }
58:
59: /**
60: * Get the "get turnover made with a certain kind of payment" function
61: * @return a function
62: */
63: public static Function getFunctionTurnoverForKindOfPayment() {
64: try {
65: Class[] par = { Integer.TYPE, KindOfPayment.class };
66:
67: return new JFunction(Customer.class.getMethod(
68: "getTurnover", par), "turnover/payment");
69: } catch (NoSuchMethodException x) {
70: x.printStackTrace(System.err);
71: }
72:
73: return null;
74: }
75:
76: /**
77: * Get the "customer gets a certain discount" predicate
78: * @return a predicate
79: */
80: public static Predicate getPredicateGetDiscount() {
81: Class[] par = { Customer.class, Discount.class };
82:
83: return new SimplePredicate("getsDiscount", par);
84: }
85:
86: /**
87: * Get the "customer is in a certain category" predicate
88: * @return a predicate
89: */
90: public static Predicate getPredicateHasCategory() {
91: Class[] par = { Customer.class, Category.class };
92:
93: return new SimplePredicate("hasCategory", par);
94:
95: //Class[] par2 = {Customer.class,Discount.class};
96: //predicates[1] = new SimplePredicate("getsDiscount",par2);
97: }
98:
99: }
|