KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > impl > AbstractExtensionPoint


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.impl;
16
17 import org.apache.commons.logging.Log;
18 import org.apache.commons.logging.LogFactory;
19 import org.apache.hivemind.ErrorLog;
20 import org.apache.hivemind.Location;
21 import org.apache.hivemind.definition.ExtensionPointDefinition;
22 import org.apache.hivemind.definition.Visibility;
23 import org.apache.hivemind.internal.ExtensionPoint;
24 import org.apache.hivemind.internal.Module;
25 import org.apache.hivemind.util.ToStringBuilder;
26
27 /**
28  * Base class for extension points; provides module, visibility and extensionPointId properties.
29  *
30  * @author Howard Lewis Ship
31  */

32 /**
33  * @author Huegen
34  */

35 public abstract class AbstractExtensionPoint extends BaseLocatable implements ExtensionPoint
36 {
37     private ExtensionPointDefinition _definition;
38
39     private Module _module;
40
41     /** @since 1.1 */
42
43     private ErrorLog _errorLog;
44     
45     /**
46      * @param definition the definition of this extension point
47      */

48     public AbstractExtensionPoint(Module module, ExtensionPointDefinition definition)
49     {
50         _module = module;
51         _definition = definition;
52     }
53     
54     public synchronized String JavaDoc toString()
55     {
56         ToStringBuilder builder = new ToStringBuilder(this);
57         builder.append("extensionPointId", getExtensionPointId());
58         builder.append("visibility", getVisibility());
59
60         extendDescription(builder);
61
62         return builder.toString();
63     }
64
65     /**
66      * Implemented in subclasses to provide details about subclass properties.
67      */

68     protected abstract void extendDescription(ToStringBuilder builder);
69
70     public Visibility getVisibility()
71     {
72         return _definition.getVisibility();
73     }
74     
75     public Location getLocation()
76     {
77         return _definition.getLocation();
78     }
79     
80     public String JavaDoc getExtensionPointId()
81     {
82         return _module.getModuleId() + "." + _definition.getId();
83     }
84
85     public Module getModule()
86     {
87         return _module;
88     }
89
90     /**
91      * Returns true if the extension point is public, or the extgension point is visible to the
92      * module.
93      *
94      * @param module
95      * The module to validate visibility against, or null for no module ... such as when
96      * the application accesses an extension via {@link org.apache.hivemind.Registry}.
97      * @since 1.1
98      */

99     public boolean visibleToModule(Module module)
100     {
101         if (getVisibility() == Visibility.PUBLIC)
102             return true;
103
104         return _module.equals(module);
105     }
106
107     /** @since 1.1 */
108     public Log getLog()
109     {
110         return LogFactory.getLog(getExtensionPointId());
111     }
112
113     /** @since 1.1 */
114     public synchronized ErrorLog getErrorLog()
115     {
116         if (_errorLog == null)
117             _errorLog = new ErrorLogImpl(_module.getErrorHandler(), getLog());
118
119         return _errorLog;
120     }
121
122     protected ExtensionPointDefinition getDefinition()
123     {
124         return _definition;
125     }
126     
127
128 }
Popular Tags