01: /* ====================================================================
02: The Jicarilla Software License
03:
04: Copyright (c) 2003 Leo Simons.
05: All rights reserved.
06:
07: Permission is hereby granted, free of charge, to any person obtaining
08: a copy of this software and associated documentation files (the
09: "Software"), to deal in the Software without restriction, including
10: without limitation the rights to use, copy, modify, merge, publish,
11: distribute, sublicense, and/or sell copies of the Software, and to
12: permit persons to whom the Software is furnished to do so, subject to
13: the following conditions:
14:
15: The above copyright notice and this permission notice shall be
16: included in all copies or substantial portions of the Software.
17:
18: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25: ==================================================================== */
26: package org.jicarilla.container.builder;
27:
28: import org.jicarilla.container.KeyAwareAdapter;
29: import org.jicarilla.container.Resolver;
30: import org.jicarilla.container.KeyRelayingContainer;
31: import org.jicarilla.container.util.PolicyUtil;
32: import org.jicarilla.container.selectors.ClassSelector;
33: import org.jicarilla.container.selectors.ResolverSelector;
34: import org.jicarilla.lang.EquivalenceSelector;
35: import org.jicarilla.lang.Selector;
36: import org.jicarilla.lang.StringSelector;
37: import org.jicarilla.lang.Assert;
38:
39: /**
40: *
41: *
42: * @author <a href="mail at leosimons dot com">Leo Simons</a>
43: * @version $Id: EntryHelper.java,v 1.9 2004/03/23 14:22:35 lsimons Exp $
44: */
45: public class EntryHelper implements BuilderHelper {
46: protected Resolver m_helpers;
47: protected KeyRelayingContainer m_target;
48:
49: public EntryHelper(Resolver helpers, KeyRelayingContainer target) {
50: Assert.assertNotNull("helpers argument may not be null",
51: helpers);
52: Assert.assertNotNull("target argument may not be null", target);
53: m_helpers = helpers;
54: m_target = target;
55: }
56:
57: public KeyAwareAdapter getAdapter(final Object provider)
58: throws Exception {
59: Assert.assertNotNull("provider argument may not be null",
60: provider);
61: final DefaultBuilder.Entry entry = (DefaultBuilder.Entry) provider;
62:
63: final Object component = entry.getComponent();
64: final Object helper = m_helpers.get(component);
65:
66: // DefaultHelper will always work... if( helper == null )
67: // throw new NoUsableHelperException( component );
68:
69: if (helper instanceof ContainerAwareBuilderHelper) {
70: final ContainerAwareBuilderHelper builder = (ContainerAwareBuilderHelper) helper;
71:
72: return builder
73: .getAdapter(component, m_target.getResolver());
74: } else // we assume builder is correctly populated... if( helper instanceof BuilderHelper )
75: {
76: final BuilderHelper builder = (BuilderHelper) helper;
77: return builder.getAdapter(component);
78: }
79: /*else
80: {
81: throw new JicarillaIllegalStateException(
82: "Found a helper for " + component + " but the helper is " +
83: "not a ContainerAwareBuilderHelper or a BuilderHelper " +
84: "so we don't know what to do with it!" );
85: }*/
86: }
87:
88: public Selector getSelector(final Object provider) throws Exception {
89: Assert.assertNotNull("provider argument may not be null",
90: provider);
91: final DefaultBuilder.Entry entry = (DefaultBuilder.Entry) provider;
92:
93: final Object criterion = entry.getSelectionCriterion();
94:
95: return PolicyUtil.getSelectorForCriterion(criterion);
96: }
97:
98: }
|