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