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.merge; 023 024 import java.util.UUID; 025 import org.jboss.dna.graph.commands.CreateNodeCommand; 026 import org.jboss.dna.graph.commands.NodeConflictBehavior; 027 import org.jboss.dna.graph.commands.basic.BasicGetNodeCommand; 028 import org.jboss.dna.graph.properties.Path; 029 030 /** 031 * An in-memory (and temporary) representation of a federated node and it's merged properties and children. 032 * 033 * @author Randall Hauch 034 */ 035 public class FederatedNode extends BasicGetNodeCommand implements CreateNodeCommand { 036 037 protected static final NodeConflictBehavior DEFAULT_CONFLICT_BEHAVIOR = NodeConflictBehavior.UPDATE; 038 039 private static final long serialVersionUID = 1L; 040 041 private UUID uuid; 042 private MergePlan mergePlan; 043 private NodeConflictBehavior nodeConflictBehavior = DEFAULT_CONFLICT_BEHAVIOR; 044 045 /** 046 * Create a federated node given the path and UUID. 047 * 048 * @param path the path of the federated node; may not be null 049 * @param uuid the UUID of the federated node; may not be null 050 */ 051 public FederatedNode( Path path, 052 UUID uuid ) { 053 super(path); 054 assert uuid != null; 055 this.uuid = uuid; 056 } 057 058 /** 059 * Get the UUID for this federated node. 060 * 061 * @return the UUID; never null 062 */ 063 public UUID getUuid() { 064 return uuid; 065 } 066 067 /** 068 * @param uuid Sets uuid to the specified value. 069 */ 070 public void setUuid( UUID uuid ) { 071 this.uuid = uuid; 072 } 073 074 /** 075 * Get the merge plan for this federated node 076 * 077 * @return the merge plan, or null if there is no merge plan 078 */ 079 public MergePlan getMergePlan() { 080 return mergePlan; 081 } 082 083 /** 084 * Set the merge plan for this federated node 085 * 086 * @param mergePlan the new merge plan for this federated node; may be null 087 */ 088 public void setMergePlan( MergePlan mergePlan ) { 089 this.mergePlan = mergePlan; 090 } 091 092 /** 093 * {@inheritDoc} 094 * 095 * @see java.lang.Comparable#compareTo(java.lang.Object) 096 */ 097 public int compareTo( CreateNodeCommand that ) { 098 if (this == that) return 0; 099 return this.getPath().compareTo(that.getPath()); 100 } 101 102 /** 103 * {@inheritDoc} 104 * 105 * @see java.lang.Object#hashCode() 106 */ 107 @Override 108 public int hashCode() { 109 return this.uuid.hashCode(); 110 } 111 112 /** 113 * {@inheritDoc} 114 * 115 * @see java.lang.Object#equals(java.lang.Object) 116 */ 117 @Override 118 public boolean equals( Object obj ) { 119 if (obj == this) return true; 120 if (obj instanceof FederatedNode) { 121 FederatedNode that = (FederatedNode)obj; 122 if (this.getPath().equals(that.getPath())) return true; 123 if (this.getUuid().equals(that.getUuid())) return true; 124 } 125 return false; 126 } 127 128 /** 129 * {@inheritDoc} 130 * 131 * @see java.lang.Object#toString() 132 */ 133 @Override 134 public String toString() { 135 return getPath().toString() + " (" + this.getUuid() + ")"; 136 } 137 138 /** 139 * {@inheritDoc} 140 * 141 * @see org.jboss.dna.graph.commands.CreateNodeCommand#getConflictBehavior() 142 */ 143 public NodeConflictBehavior getConflictBehavior() { 144 return this.nodeConflictBehavior; 145 } 146 147 /** 148 * Set the behavior when node conflicts arise. 149 * 150 * @param nodeConflictBehavior the conflict behavior, or null if the default should be used 151 */ 152 public void setConflictBehavior( NodeConflictBehavior nodeConflictBehavior ) { 153 this.nodeConflictBehavior = nodeConflictBehavior != null ? nodeConflictBehavior : DEFAULT_CONFLICT_BEHAVIOR; 154 } 155 156 }