001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.hivemind.impl;
016
017 import org.apache.commons.logging.Log;
018 import org.apache.commons.logging.LogFactory;
019 import org.apache.hivemind.ErrorLog;
020 import org.apache.hivemind.internal.ExtensionPoint;
021 import org.apache.hivemind.internal.Module;
022 import org.apache.hivemind.internal.Visibility;
023 import org.apache.hivemind.util.ToStringBuilder;
024
025 /**
026 * Base class for extension points; provides module, visibility and extensionPointId properties.
027 *
028 * @author Howard Lewis Ship
029 */
030 public abstract class AbstractExtensionPoint extends BaseLocatable implements ExtensionPoint
031 {
032 private Module _module;
033
034 private String _extensionPointId;
035
036 /** @since 1.1 */
037 private Visibility _visibility;
038
039 /** @since 1.1 */
040
041 private ErrorLog _errorLog;
042
043 public synchronized String toString()
044 {
045 ToStringBuilder builder = new ToStringBuilder(this);
046 builder.append("extensionPointId", _extensionPointId);
047 builder.append("visibility", _visibility);
048
049 extendDescription(builder);
050
051 return builder.toString();
052 }
053
054 /**
055 * Implemented in subclasses to provide details about subclass properties.
056 */
057 protected abstract void extendDescription(ToStringBuilder builder);
058
059 public void setExtensionPointId(String extensionPointId)
060 {
061 _extensionPointId = extensionPointId;
062 }
063
064 public String getExtensionPointId()
065 {
066 return _extensionPointId;
067 }
068
069 public void setModule(Module module)
070 {
071 _module = module;
072 }
073
074 public Module getModule()
075 {
076 return _module;
077 }
078
079 /**
080 * @since 1.1
081 */
082 public void setVisibility(Visibility visibility)
083 {
084 _visibility = visibility;
085 }
086
087 /**
088 * Returns true if the extension point is public, or the extgension point is visible to the
089 * module.
090 *
091 * @param module
092 * The module to validate visibility against, or null for no module ... such as when
093 * the application accesses an extension via {@link org.apache.hivemind.Registry}.
094 * @since 1.1
095 */
096 public boolean visibleToModule(Module module)
097 {
098 if (_visibility == Visibility.PUBLIC)
099 return true;
100
101 return _module.equals(module);
102 }
103
104 /** @since 1.1 */
105 public Log getLog()
106 {
107 return LogFactory.getLog(getExtensionPointId());
108 }
109
110 /** @since 1.1 */
111 public synchronized ErrorLog getErrorLog()
112 {
113 if (_errorLog == null)
114 _errorLog = new ErrorLogImpl(_module.getErrorHandler(), getLog());
115
116 return _errorLog;
117 }
118 }