KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > Policy


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.team.internal.ccvs.core;
12
13
14 import java.io.PrintStream JavaDoc;
15 import java.lang.reflect.Field JavaDoc;
16
17 import org.eclipse.core.runtime.*;
18 import org.eclipse.team.internal.core.InfiniteSubProgressMonitor;
19
20 public class Policy {
21     public static PrintStream JavaDoc recorder;
22     
23     //debug constants
24
public static boolean DEBUG_METAFILE_CHANGES = false;
25     public static boolean DEBUG_CVS_PROTOCOL = false;
26     public static boolean DEBUG_THREADING = false;
27     public static boolean DEBUG_DIRTY_CACHING = false;
28     public static boolean DEBUG_SYNC_CHANGE_EVENTS = false;
29
30     static {
31         //init debug options
32
if (CVSProviderPlugin.getPlugin().isDebugging()) {
33             DEBUG_METAFILE_CHANGES = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/metafiles"));//$NON-NLS-1$ //$NON-NLS-2$
34
DEBUG_CVS_PROTOCOL = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/cvsprotocol"));//$NON-NLS-1$ //$NON-NLS-2$
35
DEBUG_THREADING = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/threading"));//$NON-NLS-1$ //$NON-NLS-2$
36
DEBUG_DIRTY_CACHING = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/dirtycaching"));//$NON-NLS-1$ //$NON-NLS-2$
37
DEBUG_SYNC_CHANGE_EVENTS = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/syncchangeevents"));//$NON-NLS-1$ //$NON-NLS-2$
38
}
39     }
40
41     /**
42      * Progress monitor helpers
43      */

44     public static void checkCanceled(IProgressMonitor monitor) {
45         if (monitor.isCanceled())
46             throw new OperationCanceledException();
47     }
48     public static IProgressMonitor monitorFor(IProgressMonitor monitor) {
49         if (monitor == null)
50             return new NullProgressMonitor();
51         return monitor;
52     }
53     
54     public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) {
55         if (monitor == null)
56             return new NullProgressMonitor();
57         if (monitor instanceof NullProgressMonitor)
58             return monitor;
59         return new SubProgressMonitor(monitor, ticks);
60     }
61     
62     public static IProgressMonitor infiniteSubMonitorFor(IProgressMonitor monitor, int ticks) {
63         if (monitor == null)
64             return new NullProgressMonitor();
65         if (monitor instanceof NullProgressMonitor)
66             return monitor;
67         return new InfiniteSubProgressMonitor(monitor, ticks);
68     }
69     
70     public static boolean isDebugProtocol() {
71         return DEBUG_CVS_PROTOCOL || recorder != null;
72     }
73     
74     public static void printProtocolLine(String JavaDoc line) {
75         printProtocol(line, true);
76     }
77
78     public static void printProtocol(String JavaDoc string, boolean newLine) {
79         if (DEBUG_CVS_PROTOCOL) {
80             System.out.print(string);
81             if (newLine) {
82                 System.out.println();
83             }
84         }
85         if (recorder != null) {
86             recorder.print(string);
87             if (newLine) {
88                 recorder.println();
89             }
90         }
91     }
92     
93     public static String JavaDoc getMessage(String JavaDoc key) {
94         try {
95             Field JavaDoc f = CVSMessages.class.getDeclaredField(key);
96             Object JavaDoc o = f.get(null);
97             if (o instanceof String JavaDoc)
98                 return (String JavaDoc)o;
99         } catch (SecurityException JavaDoc e) {
100         } catch (NoSuchFieldException JavaDoc e) {
101         } catch (IllegalArgumentException JavaDoc e) {
102         } catch (IllegalAccessException JavaDoc e) {
103         }
104         return null;
105     }
106 }
107
Popular Tags