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 java.util.List;
018
019 import org.apache.hivemind.InterceptorStack;
020 import org.apache.hivemind.ServiceInterceptorFactory;
021 import org.apache.hivemind.internal.Module;
022 import org.apache.hivemind.internal.ServiceInterceptorContribution;
023 import org.apache.hivemind.internal.ServicePoint;
024 import org.apache.hivemind.schema.Schema;
025 import org.apache.hivemind.util.ToStringBuilder;
026
027 /**
028 * Implementation of {@link org.apache.hivemind.internal.ServiceInterceptorContribution}.
029 *
030 * @author Howard Lewis Ship
031 */
032
033 public final class ServiceInterceptorContributionImpl extends BaseLocatable implements
034 ServiceInterceptorContribution
035 {
036 private String _factoryServiceId;
037
038 private Module _contributingModule;
039
040 private List _parameters;
041
042 private List _convertedParameters;
043
044 private ServiceInterceptorFactory _factory;
045
046 private String _precedingInterceptorIds;
047
048 private String _followingInterceptorIds;
049
050 private String _name;
051
052 public String toString()
053 {
054 ToStringBuilder builder = new ToStringBuilder(this);
055 builder.append("factoryServiceId", _factoryServiceId);
056 builder.append("parameters", _parameters);
057 builder.append("precedingInterceptorIds", _precedingInterceptorIds);
058 builder.append("followingInterceptorIds", _followingInterceptorIds);
059 builder.append("name", _name );
060 return builder.toString();
061 }
062
063
064 /**
065 * @return Returns the name.
066 */
067 public String getName()
068 {
069 if( _name == null )
070 {
071 return getFactoryServiceId();
072 }
073 return _name;
074 }
075
076 public void setName( String name )
077 {
078 _name = name;
079 }
080
081 public String getFactoryServiceId()
082 {
083 return _factoryServiceId;
084 }
085
086 public void setFactoryServiceId(String string)
087 {
088 _factoryServiceId = string;
089 }
090
091 public void createInterceptor(InterceptorStack stack)
092 {
093 setup();
094
095 _factory.createInterceptor(stack, _contributingModule, _convertedParameters);
096 }
097
098 private synchronized void setup()
099 {
100 if (_factory == null)
101 {
102 ServicePoint factoryPoint = _contributingModule.getServicePoint(_factoryServiceId);
103
104 _factory = (ServiceInterceptorFactory) factoryPoint
105 .getService(ServiceInterceptorFactory.class);
106
107 Schema schema = factoryPoint.getParametersSchema();
108
109 SchemaProcessorImpl processor = new SchemaProcessorImpl(factoryPoint.getErrorLog(),
110 schema);
111
112 processor.process(_parameters, _contributingModule);
113
114 _convertedParameters = processor.getElements();
115 }
116 }
117
118 public void setContributingModule(Module module)
119 {
120 _contributingModule = module;
121 }
122
123 public void setParameters(List list)
124 {
125 _parameters = list;
126 }
127
128 public String getFollowingInterceptorIds()
129 {
130 return _followingInterceptorIds;
131 }
132
133 public String getPrecedingInterceptorIds()
134 {
135 return _precedingInterceptorIds;
136 }
137
138 public void setFollowingInterceptorIds(String string)
139 {
140 _followingInterceptorIds = string;
141 }
142
143 public void setPrecedingInterceptorIds(String string)
144 {
145 _precedingInterceptorIds = string;
146 }
147
148 }