KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > registry > SpiUtils


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
20 package org.netbeans.spi.registry;
21
22 import org.netbeans.api.registry.*;
23 import org.netbeans.modules.registry.ApiContextFactory;
24 import org.netbeans.modules.registry.mergedctx.RootContextImpl;
25
26 /**
27  * This class contains helper static methods intended for use by SPI clients only;
28  * normal API clients which do not implement SPI contexts will not need them.
29  *
30  * @author David Konecny
31  */

32 public final class SpiUtils {
33
34     private SpiUtils() {
35     }
36
37     /**
38      * Create API context for the given SPI context.
39      *
40      * @return instance of Context created for the given BasicContext
41      */

42     public static Context createContext(BasicContext ctx) {
43         return ApiContextFactory.DEFAULT.createContext(ctx);
44     }
45     
46     /**
47      * Create ContextException instance.
48      *
49      * @param ctx context; should be specified, but null is acceptable
50      * @param str optional exception description
51      * @return instance of ContextException
52      */

53     public static ContextException createContextException(BasicContext ctx, String JavaDoc str) {
54         return ApiContextFactory.DEFAULT.createContextException(ctx, str);
55     }
56
57     /**
58      * Create SubcontextEvent instance.
59      *
60      * @param source context; cannot be null
61      * @param subcontextName name of created or deleted subcontext; cannot be null
62      * @param type type; see {@link org.netbeans.api.registry.SubcontextEvent} for concrete values
63      * @return instance of SubcontextEvent
64      */

65     public static SubcontextEvent createSubcontextEvent(BasicContext source, String JavaDoc subcontextName, int type) {
66         return ApiContextFactory.DEFAULT.createSubcontextEvent(source, subcontextName, type);
67     }
68     
69     /**
70      * Create BindingEvent instance.
71      *
72      * @param source context; cannot be null
73      * @param bindingName name of the affected binding; can be null if accurate information
74      * about change is not available
75      * @param type type; see {@link org.netbeans.api.registry.BindingEvent} for concrete values
76      * @return instance of BindingEvent
77      */

78     public static BindingEvent createBindingEvent(BasicContext source, String JavaDoc bindingName, int type) {
79         return ApiContextFactory.DEFAULT.createBindingEvent(source, bindingName, type);
80     }
81     
82     /**
83      * Create AttributeEvent instance.
84      *
85      * @param source context; cannot be null
86      * @param bindingName name of the binding which attribute was changed
87      * or null for the context attribute
88      * @param attributeName attribute name; can be null if accurate information
89      * about change is not available
90      * @param type type; see {@link org.netbeans.api.registry.AttributeEvent} for concrete values
91      * @return instance of AttributeEvent
92      */

93     public static AttributeEvent createAttributeEvent(BasicContext source, String JavaDoc bindingName, String JavaDoc attributeName, int type) {
94         return ApiContextFactory.DEFAULT.createAttributeEvent(source, bindingName, attributeName, type);
95     }
96     
97     /**
98      * Creates new instance of <tt>ObjectRef</tt>.
99      * @param rootContext root context. See {@link Context#getRootContext}
100      * @param absoluteContextName absolute name of context relative to root context. See {@link Context#getAbsoluteContextName}
101      * @param bindingName name of binding
102      * @return new instance of ObjectRef
103      * @since 1.7
104      */

105     public static ObjectRef createObjectRef (BasicContext rootContext, String JavaDoc absoluteContextName, String JavaDoc bindingName) {
106         return ApiContextFactory.DEFAULT.createObjectRef(rootContext, absoluteContextName, bindingName);
107     }
108
109     /**
110      * Creates new instance of <tt>ObjectRef</tt>.
111      * @param context context
112      * @param bindingName name of binding
113      * @return new instance of ObjectRef
114      */

115     public static ObjectRef createObjectRef (BasicContext context, String JavaDoc bindingName) {
116         return ApiContextFactory.DEFAULT.createObjectRef(context, bindingName);
117     }
118         
119     /**
120       * Returns context that merges all its delegates. See JavaDoc overview for more details.
121       * @param mergeProvider provides delegates; see {@link MergedContextProvider}
122       * @return merged context
123       * @since 1.6
124       */

125      public static BasicContext merge (MergedContextProvider mergeProvider) {
126          return RootContextImpl.create(mergeProvider);
127      }
128 }
129
Popular Tags