001package org.biopax.paxtools.controller;
002
003import org.biopax.paxtools.model.BioPAXElement;
004import org.biopax.paxtools.util.IllegalBioPAXArgumentException;
005
006import java.util.Collection;
007import java.util.HashSet;
008import java.util.Set;
009
010/**
011 * Adapter class for all property accessors.
012 */
013public abstract class PropertyAccessorAdapter<D extends BioPAXElement, R> implements PropertyAccessor<D,R>
014{
015
016        /**
017         * This is the Class representing the domain of the property.
018         */
019        protected Class<D> domain;
020
021        /**
022         * This is the Class representing the range of the property. It is by default an object.
023         */
024        protected Class<R> range;
025
026        /**
027         * This is false if there is a cardinality restriction of one on the property.
028         */
029        protected boolean multipleCardinality;
030
031
032        protected PropertyAccessorAdapter(Class<D> domain, Class<R> range, boolean multipleCardinality)
033        {
034                this.domain = domain;
035                this.range = range;
036                this.multipleCardinality = multipleCardinality;
037        }
038
039        /**
040         * Returns the domain of the property.
041         * @return the domain of the editor
042         */
043        public Class<D> getDomain()
044        {
045                return domain;
046        }
047
048        /**
049         * Returns the range of the editor.
050         * @return a class
051         */
052        public Class<R> getRange()
053        {
054                return range;
055        }
056
057        /**
058         * Checks if the property to which editor is assigned has multiple cardinality.
059         * @return true if editor belongs to a multiple cardinality property.
060         */
061        public boolean isMultipleCardinality()
062        {
063                return multipleCardinality;
064        }
065
066        @Override public Set<? extends R> getValueFromBeans(Collection<? extends D> beans) throws
067                                                                                       IllegalBioPAXArgumentException
068        {
069            Set<R> aggregate = new HashSet<R>();
070                for (D bean : beans)
071                {
072                        aggregate.addAll(this.getValueFromBean(bean));
073                }
074                return aggregate;
075        }
076
077}