KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > QueryMetaData


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.metadata;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import org.w3c.dom.Element JavaDoc;
28
29 import org.jboss.deployment.DeploymentException;
30
31 /**
32  * Contains information about ejb-ql queries.
33  *
34  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
35  * @version $Revision: 58384 $
36  */

37 public class QueryMetaData extends MetaData {
38    public final static String JavaDoc REMOTE = "Remote";
39    public final static String JavaDoc LOCAL = "Local";
40
41    private String JavaDoc description;
42    private String JavaDoc methodName;
43    private ArrayList JavaDoc methodParams;
44    private String JavaDoc resultTypeMapping;
45    private String JavaDoc ejbQl;
46
47    public QueryMetaData () {
48       methodParams = new ArrayList JavaDoc();
49       resultTypeMapping = LOCAL;
50    }
51
52    /**
53     * Gets the user description of the query.
54     * @return the users description of the query
55     */

56    public String JavaDoc getDescription() {
57       return description;
58    }
59
60    /**
61     * Gets the name of the query for which this metadata applies.
62     * @return the name of the query method
63     */

64    public String JavaDoc getMethodName() {
65       return methodName;
66    }
67
68    public void setMethodName(String JavaDoc methodName)
69    {
70       this.methodName = methodName;
71    }
72
73    /**
74     * Gets an iterator over the parameters of the query method.
75     * @return an iterator over the parameters of the query method.
76     */

77    public Iterator JavaDoc getMethodParams() {
78       return methodParams.iterator();
79    }
80
81    public void addMethodParam(String JavaDoc param)
82    {
83       methodParams.add(param);
84    }
85
86    /**
87     * Gets the interface type of returned ejb objects. This will be
88     * Local or Remote, and the default is Local.
89     * @return the type the the interface returned for ejb objects
90     */

91    public String JavaDoc getResultTypeMapping() {
92       return resultTypeMapping;
93    }
94
95    public void setResultTypeMapping(String JavaDoc resultTypeMapping)
96    {
97       if(!LOCAL.equals(resultTypeMapping) && !REMOTE.equals(resultTypeMapping))
98       {
99          throw new IllegalArgumentException JavaDoc("Expected " + LOCAL + " or " + REMOTE + " but was " + resultTypeMapping);
100       }
101       this.resultTypeMapping = resultTypeMapping;
102    }
103
104    /**
105     * Gets the ejb-ql for this query.
106     * @return the ejb-ql for this query
107     */

108    public String JavaDoc getEjbQl() {
109       return ejbQl;
110    }
111
112    public void setEjbQl(String JavaDoc ejbQl)
113    {
114       this.ejbQl = ejbQl;
115    }
116
117    public boolean isResultTypeLocal()
118    {
119       return LOCAL.equals(resultTypeMapping);
120    }
121    
122    /**
123     * Loads the data from the query xml element.
124     * @param element the query xml element from the ejb-jar.xml file
125     * @throws DeploymentException if the query element is malformed
126     */

127    public void importEjbJarXml(Element JavaDoc element) throws DeploymentException {
128       // description
129
description = getOptionalChildContent(element, "description");
130
131       // query-method sub-element
132
Element JavaDoc queryMethod = getUniqueChild(element, "query-method");
133
134       // method name
135
methodName = getUniqueChildContent(queryMethod, "method-name");
136
137       // method params
138
Element JavaDoc methodParamsElement =
139             getUniqueChild(queryMethod, "method-params");
140       Iterator JavaDoc iterator =
141             getChildrenByTagName(methodParamsElement, "method-param");
142       while (iterator.hasNext()) {
143          final String JavaDoc param = getElementContent((Element JavaDoc)iterator.next());
144          if(param == null || param.trim().length() == 0)
145          {
146             throw new DeploymentException("method-param tag has no value for method: " + methodName);
147          }
148          methodParams.add(param);
149       }
150
151       // result type mapping
152
resultTypeMapping =
153             getOptionalChildContent(element, "result-type-mapping");
154       if(resultTypeMapping == null || LOCAL.equals(resultTypeMapping)) {
155          resultTypeMapping = LOCAL;
156       } else if(REMOTE.equals(resultTypeMapping)) {
157          resultTypeMapping = REMOTE;
158       } else {
159          throw new DeploymentException("result-type-mapping must be '" +
160                REMOTE + "' or '" + LOCAL + "', if specified");
161       }
162
163       ejbQl = getElementContent(getUniqueChild(element, "ejb-ql"));
164    }
165 }
166 /*
167 vim:ts=3:sw=3:et
168 */

169
Popular Tags