1 package org.jboss.cache.pojo.test.propagation.impl; 2 3 import org.jboss.cache.pojo.test.propagation.Node; 4 import org.jboss.cache.pojo.test.propagation.PropagationRule; 5 import org.jboss.cache.pojo.test.propagation.StateItem; 6 7 public abstract class AbstractPropagtionRule implements PropagationRule 8 { 9 public void changeState(Node node, long itemId, long state) 10 { 11 StateItem target = node.findStateItem(itemId); 12 if (target == null) 13 { 14 System.out.println("[Error] StateItem not found. : " + node + ":" 15 + itemId); 16 return; 17 } 18 19 if (StateItem.STATE_CHANGED == target.setState(state)) 20 { 21 summaryUpperPropagate(node); 22 } 23 } 24 25 protected void upperPropagate(Node node) 26 { 27 Node parentNode = (Node) node.getParentNode(); 28 if (parentNode != null) 29 { 30 PropagationRule parentRule = parentNode.getPropagationRule(); 31 parentRule.summaryUpperPropagate(parentNode); 32 } 33 } 34 35 protected boolean isClear(StateItem item) 36 { 37 long state = item.getState(); 38 if ((state % 10) == 0) 39 { 40 return true; 41 } else 42 { 43 return false; 44 } 45 } 46 47 protected long getSeverity(StateItem item) 48 { 49 long state = item.getState(); 50 long severity = 0; 51 if (isSummaryItem(item)) 52 { 53 severity = state % 1000; 54 } else 55 { 56 severity = (state % 1000) / 10; 57 } 58 59 return severity; 60 } 61 62 protected boolean isSummaryItem(StateItem item) 63 { 64 long state = item.getState(); 65 long summaryDigit = (state / 1000) % 10; 66 67 if (summaryDigit == 2) 68 { 69 return true; 70 } else 71 { 72 return false; 73 } 74 } 75 76 protected long updateMaxSeverity(long maxSeverity, StateItem stateItem) 77 { 78 if (!isClear(stateItem)) 79 { 80 long severity = getSeverity(stateItem); 81 if (severity > maxSeverity) 82 { 83 maxSeverity = severity; 84 } 85 } 86 87 return maxSeverity; 88 } 89 } 90 | Popular Tags |