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.service.impl;
016
017import java.util.ArrayList;
018import java.util.HashMap;
019import java.util.Iterator;
020import java.util.List;
021import java.util.Map;
022
023import org.apache.hivemind.ServiceImplementationFactoryParameters;
024import org.apache.hivemind.impl.BaseLocatable;
025
026/**
027 * Parameter object used with {@link org.apache.hivemind.service.impl.BuilderFactory}.
028 * 
029 * @author Howard Lewis Ship
030 */
031public class BuilderParameter extends BaseLocatable
032{
033    private String _className;
034
035    private List _properties = new ArrayList();
036
037    private List _parameters = new ArrayList();
038
039    /** @since 1.1 */
040    private Map _typeFacetMap = new HashMap();
041
042    private List _events = new ArrayList();
043
044    private String _initializeMethod;
045
046    private boolean _autowireServices;
047
048    public String getClassName()
049    {
050        return _className;
051    }
052
053    public void addParameter(BuilderFacet facet)
054    {
055        _parameters.add(facet);
056    }
057
058    public List getParameters()
059    {
060        return _parameters;
061    }
062
063    public void addProperty(BuilderFacet facet)
064    {
065        _properties.add(facet);
066    }
067
068    public List getProperties()
069    {
070        return _properties;
071    }
072
073    /** @since 1.1 */
074    public BuilderFacet getFacetForType(ServiceImplementationFactoryParameters factoryParameters,
075            Class targetType)
076    {
077        BuilderFacet result = (BuilderFacet) _typeFacetMap.get(targetType);
078
079        if (result == null)
080        {
081            for (Iterator i = _properties.iterator(); i.hasNext();)
082            {
083                BuilderFacet facet = (BuilderFacet) i.next();
084
085                if (facet.canAutowireConstructorParameter()
086                        && facet.isAssignableToType(factoryParameters, targetType))
087                {
088                    result = facet;
089                    break;
090                }
091            }
092
093            _typeFacetMap.put(targetType, result);
094        }
095
096        return result;
097    }
098
099    public void setClassName(String string)
100    {
101        _className = string;
102    }
103
104    public void addEventRegistration(EventRegistration registration)
105    {
106        _events.add(registration);
107    }
108
109    public List getEventRegistrations()
110    {
111        return _events;
112    }
113
114    public String getInitializeMethod()
115    {
116        return _initializeMethod;
117    }
118
119    public void setInitializeMethod(String string)
120    {
121        _initializeMethod = string;
122    }
123
124    public boolean getAutowireServices()
125    {
126        return _autowireServices;
127    }
128
129    public void setAutowireServices(boolean autowireServices)
130    {
131        _autowireServices = autowireServices;
132    }
133
134}