| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| */ |
| |
| package org.eclipse.osbp.runtime.common.validation; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.osgi.framework.FrameworkUtil; |
| |
| // TODO: Auto-generated Javadoc |
| /** |
| * The Class Status. |
| */ |
| public class Status implements IStatus { |
| |
| /** The code. */ |
| private String code = ""; |
| |
| /** The bundle symbolic name. */ |
| private String bundleSymbolicName = ""; |
| |
| /** The severity. */ |
| private Severity severity; |
| |
| /** The message. */ |
| private String message = ""; |
| |
| /** The exception. */ |
| private Exception exception; |
| |
| /** The properties. */ |
| private Map<String, Object> properties; |
| |
| /** |
| * Instantiates a new status. |
| */ |
| public Status() { |
| |
| } |
| |
| /** |
| * Creates an OK status. |
| * |
| * @return the i status |
| */ |
| public static IStatus createOKStatus() { |
| Status status = new Status(); |
| status.severity = Severity.OK; |
| return status; |
| } |
| |
| /** |
| * Creates an CANCEL status. |
| * |
| * @return the i status |
| */ |
| public static IStatus createCancelStatus() { |
| Status status = new Status(); |
| status.severity = Severity.CANCEL; |
| return status; |
| } |
| |
| /** |
| * Creates an ERROR status. |
| * |
| * @return the i status |
| */ |
| public static IStatus createErrorStatus() { |
| Status status = new Status(); |
| status.severity = Severity.ERROR; |
| return status; |
| } |
| |
| /** |
| * Creates an ERROR status. |
| * |
| * @param e |
| * - the exception |
| * @return the i status |
| */ |
| public static IStatus createErrorStatus(Exception e) { |
| Status status = new Status(); |
| status.severity = Severity.ERROR; |
| status.exception = e; |
| return status; |
| } |
| |
| /** |
| * Creates a status for the given parameters. |
| * |
| * @param code |
| * - the unique message code (is unique in a bundle) |
| * @param clazz |
| * - the class that is contained in the bundle, that specifies |
| * the code |
| * @param severity |
| * - the serverity of the status |
| * @param message |
| * - the message of the status |
| * @return the i status |
| */ |
| public static IStatus createStatus(String code, Class<?> clazz, |
| Severity severity, String message) { |
| Status status = new Status(); |
| status.code = code; |
| status.bundleSymbolicName = getBundleSymbolicName(clazz); |
| status.severity = severity; |
| status.message = message; |
| return status; |
| } |
| |
| /** |
| * Creates the status. |
| * |
| * @param code |
| * - the unique message code (is unique in a bundle) |
| * @param clazz |
| * - the class that is contained in the bundle, that specifies |
| * the code |
| * @param severity |
| * - the serverity of the status |
| * @param message |
| * - the message of the status |
| * @param exception |
| * - the thrown exception |
| * @return the i status |
| */ |
| public static IStatus createStatus(String code, Class<?> clazz, |
| Severity severity, String message, Exception exception) { |
| Status status = new Status(); |
| status.code = code; |
| status.bundleSymbolicName = getBundleSymbolicName(clazz); |
| status.severity = severity; |
| status.message = message; |
| status.exception = exception; |
| return status; |
| } |
| |
| /** |
| * Creates the status. |
| * |
| * @param code |
| * - the unique message code (is unique in a bundle) |
| * @param clazz |
| * - the class that is contained in the bundle, that specifies |
| * the code |
| * @param severity |
| * - the serverity of the status |
| * @param exception |
| * - the thrown exception |
| * @return the i status |
| */ |
| public static IStatus createStatus(String code, Class<?> clazz, |
| Severity severity, Exception exception) { |
| Status status = new Status(); |
| status.code = code; |
| status.bundleSymbolicName = getBundleSymbolicName(clazz); |
| status.severity = severity; |
| status.exception = exception; |
| return status; |
| } |
| |
| /** |
| * Returns the bundle symbolic name for the given class. |
| * |
| * @param clazz |
| * the clazz |
| * @return the bundle symbolic name |
| */ |
| private static String getBundleSymbolicName(Class<?> clazz) { |
| if (clazz == null || FrameworkUtil.getBundle(clazz) == null) { |
| return "no bundle available"; |
| } |
| return FrameworkUtil.getBundle(clazz).getSymbolicName(); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#getId() |
| */ |
| @Override |
| public String getId() { |
| return String.format("%s.%s", getBundleSymblicName(), getCode()); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#getCode() |
| */ |
| @Override |
| public String getCode() { |
| return code; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#getBundleSymblicName() |
| */ |
| @Override |
| public String getBundleSymblicName() { |
| return bundleSymbolicName; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#getSeverity() |
| */ |
| @Override |
| public Severity getSeverity() { |
| return severity; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#getMessage() |
| */ |
| @Override |
| public String getMessage() { |
| return message; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#getException() |
| */ |
| @Override |
| public Exception getException() { |
| return exception; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#isOK() |
| */ |
| @Override |
| public boolean isOK() { |
| return severity == Severity.OK || severity == Severity.INFO; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#isInfo() |
| */ |
| @Override |
| public boolean isInfo() { |
| return severity == Severity.INFO; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#isWarning() |
| */ |
| @Override |
| public boolean isWarning() { |
| return severity == Severity.WARNING; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#isError() |
| */ |
| @Override |
| public boolean isError() { |
| return severity == Severity.ERROR; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#isCancel() |
| */ |
| @Override |
| public boolean isCancel() { |
| return severity == Severity.CANCEL; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#putProperty(java.lang.String, java.lang.Object) |
| */ |
| @Override |
| public void putProperty(String key, Object value) { |
| if (properties == null) { |
| properties = new HashMap<String, Object>(); |
| } |
| properties.put(key, value); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#containsProperty(java.lang.String) |
| */ |
| @Override |
| public boolean containsProperty(String key) { |
| if (properties == null) { |
| return false; |
| } |
| return properties.containsKey(key); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.validation.IStatus#getProperty(java.lang.String) |
| */ |
| @Override |
| public Object getProperty(String key) { |
| if (properties == null) { |
| return null; |
| } |
| return properties.get(key); |
| } |
| |
| } |