KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > internal > adaptor > MessageHelper


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.runtime.internal.adaptor;
12
13 import java.util.Date JavaDoc;
14 import org.eclipse.osgi.service.resolver.*;
15 import org.eclipse.osgi.util.NLS;
16
17 /**
18  * @since 3.3
19  */

20 public class MessageHelper {
21     public static String JavaDoc getResolutionFailureMessage(VersionConstraint unsatisfied) {
22         if (unsatisfied.isResolved())
23             throw new IllegalArgumentException JavaDoc();
24         if (unsatisfied instanceof ImportPackageSpecification)
25             return NLS.bind(EclipseAdaptorMsg.ECLIPSE_MISSING_IMPORTED_PACKAGE, toString(unsatisfied));
26         else if (unsatisfied instanceof BundleSpecification)
27             if (((BundleSpecification) unsatisfied).isOptional())
28                 return NLS.bind(EclipseAdaptorMsg.ECLIPSE_MISSING_OPTIONAL_REQUIRED_BUNDLE, toString(unsatisfied));
29             else
30                 return NLS.bind(EclipseAdaptorMsg.ECLIPSE_MISSING_REQUIRED_BUNDLE, toString(unsatisfied));
31         else
32             return NLS.bind(EclipseAdaptorMsg.ECLIPSE_MISSING_HOST, toString(unsatisfied));
33     }
34
35     /**
36      * Print a debug message to the console.
37      * Pre-pend the message with the current date and the name of the current thread.
38      */

39     public static void debug(String JavaDoc message) {
40         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
41         buffer.append(new Date JavaDoc(System.currentTimeMillis()));
42         buffer.append(" - ["); //$NON-NLS-1$
43
buffer.append(Thread.currentThread().getName());
44         buffer.append("] "); //$NON-NLS-1$
45
buffer.append(message);
46         System.out.println(buffer.toString());
47     }
48
49     private static String JavaDoc toString(VersionConstraint constraint) {
50         org.eclipse.osgi.service.resolver.VersionRange versionRange = constraint.getVersionRange();
51         if (versionRange == null)
52             return constraint.getName();
53         return constraint.getName() + '_' + versionRange;
54     }
55
56 }
57
Popular Tags