001: package org.apache.ojb.broker.metadata;
002:
003: /* Copyright 2003-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import org.apache.commons.lang.builder.ToStringBuilder;
019: import org.apache.commons.lang.builder.ToStringStyle;
020: import java.io.Serializable;
021: import java.util.Iterator;
022:
023: /**
024: * An InsertProcedureDescriptor contains information that is related to the
025: * procedure/function that is used to handle the insertion of new records.
026: * <br>
027: * Note: Be careful when use InsertProcedureDescriptor variables or caching
028: * InsertProcedureDescriptor instances, because instances could become invalid
029: * during runtime (see {@link MetadataManager}).
030: *
031: * @author <a href="mailto:rongallagher@bellsouth.net">Ron Gallagher<a>
032: * @version $Id: InsertProcedureDescriptor.java,v 1.7.2.2 2005/12/21 22:26:10 tomdz Exp $
033: */
034: public class InsertProcedureDescriptor extends ProcedureDescriptor
035: implements Serializable, XmlCapable {
036: private static final long serialVersionUID = -3808311052971075269L;
037: //---------------------------------------------------------------
038: /**
039: * The value that indicates if the argument list for this procedure
040: * includes all field-descriptors from the related class-descriptor.
041: */
042: private boolean includeAllFields;
043:
044: //---------------------------------------------------------------
045: /**
046: * Constructor declaration
047: */
048: public InsertProcedureDescriptor(ClassDescriptor classDescriptor,
049: String name, boolean includeAllFields) {
050: super (classDescriptor, name);
051: if (includeAllFields) {
052: this .addArguments(this .getClassDescriptor()
053: .getFieldDescriptions());
054: }
055: this .includeAllFields = includeAllFields;
056: }
057:
058: //---------------------------------------------------------------
059: /**
060: * Retrieve the value that indicates if the argument list for this
061: * procedure includes all field-descriptors from the related
062: * class-descriptor.
063: *
064: * @return The current value
065: */
066: public boolean getIncludeAllFields() {
067: return this .includeAllFields;
068: }
069:
070: //---------------------------------------------------------------
071: /**
072: * Add an argument
073: * <p>
074: * The argument will be added only if this procedure is not configured
075: * to {@link #getIncludeAllFields() include all arguments}.
076: */
077: public final void addArgument(ArgumentDescriptor argument) {
078: if (!this .getIncludeAllFields()) {
079: super .addArgument(argument);
080: }
081: }
082:
083: /*
084: * @see XmlCapable#toXML()
085: */
086: public String toXML() {
087: RepositoryTags tags = RepositoryTags.getInstance();
088: String eol = System.getProperty("line.separator");
089:
090: // The result
091: StringBuffer result = new StringBuffer(1024);
092: result.append(eol);
093: result.append(" ");
094:
095: // Opening tag and attributes
096: result.append(" ");
097: result.append(tags
098: .getOpeningTagNonClosingById(INSERT_PROCEDURE));
099: result.append(" ");
100: result.append(tags.getAttribute(NAME, this .getName()));
101: if (this .hasReturnValue()) {
102: result.append(" ");
103: result.append(tags.getAttribute(RETURN_FIELD_REF, this
104: .getReturnValueFieldRefName()));
105: }
106: result.append(" ");
107: result.append(tags.getAttribute(INCLUDE_ALL_FIELDS, String
108: .valueOf(this .getIncludeAllFields())));
109: result.append(">");
110: result.append(eol);
111:
112: // Write all arguments only if we're not including all fields.
113: if (!this .getIncludeAllFields()) {
114: Iterator args = this .getArguments().iterator();
115: while (args.hasNext()) {
116: result.append(((ArgumentDescriptor) args.next())
117: .toXML());
118: }
119: }
120:
121: // Closing tag
122: result.append(" ");
123: result.append(tags.getClosingTagById(INSERT_PROCEDURE));
124: result.append(eol);
125: return result.toString();
126: }
127:
128: //---------------------------------------------------------------
129: /**
130: * Provide a string representation of this object
131: *
132: * @return a string representation of this object
133: */
134: public String toString() {
135: ToStringBuilder buf = new ToStringBuilder(this ,
136: ToStringStyle.MULTI_LINE_STYLE);
137: buf.append("name", this .getName());
138: buf.append("includeAllFields", this .getIncludeAllFields());
139: if (this .hasReturnValue()) {
140: buf.append("returnFieldRefName", this
141: .getReturnValueFieldRefName());
142: }
143: return buf.toString();
144: }
145: }
|