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 015package org.apache.hivemind.parse; 016 017import java.util.ArrayList; 018import java.util.List; 019 020import org.apache.hivemind.util.ToStringBuilder; 021 022/** 023 * Base class for {@link org.apache.hivemind.parse.ServicePointDescriptor} and 024 * {@link org.apache.hivemind.parse.ImplementationDescriptor}. 025 * 026 * 027 * @author Howard Lewis Ship 028 */ 029public abstract class AbstractServiceDescriptor extends BaseAnnotationHolder 030{ 031 private InstanceBuilder _instanceBuilder; 032 private List _interceptors; 033 034 035 public String toString() 036 { 037 ToStringBuilder builder = new ToStringBuilder(this); 038 039 extendDescription(builder); 040 041 builder.append("instanceBuilder", _instanceBuilder); 042 builder.append("interceptors", _interceptors); 043 044 return builder.toString(); 045 } 046 047 /** 048 * Implemented in subclasses to provide details about the instance. 049 */ 050 protected abstract void extendDescription(ToStringBuilder builder); 051 052 public InstanceBuilder getInstanceBuilder() 053 { 054 return _instanceBuilder; 055 } 056 057 /** 058 * A service extension may contribute one instance builder. 059 */ 060 public void setInstanceBuilder(InstanceBuilder descriptor) 061 { 062 _instanceBuilder = descriptor; 063 } 064 065 public void addInterceptor(InterceptorDescriptor interceptor) 066 { 067 if (_interceptors == null) 068 _interceptors = new ArrayList(); 069 070 _interceptors.add(interceptor); 071 } 072 073 /** 074 * Returns a list of {@link InterceptorDescriptor}. May 075 * return null. The caller should not modify the returned list. 076 */ 077 public List getInterceptors() 078 { 079 return _interceptors; 080 } 081 082}