KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > script > ComponentElementHelper


1 /*****************************************************************************
2  * Copyright (C) NanoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  *****************************************************************************/

9
10 package org.nanocontainer.script;
11
12 import org.picocontainer.Parameter;
13 import org.nanocontainer.ClassNameKey;
14 import org.nanocontainer.NanoContainer;
15
16
17 public class ComponentElementHelper {
18
19     public static void makeComponent(Object JavaDoc cnkey, Object JavaDoc key, Parameter[] parameters, Object JavaDoc klass, NanoContainer current, Object JavaDoc instance) {
20         if (cnkey != null) {
21             key = new ClassNameKey((String JavaDoc)cnkey);
22         }
23
24         if (klass instanceof Class JavaDoc) {
25             Class JavaDoc clazz = (Class JavaDoc) klass;
26             key = key == null ? clazz : key;
27             current.getPico().registerComponentImplementation(key, clazz, parameters);
28         } else if (klass instanceof String JavaDoc) {
29             String JavaDoc className = (String JavaDoc) klass;
30             key = key == null ? className : key;
31             try {
32                 current.registerComponentImplementation(key, className, parameters);
33             } catch (ClassNotFoundException JavaDoc e) {
34                 throw new NanoContainerMarkupException("ClassNotFoundException: " + e.getMessage(), e);
35             }
36         } else if (instance != null) {
37             key = key == null ? instance.getClass() : key;
38             current.getPico().registerComponentInstance(key, instance);
39         } else {
40             throw new NanoContainerMarkupException("Must specify a 'class' attribute for a component as a class name (string) or Class.");
41         }
42     }
43
44
45 }
46
Popular Tags