001 /*
002 * JBoss DNA (http://www.jboss.org/dna)
003 * See the COPYRIGHT.txt file distributed with this work for information
004 * regarding copyright ownership. Some portions may be licensed
005 * to Red Hat, Inc. under one or more contributor license agreements.
006 * See the AUTHORS.txt file in the distribution for a full listing of
007 * individual contributors.
008 *
009 * Unless otherwise indicated, all code in JBoss DNA is licensed
010 * to you under the terms of the GNU Lesser General Public License as
011 * published by the Free Software Foundation; either version 2.1 of
012 * the License, or (at your option) any later version.
013 *
014 * JBoss DNA is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017 * Lesser General Public License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this software; if not, write to the Free
021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023 */
024 package org.jboss.dna.jcr.cache;
025
026 import java.util.Collections;
027 import java.util.List;
028 import java.util.Map;
029 import java.util.Set;
030 import java.util.UUID;
031 import net.jcip.annotations.Immutable;
032 import org.jboss.dna.graph.Location;
033 import org.jboss.dna.graph.property.Name;
034 import org.jboss.dna.jcr.NodeDefinitionId;
035
036 /**
037 * The information that describes a node. This is the information that is kept in the cache.
038 */
039 @Immutable
040 public class ImmutableNodeInfo implements NodeInfo {
041 private final Location originalLocation;
042 private final UUID uuid;
043 private final UUID parent;
044 private final Name primaryTypeName;
045 private final NodeDefinitionId definition;
046 private final Children children;
047 private final Map<Name, PropertyInfo> properties;
048 private final List<Name> mixinTypeNames;
049
050 /**
051 * Create an immutable NodeInfo instance.
052 *
053 * @param originalLocation the original location
054 * @param primaryTypeName the name of the node's primary type
055 * @param mixinTypeNames the names of the mixin types for this node, or null if there are none
056 * @param definition the definition used when creating the node
057 * @param parent the parent
058 * @param children the immutable children; may be null if there are no children
059 * @param properties the unmodifiable map of properties; may be null if there are no properties
060 */
061 public ImmutableNodeInfo( Location originalLocation,
062 Name primaryTypeName,
063 List<Name> mixinTypeNames,
064 NodeDefinitionId definition,
065 UUID parent,
066 Children children,
067 Map<Name, PropertyInfo> properties ) {
068 this.originalLocation = originalLocation;
069 this.primaryTypeName = primaryTypeName;
070 this.definition = definition;
071 this.parent = parent;
072 this.uuid = this.originalLocation.getUuid();
073 this.children = children != null ? children : new EmptyChildren(this.uuid);
074 this.properties = properties != null ? properties : Collections.<Name, PropertyInfo>emptyMap();
075 this.mixinTypeNames = mixinTypeNames != null ? mixinTypeNames : Collections.<Name>emptyList();
076 assert this.uuid != null;
077 assert this.definition != null;
078 assert this.primaryTypeName != null;
079 assert this.children != null;
080 assert this.mixinTypeNames != null;
081 assert this.properties != null;
082 }
083
084 /**
085 * {@inheritDoc}
086 *
087 * @see org.jboss.dna.jcr.cache.NodeInfo#getOriginalLocation()
088 */
089 public Location getOriginalLocation() {
090 return originalLocation;
091 }
092
093 /**
094 * {@inheritDoc}
095 *
096 * @see org.jboss.dna.jcr.cache.NodeInfo#getUuid()
097 */
098 public UUID getUuid() {
099 return uuid;
100 }
101
102 /**
103 * {@inheritDoc}
104 *
105 * @see org.jboss.dna.jcr.cache.NodeInfo#getParent()
106 */
107 public UUID getParent() {
108 return parent;
109 }
110
111 /**
112 * {@inheritDoc}
113 *
114 * @see org.jboss.dna.jcr.cache.NodeInfo#getPrimaryTypeName()
115 */
116 public Name getPrimaryTypeName() {
117 return primaryTypeName;
118 }
119
120 /**
121 * {@inheritDoc}
122 *
123 * @see org.jboss.dna.jcr.cache.NodeInfo#getMixinTypeNames()
124 */
125 public List<Name> getMixinTypeNames() {
126 return mixinTypeNames;
127 }
128
129 /**
130 * {@inheritDoc}
131 *
132 * @see org.jboss.dna.jcr.cache.NodeInfo#getDefinitionId()
133 */
134 public NodeDefinitionId getDefinitionId() {
135 return definition;
136 }
137
138 /**
139 * {@inheritDoc}
140 *
141 * @see org.jboss.dna.jcr.cache.NodeInfo#getChildren()
142 */
143 public Children getChildren() {
144 return children;
145 }
146
147 /**
148 * {@inheritDoc}
149 *
150 * @see org.jboss.dna.jcr.cache.NodeInfo#hasProperties()
151 */
152 public boolean hasProperties() {
153 return this.properties.size() != 0;
154 }
155
156 /**
157 * {@inheritDoc}
158 *
159 * @see org.jboss.dna.jcr.cache.NodeInfo#getPropertyCount()
160 */
161 public int getPropertyCount() {
162 return this.properties.size();
163 }
164
165 /**
166 * {@inheritDoc}
167 *
168 * @see org.jboss.dna.jcr.cache.NodeInfo#getPropertyNames()
169 */
170 public Set<Name> getPropertyNames() {
171 return this.properties.keySet();
172 }
173
174 /**
175 * {@inheritDoc}
176 *
177 * @see org.jboss.dna.jcr.cache.NodeInfo#getProperty(org.jboss.dna.graph.property.Name)
178 */
179 public PropertyInfo getProperty( Name name ) {
180 return this.properties.get(name);
181 }
182
183 /**
184 *
185 * {@inheritDoc}
186 * @return {@code false} always as this object represents unmodified nodes only
187 * @see org.jboss.dna.jcr.cache.NodeInfo#isNew()
188 */
189 public boolean isNew() {
190 return false;
191 }
192
193 /**
194 *
195 * {@inheritDoc}
196 * @return {@code false} always as this object represents unmodified nodes only
197 * @see org.jboss.dna.jcr.cache.NodeInfo#isModified()
198 */
199 public boolean isModified() {
200 return false;
201 }
202 }