001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.flatfile.morph;
018
019import net.sf.morph.reflect.BeanReflector;
020import net.sf.morph.util.ContainerUtils;
021
022import org.apache.commons.flatfile.Entity;
023import org.apache.commons.flatfile.NamedEntityCollection;
024import org.apache.commons.lang3.ArrayUtils;
025
026/**
027 * NamedEntityCollection Reflector.
028 * @version $Revision: 1301235 $ $Date: 2012-03-15 17:07:14 -0500 (Thu, 15 Mar 2012) $
029 */
030public class NamedEntityCollectionReflector extends
031        BaseEntityCollectionReflector implements BeanReflector {
032    private static final Class<?>[] REFLECTABLE_CLASSES = { NamedEntityCollection.class };
033
034    /**
035     * {@inheritDoc}
036     */
037    @Override
038    protected Class<?>[] getReflectableClassesImpl() throws Exception {
039        return REFLECTABLE_CLASSES;
040    }
041
042    /**
043     * {@inheritDoc}
044     */
045    @Override
046    protected boolean isEntity(Object bean, String propertyName)
047            throws Exception {
048        return ContainerUtils.contains(((NamedEntityCollection) bean)
049                .getChildNames(), propertyName);
050    }
051
052    /**
053     * {@inheritDoc}
054     */
055    @Override
056    protected Entity getEntity(Object bean, String propertyName)
057            throws Exception {
058        return ((NamedEntityCollection) bean).getChild(propertyName);
059    }
060
061    /**
062     * {@inheritDoc}
063     */
064    @Override
065    protected String[] getPropertyNamesImpl(Object bean) throws Exception {
066        return ArrayUtils.addAll(super.getPropertyNamesImpl(bean),
067            ((NamedEntityCollection) bean).getChildNames());
068    }
069
070}