Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7f1a6a7d5f1bc95f45b2dbb8d2890f1fd1d62b10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.core;

import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugTarget;

/**
 * Default rule factory returns rules that serialzie access and modification of
 * debug elements.
 * 
 * @since 3.1
 */
public class DefaultDebugRuleFactory implements IDebugRuleFactory {
    
    private static IDebugRuleFactory fgDefault;
    
    class PessimisticRule implements ISchedulingRule {
        
        private IDebugElement fElement;
        
        PessimisticRule(IDebugElement element) {
            fElement = element;
        }

        /* (non-Javadoc)
         * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule)
         */
        public boolean contains(ISchedulingRule rule) {
            if (rule instanceof PessimisticRule) {
                return isSameTarget((PessimisticRule) rule, this);
            }
            return false;
        }

        /* (non-Javadoc)
         * @see org.eclipse.core.runtime.jobs.ISchedulingRule#isConflicting(org.eclipse.core.runtime.jobs.ISchedulingRule)
         */
        public boolean isConflicting(ISchedulingRule rule) {
            if (rule instanceof PessimisticRule) {
                return isSameTarget((PessimisticRule) rule, this);
            }
            return false;
        }
        
        private boolean isSameTarget(PessimisticRule a, PessimisticRule b) {
            IDebugTarget t1 = a.fElement.getDebugTarget();
            IDebugTarget t2 = b.fElement.getDebugTarget();
            return t1 != null && t1.equals(t2);
        }
        
    }
    
    public static IDebugRuleFactory getDefault() {
        if (fgDefault == null) {
            fgDefault = new DefaultDebugRuleFactory();
        }
        return fgDefault;
    }

    /**
     * Constucts a rule factory.
     */
    DefaultDebugRuleFactory() {
        super();
    }

    /* (non-Javadoc)
     * @see org.eclipse.debug.internal.core.IDebugRuleFactory#accessRule(org.eclipse.debug.core.model.IDebugElement)
     */
    public ISchedulingRule accessRule(IDebugElement debugElement) {
        return new PessimisticRule(debugElement);
    }

    /* (non-Javadoc)
     * @see org.eclipse.debug.internal.core.IDebugRuleFactory#modificationRule(org.eclipse.debug.core.model.IDebugElement)
     */
    public ISchedulingRule modificationRule(IDebugElement debugElement) {
        return new PessimisticRule(debugElement);
    }

}

Back to the top