001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.sql.framework.common.utils;
042:
043: import java.util.HashMap;
044: import java.util.Iterator;
045: import java.util.List;
046: import java.util.Map;
047:
048: import org.netbeans.modules.sql.framework.model.SQLConnectableObject;
049: import org.netbeans.modules.sql.framework.model.SQLConstants;
050: import org.netbeans.modules.sql.framework.model.SQLContainerObject;
051: import org.netbeans.modules.sql.framework.model.SQLDefinition;
052: import org.netbeans.modules.sql.framework.model.SQLInputObject;
053: import org.netbeans.modules.sql.framework.model.SQLObject;
054: import org.netbeans.modules.sql.framework.model.SQLObjectFactory;
055: import org.netbeans.modules.sql.framework.model.utils.SQLObjectUtil;
056: import org.w3c.dom.Element;
057: import org.w3c.dom.NamedNodeMap;
058: import org.w3c.dom.Node;
059: import org.w3c.dom.NodeList;
060:
061: import com.sun.sql.framework.exception.BaseException;
062: import com.sun.sql.framework.utils.Attribute;
063:
064: /**
065: * Utility class for reading and writing some mundane objects like SQLObjects
066: *
067: * @author Ritesh Adval
068: * @author Sudhi Seshachala
069: * @author Ahimanikya Satapathy
070: * @version $Revision$
071: */
072: public class TagParserUtility {
073:
074: public static final String ATTR_REFID = "refId";
075: public static final String ATTR_TYPE = "type";
076: public static final String TAG_INPUT = "input";
077: public static final String TAG_OBJECTREF = "objectRef";
078:
079: /**
080: * Gets ancestral SQLDefinition instance for the given SQLExpresionObject.
081: *
082: * @param sqlObj SQLConnectableObject whose ancestor SQLDefinition is sought
083: * @return SQLDefinition instance
084: * @throws BaseException if ancestral SQLDefinition could not be located
085: */
086: public static SQLDefinition getAncestralSQLDefinition(
087: SQLObject sqlObj) {
088: return SQLObjectUtil.getAncestralSQLDefinition(sqlObj);
089: }
090:
091: /**
092: * Gets the displayable representation of SQLObject type for given int type.
093: *
094: * @param type int representation of SQLObject type
095: * @return String representation of type
096: * @throws BaseException thrown while getting the type
097: */
098: public static String getDisplayStringFor(int type)
099: throws BaseException {
100: switch (type) {
101: case SQLConstants.GENERIC_OPERATOR:
102: return SQLConstants.DISPLAY_STR_GENERIC_OPERATOR;
103:
104: case SQLConstants.CAST_OPERATOR:
105: return SQLConstants.DISPLAY_STR_CAST_OPERATOR;
106:
107: case SQLConstants.DATE_DIFF_OPERATOR:
108: return SQLConstants.DISPLAY_STR_DATEDIFF_OPERATOR;
109:
110: case SQLConstants.DATE_ADD_OPERATOR:
111: return SQLConstants.DISPLAY_STR_DATEADD_OPERATOR;
112:
113: case SQLConstants.RUNTIME_ARGS:
114: return SQLConstants.DISPLAY_RUNTIME_ARGS;
115:
116: case SQLConstants.JOIN:
117: return SQLConstants.DISPLAY_STR_JOIN_OPERATOR;
118:
119: case SQLConstants.LITERAL:
120: case SQLConstants.VISIBLE_LITERAL:
121: return SQLConstants.DISPLAY_STR_LITERAL_OPERATOR;
122:
123: case SQLConstants.CASE:
124: return SQLConstants.DISPLAY_STR_CASE_OPERATOR;
125:
126: case SQLConstants.PREDICATE:
127: case SQLConstants.VISIBLE_PREDICATE:
128: return SQLConstants.DISPLAY_STR_PREDICATE;
129:
130: case SQLConstants.WHEN:
131: return SQLConstants.DISPLAY_STR_WHEN;
132:
133: case SQLConstants.SOURCE_COLUMN:
134: return SQLConstants.DISPLAY_STR_SOURCE_COLUMN;
135:
136: case SQLConstants.TARGET_COLUMN:
137: return SQLConstants.DISPLAY_STR_TARGET_COLUMN;
138:
139: case SQLConstants.TARGET_DBMODEL:
140: return SQLConstants.DISPLAY_STR_TARGET_DBMODEL;
141:
142: case SQLConstants.SOURCE_DBMODEL:
143: return SQLConstants.DISPLAY_STR_SOURCE_DBMODEL;
144:
145: case SQLConstants.SOURCE_TABLE:
146: return SQLConstants.DISPLAY_STR_SOURCE_TABLE;
147:
148: case SQLConstants.TARGET_TABLE:
149: return SQLConstants.DISPLAY_STR_TARGET_TABLE;
150:
151: case SQLConstants.FILTER:
152: return SQLConstants.DISPLAY_STR_FILTER;
153:
154: case SQLConstants.RUNTIME_DBMODEL:
155: return SQLConstants.DISPLAY_STR_RUNTIME_DBMODEL;
156:
157: case SQLConstants.RUNTIME_INPUT:
158: return SQLConstants.DISPLAY_STR_RUNTIME_INPUT;
159:
160: case SQLConstants.RUNTIME_OUTPUT:
161: return SQLConstants.DISPLAY_STR_RUNTIME_OUTPUT;
162:
163: case SQLConstants.COLUMN_REF:
164: return SQLConstants.DISPLAY_STR_COLUMN_REF;
165:
166: case SQLConstants.JOIN_VIEW:
167: return SQLConstants.DISPLAY_STR_JOIN_VIEW;
168:
169: case SQLConstants.JOIN_TABLE:
170: return SQLConstants.DISPLAY_STR_JOIN_TABLE;
171:
172: case SQLConstants.JOIN_TABLE_COLUMN:
173: return SQLConstants.DISPLAY_STR_JOIN_TABLE_COLUMN;
174:
175: case SQLConstants.CUSTOM_OPERATOR:
176: return SQLConstants.DISPLAY_STR_USER_FUNCTION;
177:
178: default:
179: throw new BaseException("Undefined SQLObject type: " + type);
180: }
181: }
182:
183: /**
184: * Gets the int representation for given SQLObject string type.
185: *
186: * @param type String representation of SQLObject type
187: * @return int representation of type
188: * @throws BaseException thrown while getting the type
189: */
190: public static int getIntType(String type) throws BaseException {
191: if (type.equals(SQLConstants.STR_GENERIC_OPERATOR)
192: || type.equals(SQLConstants.STR_SCALAR_OPERATOR)) {
193: return SQLConstants.GENERIC_OPERATOR;
194: } else if (type.equals(SQLConstants.STR_CAST_OPERATOR)) {
195: return SQLConstants.CAST_OPERATOR;
196: } else if (type.equals(SQLConstants.STR_DATEDIFF_OPERATOR)) {
197: return SQLConstants.DATE_DIFF_OPERATOR;
198: } else if (type.equals(SQLConstants.STR_DATEADD_OPERATOR)) {
199: return SQLConstants.DATE_ADD_OPERATOR;
200: } else if (type.equals(SQLConstants.STR_RUNTIME_ARGS)) {
201: return SQLConstants.RUNTIME_ARGS;
202: } else if (type.equals(SQLConstants.STR_JOIN_OPERATOR)) {
203: return SQLConstants.JOIN;
204: } else if (type.equals(SQLConstants.STR_CASE_OPERATOR)) {
205: return SQLConstants.CASE;
206: } else if (type.equals(SQLConstants.STR_LITERAL_OPERATOR)) {
207: return SQLConstants.LITERAL;
208: } else if (type.equals(SQLConstants.STR_PREDICATE)) {
209: return SQLConstants.PREDICATE;
210: } else if (type.equals(SQLConstants.STR_WHEN)) {
211: return SQLConstants.WHEN;
212: } else if (type.equals(SQLConstants.STR_SOURCE_TABLE)) {
213: return SQLConstants.SOURCE_TABLE;
214: } else if (type.equals(SQLConstants.STR_TARGET_TABLE)) {
215: return SQLConstants.TARGET_TABLE;
216: } else if (type.equals(SQLConstants.STR_SOURCE_COLUMN)) {
217: return SQLConstants.SOURCE_COLUMN;
218: } else if (type.equals(SQLConstants.STR_TARGET_COLUMN)) {
219: return SQLConstants.TARGET_COLUMN;
220: } else if (type.equals(SQLConstants.STR_VISIBLE_PREDICATE)) {
221: return SQLConstants.VISIBLE_PREDICATE;
222: } else if (type.equals(SQLConstants.STR_FILTER)) {
223: return SQLConstants.FILTER;
224: } else if (type.equals(SQLConstants.STR_VISIBLE_LITERAL)) {
225: return SQLConstants.VISIBLE_LITERAL;
226: } else if (type.equals(SQLConstants.STR_RUNTIME_DBMODEL)) {
227: return SQLConstants.RUNTIME_DBMODEL;
228: } else if (type.equals(SQLConstants.STR_RUNTIME_INPUT)) {
229: return SQLConstants.RUNTIME_INPUT;
230: } else if (type.equals(SQLConstants.STR_RUNTIME_OUTPUT)) {
231: return SQLConstants.RUNTIME_OUTPUT;
232: } else if (type.equals(SQLConstants.STR_COLUMN_REF)) {
233: return SQLConstants.COLUMN_REF;
234: } else if (type.equals(SQLConstants.STR_JOIN_VIEW)) {
235: return SQLConstants.JOIN_VIEW;
236: } else if (type.equals(SQLConstants.STR_JOIN_TABLE)) {
237: return SQLConstants.JOIN_TABLE;
238: } else if (type.equals(SQLConstants.STR_JOIN_TABLE_COLUMN)) {
239: return SQLConstants.JOIN_TABLE_COLUMN;
240: } else if (type.equals(SQLConstants.STR_CUSTOM_OPERATOR)) {
241: return SQLConstants.CUSTOM_OPERATOR;
242: } else {
243: throw new BaseException("Failed to get Int type for '"
244: + type + "'");
245: }
246: }
247:
248: /**
249: * Returns all the attributes name value of Node in a Map.
250: *
251: * @param node
252: * @return map containing name/value of all Node attributes.
253: */
254: public static Map getNodeAttributes(Node node) {
255: Map ret = new HashMap();
256: NamedNodeMap nnm = node.getAttributes();
257: Node attNode = null;
258: int length = nnm.getLength();
259:
260: for (int i = 0; i < length; i++) {
261: attNode = nnm.item(i);
262: ret.put(attNode.getNodeName(), attNode.getNodeValue());
263: }
264:
265: return ret;
266: }
267:
268: /**
269: * Returns node attribute value
270: *
271: * @param node
272: * @param attName
273: * @return value of the attribute
274: */
275: public static String getNodeAttributeValue(Node node, String attName) {
276: String ret = null;
277: NamedNodeMap nnm = node.getAttributes();
278: if (nnm != null) {
279: Node att = nnm.getNamedItem(attName);
280: if (att != null) {
281: ret = att.getNodeValue();
282: }
283: }
284: return ret;
285: }
286:
287: /**
288: * Gets the String representation of SQLObject type for given int type.
289: *
290: * @param type int representation of SQLObject type
291: * @return String representation of type
292: * @throws BaseException thrown while getting the type
293: */
294: public static String getStringType(int type) throws BaseException {
295: switch (type) {
296: case SQLConstants.GENERIC_OPERATOR:
297: return SQLConstants.STR_GENERIC_OPERATOR;
298:
299: case SQLConstants.CAST_OPERATOR:
300: return SQLConstants.STR_CAST_OPERATOR;
301:
302: case SQLConstants.DATE_DIFF_OPERATOR:
303: return SQLConstants.STR_DATEDIFF_OPERATOR;
304:
305: case SQLConstants.DATE_ADD_OPERATOR:
306: return SQLConstants.STR_DATEADD_OPERATOR;
307:
308: case SQLConstants.RUNTIME_ARGS:
309: return SQLConstants.STR_RUNTIME_ARGS;
310:
311: case SQLConstants.JOIN:
312: return SQLConstants.STR_JOIN_OPERATOR;
313:
314: case SQLConstants.LITERAL:
315: return SQLConstants.STR_LITERAL_OPERATOR;
316:
317: case SQLConstants.CASE:
318: return SQLConstants.STR_CASE_OPERATOR;
319:
320: case SQLConstants.PREDICATE:
321: return SQLConstants.STR_PREDICATE;
322:
323: case SQLConstants.WHEN:
324: return SQLConstants.STR_WHEN;
325:
326: case SQLConstants.SOURCE_COLUMN:
327: return SQLConstants.STR_SOURCE_COLUMN;
328:
329: case SQLConstants.TARGET_COLUMN:
330: return SQLConstants.STR_TARGET_COLUMN;
331:
332: case SQLConstants.TARGET_DBMODEL:
333: return SQLConstants.STR_TARGET_DBMODEL;
334:
335: case SQLConstants.SOURCE_DBMODEL:
336: return SQLConstants.STR_SOURCE_DBMODEL;
337:
338: case SQLConstants.SOURCE_TABLE:
339: return SQLConstants.STR_SOURCE_TABLE;
340:
341: case SQLConstants.TARGET_TABLE:
342: return SQLConstants.STR_TARGET_TABLE;
343:
344: case SQLConstants.VISIBLE_PREDICATE:
345: return SQLConstants.STR_VISIBLE_PREDICATE;
346:
347: case SQLConstants.FILTER:
348: return SQLConstants.STR_FILTER;
349:
350: case SQLConstants.VISIBLE_LITERAL:
351: return SQLConstants.STR_VISIBLE_LITERAL;
352:
353: case SQLConstants.RUNTIME_DBMODEL:
354: return SQLConstants.STR_RUNTIME_DBMODEL;
355:
356: case SQLConstants.RUNTIME_INPUT:
357: return SQLConstants.STR_RUNTIME_INPUT;
358:
359: case SQLConstants.RUNTIME_OUTPUT:
360: return SQLConstants.STR_RUNTIME_OUTPUT;
361:
362: case SQLConstants.COLUMN_REF:
363: return SQLConstants.STR_COLUMN_REF;
364:
365: case SQLConstants.JOIN_VIEW:
366: return SQLConstants.STR_JOIN_VIEW;
367:
368: case SQLConstants.JOIN_TABLE:
369: return SQLConstants.STR_JOIN_TABLE;
370:
371: case SQLConstants.JOIN_TABLE_COLUMN:
372: return SQLConstants.STR_JOIN_TABLE_COLUMN;
373:
374: case SQLConstants.CUSTOM_OPERATOR:
375: return SQLConstants.STR_CUSTOM_OPERATOR;
376:
377: default:
378: throw new BaseException("Undefined Operator Type" + type);
379: }
380: }
381:
382: public static Attribute parseAttribute(Element elem)
383: throws BaseException {
384: if (elem == null) {
385: throw new IllegalArgumentException(
386: "Attribute element can not be null.");
387: }
388:
389: if (elem.getNodeName().equals(Attribute.TAG_ATTR)) {
390: Attribute attr = new Attribute();
391: attr.parseXMLString(elem);
392: return attr;
393: }
394: throw new IllegalArgumentException(
395: "Element is not an attribute element.");
396: }
397:
398: public static void parseAttributeList(Map attributes, NodeList list)
399: throws BaseException {
400: if (attributes == null) {
401: throw new IllegalArgumentException(
402: "Attribute map can not be null");
403: }
404:
405: for (int i = 0; i < list.getLength(); i++) {
406: if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {
407: Element elem = (Element) list.item(i);
408: if (elem.getNodeName().equals(Attribute.TAG_ATTR)) {
409: Attribute attr = new Attribute();
410: attr.parseXMLString(elem);
411: attributes.put(attr.getAttributeName(), attr);
412: }
413: }
414: }
415: }
416:
417: /**
418: * Parses list of Nodes possibly containing input elements.
419: *
420: * @param sqlObj SQLConnectableObject to contain the parsed input objects
421: * @param inputArgList NodeList with possible input elements
422: * @throws BaseException if error occurs while parsing
423: */
424: public static void parseInputChildNodes(
425: SQLConnectableObject sqlObj, NodeList inputArgList)
426: throws BaseException {
427: for (int i = 0; i < inputArgList.getLength(); i++) {
428: if (inputArgList.item(i).getNodeType() == Node.ELEMENT_NODE
429: && inputArgList.item(i).getNodeName().equals(
430: TAG_INPUT)) {
431: Element elem = (Element) inputArgList.item(i);
432: parseInputTag(sqlObj, elem);
433: }
434: }
435: }
436:
437: /**
438: * Parser the <input>tag . This should be called from any SQLObject which has input
439: * tag
440: *
441: * @param sqlObj to be parsed
442: * @param elem Element
443: * @throws BaseException if error occurs while parsing
444: */
445: public static void parseInputTag(SQLConnectableObject sqlObj,
446: Element elem) throws BaseException {
447: if (elem != null) {
448: String argName = elem
449: .getAttribute(SQLInputObject.ATTR_ARGNAME);
450:
451: // Recurse ancestor list to obtain parent SQLDefinition.
452: SQLContainerObject defn = null;
453: SQLObject loopObj = sqlObj;
454: do {
455: Object parentObject = loopObj.getParentObject();
456: if (parentObject instanceof SQLContainerObject) {
457: defn = (SQLContainerObject) parentObject;
458: break;
459: } else if (parentObject == null) {
460: throw new BaseException(
461: "Could not locate root SQLDefinition instance!");
462: }
463: loopObj = (SQLObject) parentObject;
464: } while (true);
465:
466: NodeList objRefList = elem
467: .getElementsByTagName(TAG_OBJECTREF);
468:
469: // Only one Element
470: if (objRefList != null && objRefList.getLength() != 0) {
471: Element objRefElement = (Element) objRefList.item(0);
472: if (objRefElement != null) {
473: SQLObject refObj = parseXMLObjectRefTag(defn,
474: objRefElement);
475:
476: // If input is null it may not be parsed yet so do a second parse...
477: // This will take for any second parse for SQL objects
478: if (refObj == null) {
479: // QAI#: 85425 to maintain order of the argument of var-argument
480: // operators, create a placeholder for this argument in the
481: // inputmap.
482: if (sqlObj.getInputObjectMap().get(argName) == null) {
483: sqlObj.getInputObjectMap().put(argName,
484: null);
485: }
486: defn.addSecondPassSQLObject(sqlObj, elem);
487: } else {
488: sqlObj.addInput(argName, refObj);
489: }
490: }
491: } else {
492: // If input does not have an object ref then it must be a part of object
493: NodeList objList = elem
494: .getElementsByTagName(SQLObject.TAG_SQLOBJECT);
495: if (objList != null && objList.getLength() != 0) {
496: Element objElement = (Element) objList.item(0);
497: if (objElement != null) {
498: SQLObject partObj = SQLObjectFactory
499: .createSQLObjectForElement(sqlObj,
500: objElement);
501:
502: if (partObj != null) {
503: sqlObj.addInput(argName, partObj);
504: }
505: }
506: }
507: }
508: }
509: }
510:
511: /**
512: * Parses the <input>tag . This should be called from any SQLObject which has input
513: * tag
514: *
515: * @param sqlObj to be parsed
516: * @param inputArgList NodeList
517: * @throws BaseException if error occurs while parsing
518: */
519: public static void parseInputTagList(SQLConnectableObject sqlObj,
520: NodeList inputArgList) throws BaseException {
521: for (int i = 0; i < inputArgList.getLength(); i++) {
522: Element elem = (Element) inputArgList.item(i);
523: parseInputTag(sqlObj, elem);
524: }
525: }
526:
527: /**
528: * Reads in and resolves, if possible, from the given SQLDefinition instance the
529: * reference to an SQLObject contained in the given XML Element.
530: *
531: * @param definition definition from which to attempt to resolve the SQLObject
532: * reference
533: * @param xmlElement Element representing the SQLObject reference
534: * @return SQLObject referenced by xmlElement; null if object has not yet been parsed
535: * and registered with definition.
536: * @throws BaseException if errors occur during parsing
537: */
538: public static SQLObject parseXMLObjectRefTag(
539: SQLContainerObject definition, Element xmlElement)
540: throws BaseException {
541: if (definition == null) {
542: throw new BaseException(
543: "Must supply non-null SQLDefinition ref for param 'definition'.");
544: }
545:
546: if (xmlElement == null) {
547: throw new BaseException(
548: "Must supply non-null Element ref for param 'xmlElement'.");
549: }
550:
551: String refIdValue = xmlElement.getAttribute(ATTR_REFID);
552: String type = xmlElement.getAttribute(ATTR_TYPE);
553:
554: // Now get SQLObject for this refId
555: return definition.getObject(refIdValue, TagParserUtility
556: .getIntType(type));
557: }
558:
559: /**
560: * Generates XML elements representing this object's associated attributes.
561: *
562: * @param prefix Prefix string to be prepended to each element
563: * @return String containing XML representation of attributes
564: */
565: public static String toXMLAttributeTags(Map attributes,
566: String prefix) {
567: StringBuilder buf = new StringBuilder(100);
568:
569: Iterator iter = attributes.values().iterator();
570: while (iter.hasNext()) {
571: Attribute attr = (Attribute) iter.next();
572: if (attr.getAttributeValue() != null) {
573: buf.append(attr.toXMLString(prefix + "\t"));
574: }
575: }
576:
577: return buf.toString();
578: }
579:
580: /**
581: * Writer for <input>tag. This should be called from any SQLObject which needs to
582: * write out input child elements from a List.
583: *
584: * @param prefix Prefix string to be appended to each line of the generated XML
585: * document
586: * @param inputs List of SQLInputObject instances to be written out
587: * @return XML element containing input reference information
588: */
589: public static String toXMLInputTag(String prefix, List inputs)
590: throws BaseException {
591: Iterator it = inputs.iterator();
592: StringBuilder buffer = new StringBuilder();
593:
594: while (it.hasNext()) {
595: SQLObject obj = (SQLObject) it.next();
596: buffer.append(obj.toXMLString(prefix));
597: }
598:
599: return buffer.toString();
600: }
601:
602: /**
603: * Writer for <input>tag. This should be called from any SQLObject which needs to
604: * write out input child elements from a Map.
605: *
606: * @param prefix Prefix string to be appended to each line of the generated XML
607: * document
608: * @param inputs Map of SQLInputObject instances to be written out
609: * @return XML element containing references to SQLObjects as contained in inputs
610: */
611: public static String toXMLInputTag(String prefix, Map inputs) {
612: Iterator it = inputs.values().iterator();
613: StringBuilder buffer = new StringBuilder();
614:
615: while (it.hasNext()) {
616: SQLInputObject obj = (SQLInputObject) it.next();
617: if (obj != null && obj.getSQLObject() != null) {
618: buffer.append(obj.toXMLString(prefix));
619: }
620: }
621:
622: return buffer.toString();
623: }
624:
625: /**
626: * Writes out an XML document element representing a reference to the given SQLObject,
627: * using the given string as a prefix for each output line.
628: *
629: * @param object SQLObject to be referenced in the XML element
630: * @param prefix String to prepend to each new line in the String
631: * @return XML document element referencing object
632: * @throws BaseException if object is null or errors occur during writing
633: */
634: public static String toXMLObjectRefTag(SQLObject object,
635: String prefix) throws BaseException {
636: if (object == null) {
637: throw new BaseException(
638: "Must supply non-null SQLObject ref for param 'object'.");
639: }
640:
641: StringBuilder xml = new StringBuilder(prefix);
642:
643: xml.append("<" + TAG_OBJECTREF + " ");
644: xml.append(ATTR_REFID + "=\"" + object.getId() + "\" ");
645: xml.append(ATTR_TYPE + "=\"");
646:
647: xml.append(
648: TagParserUtility.getStringType(object.getObjectType()))
649: .append("\" />\n");
650:
651: return xml.toString();
652: }
653:
654: /*
655: * Creates a new instance of TagParserUtility. No-arg and private as this is a static
656: * utility class.
657: */
658: private TagParserUtility() {
659: }
660: }
|