KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > registry > mergedctx > MaskUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.registry.mergedctx;
20
21 import org.netbeans.api.registry.ContextException;
22 import org.netbeans.spi.registry.BasicContext;
23
24 final class MaskUtils {
25     private static final String JavaDoc MASK_EXTENSION = "_mergehidden";//NOI18N
26

27
28     static boolean existMaskForCtx(/*MergedDelegates delegates*/final BasicContext activeCtx, final String JavaDoc subcontextName) {
29         //final BasicContext activeCtx = delegates.getActiveDelegate(false);
30
if (activeCtx == null) return false;
31         return (activeCtx.getSubcontextNames().contains(subcontextName + MASK_EXTENSION));
32     }
33
34     static boolean existMaskForBinding(final BasicContext activeCtx, final String JavaDoc bindingName) {
35         if (activeCtx == null) return false;
36         return (activeCtx.getBindingNames().contains((bindingName + MASK_EXTENSION)));//lookupObject(bindingName + MASK_EXTENSION) != null);
37
}
38
39     static boolean existMaskForAttributes(final BasicContext activeCtx, final String JavaDoc bindingName, final String JavaDoc attributeName) {
40         if (activeCtx == null) return false;
41         return (activeCtx.getAttributeNames(bindingName).contains(attributeName + MASK_EXTENSION));
42     }
43
44     static boolean isMaskForCtxName(final String JavaDoc contextName) {
45         return contextName.endsWith(MASK_EXTENSION);
46     }
47
48     static boolean isMaskForBindingName(final String JavaDoc bindingName) {
49         return bindingName.endsWith(MASK_EXTENSION);
50     }
51
52     static boolean isMaskForAttributeName(final String JavaDoc attributeName) {
53         return attributeName.endsWith(MASK_EXTENSION);
54
55     }
56
57     static void createMaskForCtx(final BasicContext activeCtx, final String JavaDoc subcontextName) throws ContextException {
58         if (!existMaskForCtx(activeCtx, subcontextName))
59             activeCtx.createSubcontext(subcontextName + MASK_EXTENSION);
60     }
61
62     static void createMaskForBinding(final BasicContext activeCtx, final String JavaDoc bindingName) throws ContextException {
63         if (!existMaskForBinding(activeCtx, bindingName))
64             activeCtx.bindObject(bindingName + MASK_EXTENSION, "mask"); //NOI18N
65
}
66
67     static void createMaskForAttributes(final BasicContext activeCtx, final String JavaDoc bindingName, final String JavaDoc attributeName) throws ContextException {
68         if (!existMaskForAttributes(activeCtx, bindingName, attributeName))
69             activeCtx.setAttribute(bindingName, attributeName + MASK_EXTENSION, "mask");//NOI18N
70
}
71
72     static void deleteMaskForCtx(final BasicContext activeCtx, final String JavaDoc subcontextName) throws ContextException {
73         if (activeCtx == null) return;
74
75         if (existMaskForCtx(activeCtx, subcontextName))
76             activeCtx.destroySubcontext(subcontextName + MASK_EXTENSION);
77     }
78
79     static void deleteMaskForBinding(final BasicContext activeCtx, final String JavaDoc bindingName) throws ContextException {
80         if (activeCtx == null) return;
81
82         if (existMaskForBinding(activeCtx, bindingName))
83             activeCtx.bindObject(bindingName + MASK_EXTENSION, null);
84     }
85
86     static void deleteMaskForAttributes(final BasicContext activeCtx, final String JavaDoc bindingName, final String JavaDoc attributeName) throws ContextException {
87         if (activeCtx == null) return;
88
89         if (existMaskForAttributes(activeCtx, bindingName, attributeName))
90             activeCtx.setAttribute(bindingName, attributeName + MASK_EXTENSION, null);
91     }
92
93 }
94
Popular Tags