001 /*
002 * JBoss, Home of Professional Open Source.
003 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
004 * as indicated by the @author tags. See the copyright.txt file in the
005 * distribution for a full listing of individual contributors.
006 *
007 * This is free software; you can redistribute it and/or modify it
008 * under the terms of the GNU Lesser General Public License as
009 * published by the Free Software Foundation; either version 2.1 of
010 * the License, or (at your option) any later version.
011 *
012 * This software is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this software; if not, write to the Free
019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021 */
022 package org.jboss.dna.connector.federation.contribution;
023
024 import java.util.HashMap;
025 import java.util.Iterator;
026 import java.util.Map;
027 import net.jcip.annotations.Immutable;
028 import org.jboss.dna.graph.properties.DateTime;
029 import org.jboss.dna.graph.properties.Name;
030 import org.jboss.dna.graph.properties.Path;
031 import org.jboss.dna.graph.properties.Property;
032
033 /**
034 * The record of a source contributing only properties to a node.
035 *
036 * @author Randall Hauch
037 */
038 @Immutable
039 public class MultiPropertyContribution extends NonEmptyContribution {
040
041 /**
042 * This is the first version of this class. See the documentation of MergePlan.serialVersionUID.
043 */
044 private static final long serialVersionUID = 1L;
045
046 protected final Map<Name, Property> properties;
047
048 /**
049 * Create a contribution of node properties from the source with the supplied name.
050 *
051 * @param sourceName the name of the source, which may not be null or blank
052 * @param pathInSource the path in the source for this contributed information; may not be null
053 * @param expirationTime the time (in UTC) after which this contribution should be considered expired, or null if there is no
054 * expiration time
055 * @param properties the properties from the source; may not be null
056 */
057 public MultiPropertyContribution( String sourceName,
058 Path pathInSource,
059 DateTime expirationTime,
060 Iterable<Property> properties ) {
061 super(sourceName, pathInSource, expirationTime);
062 assert properties != null;
063 this.properties = new HashMap<Name, Property>();
064 for (Property property : properties) {
065 if (property != null) this.properties.put(property.getName(), property);
066 }
067 assert this.properties.isEmpty() == false;
068 if (ContributionStatistics.RECORD) ContributionStatistics.record(this.properties.size(), 0);
069 }
070
071 /**
072 * {@inheritDoc}
073 *
074 * @see org.jboss.dna.connector.federation.contribution.Contribution#getProperties()
075 */
076 @Override
077 public Iterator<Property> getProperties() {
078 return new ImmutableIterator<Property>(this.properties.values().iterator());
079 }
080
081 /**
082 * {@inheritDoc}
083 *
084 * @see org.jboss.dna.connector.federation.contribution.Contribution#getPropertyCount()
085 */
086 @Override
087 public int getPropertyCount() {
088 return this.properties.size();
089 }
090
091 /**
092 * {@inheritDoc}
093 *
094 * @see org.jboss.dna.connector.federation.contribution.Contribution#getProperty(org.jboss.dna.graph.properties.Name)
095 */
096 @Override
097 public Property getProperty( Name name ) {
098 return this.properties.get(name);
099 }
100 }