1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.javaclass;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.astrogrid.applications.service.v1.cea.CeaSecurityGuard;
16
17
18 /*** Sample class of static methods, to use as java 'applications'
19 * @author Noel Winstanley nw@jb.man.ac.uk 08-Jun-2004
20 *
21 */
22 public class SampleJavaClassApplications {
23 /***
24 * Commons Logger for this class
25 */
26 private static final Log logger = LogFactory
27 .getLog(SampleJavaClassApplications.class);
28
29 /*** Static methods - so no public constructor
30 *
31 */
32 private SampleJavaClassApplications() {
33 super();
34 }
35 /*** the classic */
36 public static String helloWorld() {
37 return "Hello World!";
38 }
39
40 /*** say hello to someone */
41 public static String helloYou(String who) {
42 return "Hello " + who;
43 }
44 /*** add two numbers */
45 public static int sum(int a, int b) {
46 logger.info("Summing " + a + " and " + b);
47 return a + b;
48 }
49
50 /*** Two different argument types */
51 public static String echoDifferentArgs(String string, int integer) {
52 return string + integer;
53 }
54
55 /***
56 * Uses security facade to find the caller's identity.
57 */
58 public static String whoAmI() {
59 CeaSecurityGuard g = CeaSecurityGuard.getInstanceFromContext();
60 if (g.isAuthenticated()) {
61 return g.getX500Principal().getName();
62 }
63 else {
64 return "not authenticated";
65 }
66 }
67
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102