View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.component.factory.desc;
17  
18  import java.lang.reflect.Constructor;
19  import java.util.List;
20  
21  import org.seasar.framework.beans.BeanDesc;
22  import org.seasar.framework.beans.factory.BeanDescFactory;
23  import org.seasar.framework.util.OgnlUtil;
24  import org.seasar.framework.xml.TagHandler;
25  
26  public class TagHandlerBuilder {
27      public static TagHandler buildTagHandler(final UrumaComponentDesc desc)
28              throws ClassNotFoundException {
29          Object[] args = getArgs(desc);
30          Class<?>[] argTypes = getArgTypes(args);
31  
32          String clazz = desc.getTagHandlerClass();
33          BeanDesc bd = BeanDescFactory.getBeanDesc(Class.forName(clazz));
34          Constructor<?> constructor = bd.getConstructor(argTypes);
35  
36          return null;
37      }
38  
39      protected static Object[] getArgs(final UrumaComponentDesc desc) {
40          int size = desc.getTagHandlerArgs().size();
41          List<String> argExprs = desc.getTagHandlerArgs();
42          Object[] args = new Object[size];
43          for (int i = 0; i < size; i++) {
44              Object exp = OgnlUtil.parseExpression(argExprs.get(i));
45              args[i] = OgnlUtil.getValue(exp, null);
46          }
47          return args;
48      }
49  
50      protected static Class<?>[] getArgTypes(final Object[] args) {
51          Class<?>[] types = new Class<?>[args.length];
52          for (int i = 0; i < args.length; i++) {
53              Object object = args[i];
54              types[i] = object.getClass();
55          }
56          return types;
57      }
58  }