001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, 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.metadata;
023:
024: import java.util.ArrayList;
025: import java.util.Iterator;
026:
027: import org.w3c.dom.Element;
028:
029: import org.jboss.deployment.DeploymentException;
030:
031: /**
032: * Contains information about ejb-ql queries.
033: *
034: * @author <a href="mailto:dain@daingroup.com">Dain Sundstrom</a>
035: * @version $Revision: 57209 $
036: */
037: public class QueryMetaData extends MetaData {
038: public final static String REMOTE = "Remote";
039: public final static String LOCAL = "Local";
040:
041: private String description;
042: private String methodName;
043: private ArrayList methodParams;
044: private String resultTypeMapping;
045: private String ejbQl;
046:
047: public QueryMetaData() {
048: methodParams = new ArrayList();
049: }
050:
051: /**
052: * Gets the user description of the query.
053: * @return the users description of the query
054: */
055: public String getDescription() {
056: return description;
057: }
058:
059: /**
060: * Gets the name of the query for which this metadata applies.
061: * @return the name of the query method
062: */
063: public String getMethodName() {
064: return methodName;
065: }
066:
067: /**
068: * Gets an iterator over the parameters of the query method.
069: * @return an iterator over the parameters of the query method.
070: */
071: public Iterator getMethodParams() {
072: return methodParams.iterator();
073: }
074:
075: /**
076: * Gets the interface type of returned ejb objects. This will be
077: * Local or Remote, and the default is Local.
078: * @return the type the the interface returned for ejb objects
079: */
080: public String getResultTypeMapping() {
081: return resultTypeMapping;
082: }
083:
084: /**
085: * Gets the ejb-ql for this query.
086: * @return the ejb-ql for this query
087: */
088: public String getEjbQl() {
089: return ejbQl;
090: }
091:
092: /**
093: * Loads the data from the query xml element.
094: * @param element the query xml element from the ejb-jar.xml file
095: * @throws DeploymentException if the query element is malformed
096: */
097: public void importEjbJarXml(Element element)
098: throws DeploymentException {
099: // description
100: description = getOptionalChildContent(element, "description");
101:
102: // query-method sub-element
103: Element queryMethod = getUniqueChild(element, "query-method");
104:
105: // method name
106: methodName = getUniqueChildContent(queryMethod, "method-name");
107:
108: // method params
109: Element methodParamsElement = getUniqueChild(queryMethod,
110: "method-params");
111: Iterator iterator = getChildrenByTagName(methodParamsElement,
112: "method-param");
113: while (iterator.hasNext()) {
114: final String param = getElementContent((Element) iterator
115: .next());
116: if (param == null || param.trim().length() == 0) {
117: throw new DeploymentException(
118: "method-param tag has no value for method: "
119: + methodName);
120: }
121: methodParams.add(param);
122: }
123:
124: // result type mapping
125: resultTypeMapping = getOptionalChildContent(element,
126: "result-type-mapping");
127: if (resultTypeMapping == null
128: || LOCAL.equals(resultTypeMapping)) {
129: resultTypeMapping = LOCAL;
130: } else if (REMOTE.equals(resultTypeMapping)) {
131: resultTypeMapping = REMOTE;
132: } else {
133: throw new DeploymentException(
134: "result-type-mapping must be '" + REMOTE + "' or '"
135: + LOCAL + "', if specified");
136: }
137:
138: ejbQl = getElementContent(getUniqueChild(element, "ejb-ql"));
139: }
140: }
141: /*
142: vim:ts=3:sw=3:et
143: */
|