1 22 package org.jboss.ejb.plugins.cmp.jdbc.metadata; 23 24 import org.w3c.dom.Element ; 25 import org.jboss.metadata.MetaData; 26 import org.jboss.deployment.DeploymentException; 27 28 import java.util.List ; 29 import java.util.Iterator ; 30 import java.util.Collections ; 31 import java.util.ArrayList ; 32 33 42 public final class JDBCLeftJoinMetaData 43 { 44 private final String cmrField; 45 private final String eagerLoadGroup; 46 private final List leftJoinList; 47 48 public static List readLeftJoinList(Iterator leftJoinIterator) 49 throws DeploymentException 50 { 51 List leftJoinList; 52 if(leftJoinIterator.hasNext()) 53 { 54 leftJoinList = new ArrayList (); 55 while(leftJoinIterator.hasNext()) 56 { 57 Element leftJoinElement = (Element )leftJoinIterator.next(); 58 JDBCLeftJoinMetaData leftJoin = new JDBCLeftJoinMetaData(leftJoinElement); 59 leftJoinList.add(leftJoin); 60 } 61 } 62 else 63 { 64 leftJoinList = Collections.EMPTY_LIST; 65 } 66 return leftJoinList; 67 } 68 69 72 public JDBCLeftJoinMetaData(String cmrField, String eagerLoadGroup, List leftJoinList) 73 { 74 this.cmrField = cmrField; 75 this.eagerLoadGroup = eagerLoadGroup; 76 this.leftJoinList = leftJoinList; 77 } 78 79 public JDBCLeftJoinMetaData(Element element) throws DeploymentException 80 { 81 cmrField = element.getAttribute("cmr-field"); 82 if(cmrField == null || cmrField.trim().length() == 0) 83 { 84 throw new DeploymentException("left-join MUST have non-empty cmr-field attribute."); 85 } 86 87 String eagerLoadGroup = element.getAttribute("eager-load-group"); 88 if(eagerLoadGroup == null || eagerLoadGroup.trim().length() == 0) 89 { 90 this.eagerLoadGroup = "*"; 91 } 92 else 93 { 94 this.eagerLoadGroup = eagerLoadGroup; 95 } 96 97 Iterator leftJoinIterator = MetaData.getChildrenByTagName(element, "left-join"); 98 leftJoinList = readLeftJoinList(leftJoinIterator); 99 } 100 101 public String getCmrField() 102 { 103 return cmrField; 104 } 105 106 public String getEagerLoadGroup() 107 { 108 return eagerLoadGroup; 109 } 110 111 public Iterator getLeftJoins() 112 { 113 return leftJoinList.iterator(); 114 } 115 116 public boolean equals(Object o) 117 { 118 boolean result; 119 if(o == this) 120 { 121 result = true; 122 } 123 else if(o instanceof JDBCLeftJoinMetaData) 124 { 125 JDBCLeftJoinMetaData other = (JDBCLeftJoinMetaData)o; 126 result = 127 (cmrField == null ? other.cmrField == null : cmrField.equals(other.cmrField)) && 128 (eagerLoadGroup == null ? other.eagerLoadGroup == null : eagerLoadGroup.equals(other.eagerLoadGroup)) && 129 (leftJoinList == null ? other.leftJoinList == null : leftJoinList.equals(other.leftJoinList)); 130 } 131 else 132 { 133 result = false; 134 } 135 return result; 136 } 137 138 public int hashCode() 139 { 140 int result = Integer.MIN_VALUE; 141 result += (cmrField == null ? 0 : cmrField.hashCode()); 142 result += (eagerLoadGroup == null ? 0 : eagerLoadGroup.hashCode()); 143 result += (leftJoinList == null ? 0 : leftJoinList.hashCode()); 144 return result; 145 } 146 147 public String toString() 148 { 149 return "[cmr-field=" + cmrField + ", eager-load-group=" + eagerLoadGroup + ", left-join=" + leftJoinList + ']'; 150 } 151 } 152 | Popular Tags |