KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.List JavaDoc;
18
19 import org.apache.hivemind.InterceptorStack;
20 import org.apache.hivemind.ServiceInterceptorFactory;
21 import org.apache.hivemind.internal.Module;
22 import org.apache.hivemind.internal.ServiceInterceptorContribution;
23 import org.apache.hivemind.internal.ServicePoint;
24 import org.apache.hivemind.schema.Schema;
25 import org.apache.hivemind.util.ToStringBuilder;
26
27 /**
28  * Implementation of {@link org.apache.hivemind.internal.ServiceInterceptorContribution}.
29  *
30  * @author Howard Lewis Ship
31  */

32
33 public final class ServiceInterceptorContributionImpl extends BaseLocatable implements
34         ServiceInterceptorContribution
35 {
36     private String JavaDoc _factoryServiceId;
37
38     private Module _contributingModule;
39
40     private List JavaDoc _parameters;
41
42     private List JavaDoc _convertedParameters;
43
44     private ServiceInterceptorFactory _factory;
45
46     private String JavaDoc _precedingInterceptorIds;
47
48     private String JavaDoc _followingInterceptorIds;
49
50     private String JavaDoc _name;
51     
52     public String JavaDoc toString()
53     {
54         ToStringBuilder builder = new ToStringBuilder(this);
55         builder.append("factoryServiceId", _factoryServiceId);
56         builder.append("parameters", _parameters);
57         builder.append("precedingInterceptorIds", _precedingInterceptorIds);
58         builder.append("followingInterceptorIds", _followingInterceptorIds);
59         builder.append("name", _name );
60         return builder.toString();
61     }
62
63     
64     /**
65      * @return Returns the name.
66      */

67     public String JavaDoc getName()
68     {
69         if( _name == null )
70         {
71             return getFactoryServiceId();
72         }
73         return _name;
74     }
75     
76     public void setName( String JavaDoc name )
77     {
78         _name = name;
79     }
80     
81     public String JavaDoc getFactoryServiceId()
82     {
83         return _factoryServiceId;
84     }
85
86     public void setFactoryServiceId(String JavaDoc string)
87     {
88         _factoryServiceId = string;
89     }
90
91     public void createInterceptor(InterceptorStack stack)
92     {
93         setup();
94
95         _factory.createInterceptor(stack, _contributingModule, _convertedParameters);
96     }
97
98     private synchronized void setup()
99     {
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 JavaDoc list)
124     {
125         _parameters = list;
126     }
127
128     public String JavaDoc getFollowingInterceptorIds()
129     {
130         return _followingInterceptorIds;
131     }
132
133     public String JavaDoc getPrecedingInterceptorIds()
134     {
135         return _precedingInterceptorIds;
136     }
137
138     public void setFollowingInterceptorIds(String JavaDoc string)
139     {
140         _followingInterceptorIds = string;
141     }
142
143     public void setPrecedingInterceptorIds(String JavaDoc string)
144     {
145         _precedingInterceptorIds = string;
146     }
147
148 }
Popular Tags