summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java')
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/AddService.java25
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/AddServiceImpl.java33
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/CalculatorService.java40
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/CalculatorServiceImpl.java61
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/DivideService.java25
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/DivideServiceImpl.java37
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/MultiplyService.java25
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/MultiplyServiceImpl.java33
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/SubtractService.java25
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/SubtractServiceImpl.java33
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/client/CalculatorClient.java84
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SciCalculatorService.java34
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SciCalculatorServiceImpl.java82
-rw-r--r--branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SqrtService.java27
14 files changed, 564 insertions, 0 deletions
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/AddService.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/AddService.java
new file mode 100644
index 0000000000..6392676e76
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/AddService.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+public interface AddService {
+
+ double add(double n1, double n2);
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/AddServiceImpl.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/AddServiceImpl.java
new file mode 100644
index 0000000000..39e9be92e6
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/AddServiceImpl.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Add service
+ */
+@Scope("MODULE")
+public class AddServiceImpl implements AddService {
+
+ public double add(double n1, double n2) {
+ return n1 + n2;
+ }
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/CalculatorService.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/CalculatorService.java
new file mode 100644
index 0000000000..d17650ec3f
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/CalculatorService.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+
+/**
+ * The Calculator service interface.
+ */
+@Remotable
+@Service
+public interface CalculatorService {
+
+ double add(double n1, double n2);
+
+ double subtract(double n1, double n2);
+
+ double multiply(double n1, double n2);
+
+ double divide(double n1, double n2);
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/CalculatorServiceImpl.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/CalculatorServiceImpl.java
new file mode 100644
index 0000000000..0953eae036
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/CalculatorServiceImpl.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Calculator service.
+ */
+@Scope("MODULE")
+public class CalculatorServiceImpl implements CalculatorService {
+
+ @Reference
+ protected AddService addService;
+
+ @Reference
+ protected SubtractService subtractService;
+
+ @Reference
+ protected MultiplyService multiplyService;
+
+ @Reference
+ protected DivideService divideService;
+
+ @Reference
+ protected CalculatorService rmiCalculatorService;
+
+ public double add(double n1, double n2) {
+ return addService.add(n1, n2);
+ }
+
+ public double subtract(double n1, double n2) {
+ return subtractService.subtract(n1, n2);
+ }
+
+ public double multiply(double n1, double n2) {
+ return rmiCalculatorService.multiply(n1, n2);
+ }
+
+ public double divide(double n1, double n2) {
+ return divideService.divide(n1, n2);
+ }
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/DivideService.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/DivideService.java
new file mode 100644
index 0000000000..3158458b5e
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/DivideService.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+public interface DivideService {
+
+ double divide(double n1, double n2);
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/DivideServiceImpl.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/DivideServiceImpl.java
new file mode 100644
index 0000000000..6363068cfd
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/DivideServiceImpl.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Divide service.
+ */
+@Scope("MODULE")
+public class DivideServiceImpl implements DivideService {
+
+ @Reference
+ protected CalculatorService calculatorWebService;
+
+ public double divide(double n1, double n2) {
+ return calculatorWebService.divide(n1, n2);
+ }
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/MultiplyService.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/MultiplyService.java
new file mode 100644
index 0000000000..62db05175e
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/MultiplyService.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+public interface MultiplyService {
+
+ double multiply(double n1, double n2);
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/MultiplyServiceImpl.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/MultiplyServiceImpl.java
new file mode 100644
index 0000000000..7276bb6964
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/MultiplyServiceImpl.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Multiply service.
+ */
+@Scope("MODULE")
+public class MultiplyServiceImpl implements MultiplyService {
+
+ public double multiply(double n1, double n2) {
+ return n1 * n2;
+ }
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/SubtractService.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/SubtractService.java
new file mode 100644
index 0000000000..309f88f098
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/SubtractService.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+public interface SubtractService {
+
+ double subtract(double n1, double n2);
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/SubtractServiceImpl.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/SubtractServiceImpl.java
new file mode 100644
index 0000000000..3c3388f4cd
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/SubtractServiceImpl.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the subtract service.
+ */
+@Scope("MODULE")
+public class SubtractServiceImpl implements SubtractService {
+
+ public double subtract(double n1, double n2) {
+ return n1 - n2;
+ }
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/client/CalculatorClient.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/client/CalculatorClient.java
new file mode 100644
index 0000000000..c02c284007
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/client/CalculatorClient.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator.client;
+
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.CurrentCompositeContext;
+
+import calculator.CalculatorService;
+import calculator.sci.SciCalculatorService;
+
+/**
+ * Calculator client
+ */
+public class CalculatorClient {
+
+ public CalculatorClient() {
+ }
+
+ public static void main(String args[]) throws Exception {
+ try {
+ CalculatorClient calcClient = new CalculatorClient();
+ calcClient.testCalcCombo(args);
+ System.exit(0);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void testCalcCombo(String args[]) {
+ System.out.println("\n\n***************************************");
+ System.out.println("Starting the Calculator Combo sample!!!");
+ System.out.println("***************************************");
+ CompositeContext context = CurrentCompositeContext.getContext();
+ CalculatorService calculatorService =
+ (CalculatorService)context.locateService(CalculatorService.class, "CalculatorServiceComponent");
+ System.out.println("\nInvoking Java Implementation ... ");
+ System.out.println((new StringBuilder()).append("3 + 2 = ").append(calculatorService.add(3D, 2D))
+ .toString());
+ System.out.println("\nInvoking Ruby Implementation ... ");
+ System.out.println((new StringBuilder()).append("3 - 2 = ")
+ .append(calculatorService.subtract(3D, 2D)).toString());
+ System.out.println("\nInvoking over RMI Reference... ");
+ System.out.println((new StringBuilder()).append("3 * 2 = ")
+ .append(calculatorService.multiply(3D, 2D)).toString());
+ System.out.println("\nInvoking WebService Implementation ... ");
+ System.out.println((new StringBuilder()).append("3 / 2 = ").append(calculatorService.divide(3D, 2D))
+ .toString());
+ System.out.println("\nInvoking Scientific Calculator Composite Implementation ... ");
+ SciCalculatorService sciCalculator =
+ (SciCalculatorService)context.locateService(SciCalculatorService.class, "sciCalculatorService");
+ double values[] = {1.0D, 2D, 3D, 4D, 5D, 6D, 7D, 8D, 9D};
+ System.out.println("\tInvoking Java Implementation ... ");
+ System.out.println((new StringBuilder()).append("\tAverage of 1,2,3,4,5,6,7,8,9 = ")
+ .append(sciCalculator.average(values)).toString());
+ System.out.println("\n\tInvoking JavaScript Implementation ... ");
+ System.out.println((new StringBuilder()).append("\tSquare Root of 81 = ").append(sciCalculator
+ .sqrt(81D)).toString());
+ System.out.println("\tInvoking Java Implementation configured for Property ... ");
+ System.out.println((new StringBuilder()).append("\tSine 90 Degrees = ")
+ .append(sciCalculator.sin(90D)).toString());
+ System.out.println((new StringBuilder()).append("\tCos 90 Degrees = ").append(sciCalculator.cos(90D))
+ .toString());
+ System.out.println((new StringBuilder()).append("\tTan 90 Degrees = ").append(sciCalculator.tan(90D))
+ .toString());
+ System.out.println("\nExiting...");
+ }
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SciCalculatorService.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SciCalculatorService.java
new file mode 100644
index 0000000000..ef36007eb6
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SciCalculatorService.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator.sci;
+
+/**
+ * Scientific calculator
+ */
+public interface SciCalculatorService {
+ public abstract double average(double ad[]);
+
+ public abstract double sqrt(double d);
+
+ public abstract double sin(double d);
+
+ public abstract double cos(double d);
+
+ public abstract double tan(double d);
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SciCalculatorServiceImpl.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SciCalculatorServiceImpl.java
new file mode 100644
index 0000000000..b1aba993a7
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SciCalculatorServiceImpl.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator.sci;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+public class SciCalculatorServiceImpl implements SciCalculatorService {
+
+ public static final String RADIANS = "RADIANS";
+ public static final String DEGREES = "DEGREES";
+
+ @Reference
+ protected SqrtService sqrtService;
+
+ private String trig_metric;
+
+ public SciCalculatorServiceImpl() {
+ }
+
+ public double average(double values[]) {
+ double sum = 0.0D;
+ int count = 0;
+ double arr$[] = values;
+ int len$ = arr$.length;
+ for (int i$ = 0; i$ < len$; i$++) {
+ double aValue = arr$[i$];
+ sum += aValue;
+ count++;
+ }
+
+ return sum / (double)count;
+ }
+
+ public double sqrt(double n) {
+ return sqrtService.sqrt(n);
+ }
+
+ public double sin(double angle) {
+ if (trig_metric.equalsIgnoreCase("DEGREES"))
+ angle = Math.toRadians(angle);
+ return Math.sin(angle);
+ }
+
+ public double cos(double angle) {
+ if (trig_metric.equalsIgnoreCase("DEGREES"))
+ angle = Math.toRadians(angle);
+ return Math.cos(angle);
+ }
+
+ public double tan(double angle) {
+ if (trig_metric.equalsIgnoreCase("DEGREES"))
+ angle = Math.toRadians(angle);
+ return Math.tan(angle);
+ }
+
+ public String getTrig_metric() {
+ return trig_metric;
+ }
+
+ @Property
+ public void setTrig_metric(String trig_metric) {
+ this.trig_metric = trig_metric;
+ }
+
+}
diff --git a/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SqrtService.java b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SqrtService.java
new file mode 100644
index 0000000000..d9027b5616
--- /dev/null
+++ b/branches/sca-java-M2/samples/standalone/calculator-combo/src/main/java/calculator/sci/SqrtService.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator.sci;
+
+/**
+ * Interface to calculate the square root
+ */
+public interface SqrtService {
+ public abstract double sqrt(double d);
+
+}