+++ /dev/null
-/*--------------------------------------------------------------------------\r
- * Copyright 2008 Taro L. Saito\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *--------------------------------------------------------------------------*/\r
-//--------------------------------------\r
-// XerialJ\r
-//\r
-// BindRuleGeneratorForBeanStream.java\r
-// Since: Jan 22, 2008 11:06:06 AM\r
-//\r
-// $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/main/java/org/xerial/util/bean/impl/BindRuleGeneratorForBeanStream.java $\r
-// $Author: leo $\r
-//--------------------------------------\r
-package org.xerial.util.bean.impl;\r
-\r
-import java.util.Vector;\r
-\r
-import org.xerial.core.XerialErrorCode;\r
-import org.xerial.core.XerialException;\r
-import org.xerial.util.bean.BeanBinder;\r
-import org.xerial.util.bean.BeanBinderSet;\r
-import org.xerial.util.bean.BeanUtil;\r
-\r
-public class BindRuleGeneratorForBeanStream<E> implements BindRuleGenerator\r
-{\r
- private final Class<E> targetBeanClass;\r
- private String className;\r
- private final BeanBinderSet binderSetForTargetBean;\r
-\r
- public BindRuleGeneratorForBeanStream(Class<E> targetBeanClass) throws XerialException {\r
- this(targetBeanClass, targetBeanClass.getSimpleName());\r
- }\r
-\r
- public BindRuleGeneratorForBeanStream(Class<E> targetBeanClass, String targetNodeName) throws XerialException {\r
- this.targetBeanClass = targetBeanClass;\r
- className = targetNodeName.toLowerCase();\r
- try {\r
- binderSetForTargetBean = new MyBeanBinderSet();\r
- }\r
- catch (SecurityException e) {\r
- throw new XerialException(XerialErrorCode.InvalidBeanClass, e);\r
- }\r
- catch (NoSuchMethodException e) {\r
- throw new XerialException(XerialErrorCode.InvalidBeanClass, e);\r
- }\r
- }\r
-\r
- class MyBeanBinderSet implements BeanBinderSet\r
- {\r
- private CollectionAdder adder;\r
-\r
- public MyBeanBinderSet() throws XerialException, SecurityException, NoSuchMethodException {\r
- adder = new CollectionAdder(BeanStreamReader.class.getMethod("add", Object.class), className,\r
- targetBeanClass);\r
- }\r
-\r
- public void addRule(BeanBinder binder) {\r
- throw new UnsupportedOperationException("addRule");\r
- }\r
-\r
- public BeanBinder findRule(String name) {\r
- if (name.equals(className)) {\r
- return adder;\r
- }\r
- else\r
- return null;\r
- }\r
-\r
- public Vector<BeanBinder> getBindRules() {\r
- throw new UnsupportedOperationException("getBindRules");\r
- }\r
-\r
- public MapPutter getStandardMapPutter() {\r
- throw new UnsupportedOperationException("getStandardMapPutter");\r
- }\r
-\r
- }\r
-\r
- public <T> BeanBinderSet getBeanBinderSet(Class<T> beanClass) throws XerialException {\r
- if (BeanStreamReader.class.isAssignableFrom(beanClass)) {\r
- return binderSetForTargetBean;\r
- }\r
- else\r
- return BeanUtil.getBeanLoadRule(beanClass);\r
- }\r
-}\r