| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 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 net.sourceforge.hiveutils.service.impl; |
| 16 | |
| 17 | import java.util.ArrayList; |
| 18 | import java.util.HashMap; |
| 19 | import java.util.List; |
| 20 | import java.util.Map; |
| 21 | |
| 22 | import org.apache.hivemind.impl.BaseLocatable; |
| 23 | import org.apache.hivemind.util.ToStringBuilder; |
| 24 | |
| 25 | /** |
| 26 | * Represents a configuration parameter to the ObjectBuilder, indicating |
| 27 | * which class to instantiate and the unique name of the definition. |
| 28 | * |
| 29 | * @author Jean-Francois Poilpret |
| 30 | */ |
| 31 | public class ObjectContribution extends BaseLocatable |
| 32 | { |
| 33 | public ObjectContribution() |
| 34 | { |
| 35 | _listeners = new ArrayList<ListenerContribution>(); |
| 36 | _ctorInjections = new ArrayList<InjectObjectInformation>(); |
| 37 | _setterInjections = new HashMap<String, InjectObjectInformation>(); |
| 38 | } |
| 39 | |
| 40 | public void setName(String name) |
| 41 | { |
| 42 | _name = name; |
| 43 | } |
| 44 | |
| 45 | public String getName() |
| 46 | { |
| 47 | return _name; |
| 48 | } |
| 49 | |
| 50 | public void setCached(boolean cached) |
| 51 | { |
| 52 | _cached = cached; |
| 53 | } |
| 54 | |
| 55 | public boolean isCached() |
| 56 | { |
| 57 | return _cached; |
| 58 | } |
| 59 | |
| 60 | public void setEagerLoad(boolean eagerLoad) |
| 61 | { |
| 62 | _eagerLoad = eagerLoad; |
| 63 | } |
| 64 | |
| 65 | public boolean isEagerLoad() |
| 66 | { |
| 67 | return _eagerLoad; |
| 68 | } |
| 69 | |
| 70 | public void setObjectClass(Class clazz) |
| 71 | { |
| 72 | _clazz = clazz; |
| 73 | } |
| 74 | |
| 75 | public Class getObjectClass() |
| 76 | { |
| 77 | return _clazz; |
| 78 | } |
| 79 | |
| 80 | public void addInjection(InjectContribution inject) |
| 81 | { |
| 82 | if (inject.getName() != null) |
| 83 | { |
| 84 | _setterInjections.put(inject.getName(), inject.getObject()); |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | _ctorInjections.add(inject.getObject()); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | public void addListener(ListenerContribution listener) |
| 93 | { |
| 94 | _listeners.add(listener); |
| 95 | } |
| 96 | |
| 97 | public List<ListenerContribution> getListeners() |
| 98 | { |
| 99 | return _listeners; |
| 100 | } |
| 101 | |
| 102 | public List<InjectObjectInformation> getConstructorInjections() |
| 103 | { |
| 104 | return _ctorInjections; |
| 105 | } |
| 106 | |
| 107 | public Map<String, InjectObjectInformation> getSetterInjections() |
| 108 | { |
| 109 | return _setterInjections; |
| 110 | } |
| 111 | |
| 112 | public String toString() |
| 113 | { |
| 114 | ToStringBuilder builder = new ToStringBuilder(this); |
| 115 | builder.append("name", _name); |
| 116 | builder.append("cached", _cached); |
| 117 | builder.append("class", _clazz); |
| 118 | return builder.toString(); |
| 119 | } |
| 120 | |
| 121 | private String _name; |
| 122 | private boolean _cached; |
| 123 | private boolean _eagerLoad; |
| 124 | private Class _clazz; |
| 125 | private List<ListenerContribution> _listeners; |
| 126 | private List<InjectObjectInformation> _ctorInjections; |
| 127 | private Map<String, InjectObjectInformation> _setterInjections; |
| 128 | } |