| 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 org.apache.hivemind.HiveMind; |
| 18 | import org.apache.hivemind.Location; |
| 19 | import org.apache.hivemind.internal.Module; |
| 20 | import org.apache.hivemind.service.ObjectProvider; |
| 21 | |
| 22 | import net.sourceforge.hiveutils.service.ObjectBuilder; |
| 23 | |
| 24 | /** |
| 25 | * An <code>org.apache.hivemind.service.ObjectProvider</code> |
| 26 | * that references a named object to create from the |
| 27 | * <code>net.sourceforge.hiveutils.service.ObjectBuilder</code>. The |
| 28 | * translator string is of the form: <code>name</code>. That is, the name of |
| 29 | * the object definition in <code>ObjectBuilderObjects</code> configuration |
| 30 | * point. |
| 31 | * |
| 32 | * @author Jean-Francois Poilpret |
| 33 | */ |
| 34 | public class ObjectBuilderObjectProvider implements ObjectProvider |
| 35 | { |
| 36 | public ObjectBuilderObjectProvider(ObjectBuilder builder) |
| 37 | { |
| 38 | _builder = builder; |
| 39 | } |
| 40 | |
| 41 | public Object provideObject(Module contributingModule, |
| 42 | Class propertyType, |
| 43 | String inputValue, |
| 44 | Location location) |
| 45 | { |
| 46 | if (HiveMind.isBlank(inputValue)) |
| 47 | { |
| 48 | return null; |
| 49 | } |
| 50 | |
| 51 | return _builder.create(inputValue); |
| 52 | } |
| 53 | |
| 54 | private final ObjectBuilder _builder; |
| 55 | } |