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 UpdateProcedureDescriptor contains information that is related to the
025: * procedure/function that is used to handle the updating of existing records.
026: * <br>
027: * Note: Be careful when use UpdateProcedureDescriptor variables or caching
028: * UpdateProcedureDescriptor 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: UpdateProcedureDescriptor.java,v 1.7.2.2 2005/12/21 22:26:11 tomdz Exp $
033: */
034: public class UpdateProcedureDescriptor extends ProcedureDescriptor
035: implements Serializable, XmlCapable {
036: private static final long serialVersionUID = 1319547080310130251L;
037:
038: //---------------------------------------------------------------
039: /**
040: * The value that indicates if the argument list for this procedure
041: * includes all field-descriptors from the related class-descriptor.
042: */
043: private boolean includeAllFields;
044:
045: //---------------------------------------------------------------
046: /**
047: * Constructor declaration
048: */
049: public UpdateProcedureDescriptor(ClassDescriptor classDescriptor,
050: String name, boolean includeAllFields) {
051: super (classDescriptor, name);
052: if (includeAllFields) {
053: this .addArguments(this .getClassDescriptor()
054: .getFieldDescriptions());
055: }
056: this .includeAllFields = includeAllFields;
057: }
058:
059: //---------------------------------------------------------------
060: /**
061: * Retrieve the value that indicates if the argument list for this
062: * procedure includes all field-descriptors from the related
063: * class-descriptor.
064: *
065: * @return The current value
066: */
067: public boolean getIncludeAllFields() {
068: return this .includeAllFields;
069: }
070:
071: //---------------------------------------------------------------
072: /**
073: * Add an argument
074: * <p>
075: * The argument will be added only if this procedure is not configured
076: * to {@link #getIncludeAllFields() include all arguments}.
077: */
078: public final void addArgument(ArgumentDescriptor argument) {
079: if (!this .getIncludeAllFields()) {
080: super .addArgument(argument);
081: }
082: }
083:
084: /*
085: * @see XmlCapable#toXML()
086: */
087: public String toXML() {
088: RepositoryTags tags = RepositoryTags.getInstance();
089: String eol = System.getProperty("line.separator");
090:
091: // The result
092: StringBuffer result = new StringBuffer(1024);
093: result.append(eol);
094: result.append(" ");
095:
096: // Opening tag and attributes
097: result.append(" ");
098: result.append(tags
099: .getOpeningTagNonClosingById(UPDATE_PROCEDURE));
100: result.append(" ");
101: result.append(tags.getAttribute(NAME, this .getName()));
102: if (this .hasReturnValue()) {
103: result.append(" ");
104: result.append(tags.getAttribute(RETURN_FIELD_REF, this
105: .getReturnValueFieldRefName()));
106: }
107: result.append(" ");
108: result.append(tags.getAttribute(INCLUDE_ALL_FIELDS, String
109: .valueOf(this .getIncludeAllFields())));
110: result.append(">");
111: result.append(eol);
112:
113: // Write all arguments only if we're not including all fields.
114: if (!this .getIncludeAllFields()) {
115: Iterator args = this .getArguments().iterator();
116: while (args.hasNext()) {
117: result.append(((ArgumentDescriptor) args.next())
118: .toXML());
119: }
120: }
121:
122: // Closing tag
123: result.append(" ");
124: result.append(tags.getClosingTagById(UPDATE_PROCEDURE));
125: result.append(eol);
126: return result.toString();
127: }
128:
129: //---------------------------------------------------------------
130: /**
131: * Provide a string representation of this object
132: *
133: * @return a string representation of this object
134: */
135: public String toString() {
136: ToStringBuilder buf = new ToStringBuilder(this ,
137: ToStringStyle.MULTI_LINE_STYLE);
138: buf.append("name", this .getName());
139: buf.append("includeAllFields", this .getIncludeAllFields());
140: if (this .hasReturnValue()) {
141: buf.append("returnFieldRefName", this
142: .getReturnValueFieldRefName());
143: }
144: return buf.toString();
145: }
146: }
|