summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.5.1/modules/monitor
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-08-13 14:52:13 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-08-13 14:52:13 +0000
commit8d663999600764840aece20d666563d3ba3cdea3 (patch)
tree928ee2ddf235defe549d58318d3fe53c4ac559b3 /branches/sca-java-1.5.1/modules/monitor
parent97346923d491cb9bef32b442afe64701a944e80c (diff)
TUSCANY-3213 - move ProblemImpl from assembly.builder.impl to monitor.impl and extend the Monitor interface to allow problems to be created without needing to access and implementation package
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@803910 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.5.1/modules/monitor')
-rw-r--r--branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java124
-rw-r--r--branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java18
-rw-r--r--branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java132
3 files changed, 269 insertions, 5 deletions
diff --git a/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java b/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java
index c16140213d..6ee6e705cc 100644
--- a/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java
+++ b/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java
@@ -20,25 +20,143 @@
package org.apache.tuscany.sca.monitor;
import java.util.List;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
/**
* A monitor for the watching for validation problems
*
* @version $Rev$ $Date$
*/
-public interface Monitor {
+public abstract class Monitor {
/**
* Reports a build problem.
*
* @param problem
*/
- void problem(Problem problem);
+ public abstract void problem(Problem problem);
/**
* Returns a list of reported problems.
*
* @return the list of problems. The list may be empty
*/
- List<Problem> getProblems();
+ public abstract List<Problem> getProblems();
+
+ /**
+ * Create a new problem.
+ *
+ * @param sourceClassName the class name reporting the problem
+ * @param bundleName the name of the message bundle to use
+ * @param severity the severity of the problem
+ * @param problemObject the model object for which the problem is being reported
+ * @param messageId the id of the problem message
+ * @param cause the exception which caused the problem
+ * @return
+ */
+ public abstract Problem createProblem(String sourceClassName,
+ String bundleName,
+ Severity severity,
+ Object problemObject,
+ String messageId,
+ Exception cause);
+
+ /**
+ * Create a new problem.
+ *
+ * @param sourceClassName the class name reporting the problem
+ * @param bundleName the name of the message bundle to use
+ * @param severity the severity of the problem
+ * @param problemObject the model object for which the problem is being reported
+ * @param messageId the id of the problem message
+ * @param messageParams the parameters of the problem message
+ * @return
+ */
+ public abstract Problem createProblem(String sourceClassName,
+ String bundleName,
+ Severity severity,
+ Object problemObject,
+ String messageId,
+ Object... messageParams);
+
+ /**
+ * A utility function for raising a warning. It creates the problem and
+ * adds it to the monitor
+ *
+ * @param monitor
+ * @param reportingObject
+ * @param messageBundle
+ * @param messageId
+ * @param messageParameters
+ */
+ public static void warning (Monitor monitor,
+ Object reportingObject,
+ String messageBundle,
+ String messageId,
+ String... messageParameters){
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(reportingObject.getClass().getName(),
+ messageBundle,
+ Severity.WARNING,
+ null,
+ messageId,
+ (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * A utility function for raising an error. It creates the problem and
+ * adds it to the monitor
+ *
+ * @param monitor
+ * @param reportingObject
+ * @param messageBundle
+ * @param messageId
+ * @param messageParameters
+ */
+ public static void error (Monitor monitor,
+ Object reportingObject,
+ String messageBundle,
+ String messageId,
+ String... messageParameters){
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(reportingObject.getClass().getName(),
+ messageBundle,
+ Severity.ERROR,
+ null,
+ messageId,
+ (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * A utility function for raising an error. It creates the problem and
+ * adds it to the monitor
+ *
+ * @param monitor
+ * @param reportingObject
+ * @param messageBundle
+ * @param messageId
+ * @param exception
+ */
+ public static void error (Monitor monitor,
+ Object reportingObject,
+ String messageBundle,
+ String messageId,
+ Exception cause){
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(reportingObject.getClass().getName(),
+ messageBundle,
+ Severity.ERROR,
+ null,
+ messageId,
+ cause);
+ monitor.problem(problem);
+ }
+ }
}
diff --git a/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java b/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java
index b98f29d4dd..7df34d0c74 100644
--- a/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java
+++ b/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java
@@ -34,7 +34,7 @@ import org.apache.tuscany.sca.monitor.Problem.Severity;
*
* @version $Rev$ $Date$
*/
-public class DefaultMonitorImpl implements Monitor {
+public class DefaultMonitorImpl extends Monitor {
private static final Logger logger = Logger.getLogger(DefaultMonitorImpl.class.getName());
// Cache all the problem reported to monitor for further analysis
@@ -76,6 +76,20 @@ public class DefaultMonitorImpl implements Monitor {
return problemCache;
}
+ public Problem createProblem(String sourceClassName, String bundleName,
+ Severity severity, Object problemObject, String messageId,
+ Exception cause) {
+ return new ProblemImpl(sourceClassName, bundleName, severity,
+ problemObject, messageId, cause);
+ }
+
+ public Problem createProblem(String sourceClassName, String bundleName,
+ Severity severity, Object problemObject, String messageId,
+ Object... messageParams) {
+ return new ProblemImpl(sourceClassName, bundleName, severity,
+ problemObject, messageId, messageParams);
+ }
+
public Problem getLastLoggedProblem(){
return problemCache.get(problemCache.size() - 1);
}
@@ -98,5 +112,5 @@ public class DefaultMonitorImpl implements Monitor {
}
return null;
- }
+ }
}
diff --git a/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java b/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java
new file mode 100644
index 0000000000..5a0aaeddd0
--- /dev/null
+++ b/branches/sca-java-1.5.1/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java
@@ -0,0 +1,132 @@
+/*
+ * 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 org.apache.tuscany.sca.monitor.impl;
+
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import java.util.logging.SimpleFormatter;
+
+import org.apache.tuscany.sca.monitor.Problem;
+
+/**
+ * Reports a composite assembly problem.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProblemImpl implements Problem {
+
+ private String sourceClassName;
+ private String bundleName;
+ private Severity severity;
+ private Object problemObject;
+ private String messageId;
+ private Object[] messageParams;
+ private Exception cause;
+
+ /**
+ * Construct a new problem
+ *
+ * @param sourceClassName the class name reporting the problem
+ * @param bundleName the name of the message bundle to use
+ * @param severity the severity of the problem
+ * @param problemObject the model object for which the problem is being reported
+ * @param messageId the id of the problem message
+ * @param messageParams the parameters of the problem message
+ */
+ public ProblemImpl(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Object... messageParams ) {
+ this.sourceClassName = sourceClassName;
+ this.bundleName = bundleName;
+ this.severity = severity;
+ this.problemObject = problemObject;
+ this.messageId = messageId;
+ this.messageParams = messageParams;
+ }
+
+ /**
+ * Construct a new problem
+ *
+ * @param sourceClassName the class name reporting the problem
+ * @param bundleName the name of the message bundle to use
+ * @param severity the severity of the problem
+ * @param problemObject the model object for which the problem is being reported
+ * @param messageId the id of the problem message
+ * @param cause the exception which caused the problem
+ */
+ public ProblemImpl(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Exception cause) {
+ this.sourceClassName = sourceClassName;
+ this.bundleName = bundleName;
+ this.severity = severity;
+ this.problemObject = problemObject;
+ this.messageId = messageId;
+ this.cause = cause;
+ }
+
+ public String getSourceClassName() {
+ return sourceClassName;
+ }
+
+ public String getBundleName() {
+ return bundleName;
+ }
+
+ public Severity getSeverity() {
+ return severity;
+ }
+
+ public Object getProblemObject() {
+ return problemObject;
+ }
+
+ public String getMessageId() {
+ return messageId;
+ }
+
+ public Object[] getMessageParams() {
+ return messageParams;
+ }
+
+ public Exception getCause() {
+ return cause;
+ }
+
+ @Override
+ public String toString() {
+ Logger logger = Logger.getLogger(sourceClassName, bundleName);
+
+ LogRecord record = new LogRecord(Level.INFO, messageId);
+
+ if (cause == null){
+ record.setParameters(messageParams);
+
+ } else {
+ Object[] params = new String[1];
+ params[0] = cause.toString();
+ record.setParameters(params);
+ }
+ record.setResourceBundle(logger.getResourceBundle());
+ record.setSourceClassName(sourceClassName);
+
+ Formatter formatter = new SimpleFormatter();
+
+ return formatter.formatMessage(record);
+ }
+}