KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > jdbc > metadata > JDBCLeftJoinMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb.plugins.cmp.jdbc.metadata;
23
24 import org.w3c.dom.Element JavaDoc;
25 import org.jboss.metadata.MetaData;
26 import org.jboss.deployment.DeploymentException;
27
28 import java.util.List JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Collections JavaDoc;
31 import java.util.ArrayList JavaDoc;
32
33 /**
34  * Represents
35  * <left-join cmr-field="lineItems">
36  * <left-join cmr-field="product" eager-load-group="product"/>
37  * </left-join>
38  *
39  * @version <tt>$Revision: 37459 $</tt>
40  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
41  */

42 public final class JDBCLeftJoinMetaData
43 {
44    private final String JavaDoc cmrField;
45    private final String JavaDoc eagerLoadGroup;
46    private final List JavaDoc leftJoinList;
47
48    public static List JavaDoc readLeftJoinList(Iterator JavaDoc leftJoinIterator)
49       throws DeploymentException
50    {
51       List JavaDoc leftJoinList;
52       if(leftJoinIterator.hasNext())
53       {
54          leftJoinList = new ArrayList JavaDoc();
55          while(leftJoinIterator.hasNext())
56          {
57             Element JavaDoc leftJoinElement = (Element JavaDoc)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    /**
70     * Used only from the testsuite.
71     */

72    public JDBCLeftJoinMetaData(String JavaDoc cmrField, String JavaDoc eagerLoadGroup, List JavaDoc leftJoinList)
73    {
74       this.cmrField = cmrField;
75       this.eagerLoadGroup = eagerLoadGroup;
76       this.leftJoinList = leftJoinList;
77    }
78
79    public JDBCLeftJoinMetaData(Element JavaDoc 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 JavaDoc 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 JavaDoc leftJoinIterator = MetaData.getChildrenByTagName(element, "left-join");
98       leftJoinList = readLeftJoinList(leftJoinIterator);
99    }
100
101    public String JavaDoc getCmrField()
102    {
103       return cmrField;
104    }
105
106    public String JavaDoc getEagerLoadGroup()
107    {
108       return eagerLoadGroup;
109    }
110
111    public Iterator JavaDoc getLeftJoins()
112    {
113       return leftJoinList.iterator();
114    }
115
116    public boolean equals(Object JavaDoc 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 JavaDoc toString()
148    {
149       return "[cmr-field=" + cmrField + ", eager-load-group=" + eagerLoadGroup + ", left-join=" + leftJoinList + ']';
150    }
151 }
152
Popular Tags