Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UpdateProcedureDescriptor |
|
| 2.2;2.2 |
1 | package org.apache.ojb.broker.metadata; | |
2 | ||
3 | /* Copyright 2003-2005 The Apache Software Foundation | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | import org.apache.commons.lang.builder.ToStringBuilder; | |
19 | import org.apache.commons.lang.builder.ToStringStyle; | |
20 | import java.io.Serializable; | |
21 | import java.util.Iterator; | |
22 | ||
23 | /** | |
24 | * An UpdateProcedureDescriptor contains information that is related to the | |
25 | * procedure/function that is used to handle the updating of existing records. | |
26 | * <br> | |
27 | * Note: Be careful when use UpdateProcedureDescriptor variables or caching | |
28 | * UpdateProcedureDescriptor instances, because instances could become invalid | |
29 | * during runtime (see {@link MetadataManager}). | |
30 | * | |
31 | * @author <a href="mailto:rongallagher@bellsouth.net">Ron Gallagher<a> | |
32 | * @version $Id: UpdateProcedureDescriptor.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $ | |
33 | */ | |
34 | public class UpdateProcedureDescriptor | |
35 | extends ProcedureDescriptor | |
36 | implements Serializable, XmlCapable | |
37 | { | |
38 | private static final long serialVersionUID = 1319547080310130251L; | |
39 | ||
40 | //--------------------------------------------------------------- | |
41 | /** | |
42 | * The value that indicates if the argument list for this procedure | |
43 | * includes all field-descriptors from the related class-descriptor. | |
44 | */ | |
45 | private boolean includeAllFields; | |
46 | ||
47 | //--------------------------------------------------------------- | |
48 | /** | |
49 | * Constructor declaration | |
50 | */ | |
51 | public UpdateProcedureDescriptor( | |
52 | ClassDescriptor classDescriptor, | |
53 | String name, | |
54 | boolean includeAllFields) | |
55 | { | |
56 | super(classDescriptor, name); | |
57 | if (includeAllFields) | |
58 | { | |
59 | this.addArguments(this.getClassDescriptor().getFieldDescriptions()); | |
60 | } | |
61 | this.includeAllFields = includeAllFields; | |
62 | } | |
63 | ||
64 | //--------------------------------------------------------------- | |
65 | /** | |
66 | * Retrieve the value that indicates if the argument list for this | |
67 | * procedure includes all field-descriptors from the related | |
68 | * class-descriptor. | |
69 | * | |
70 | * @return The current value | |
71 | */ | |
72 | public boolean getIncludeAllFields() | |
73 | { | |
74 | return this.includeAllFields; | |
75 | } | |
76 | ||
77 | //--------------------------------------------------------------- | |
78 | /** | |
79 | * Add an argument | |
80 | * <p> | |
81 | * The argument will be added only if this procedure is not configured | |
82 | * to {@link #getIncludeAllFields() include all arguments}. | |
83 | */ | |
84 | public final void addArgument(ArgumentDescriptor argument) | |
85 | { | |
86 | if (!this.getIncludeAllFields()) | |
87 | { | |
88 | super.addArgument(argument); | |
89 | } | |
90 | } | |
91 | ||
92 | /* | |
93 | * @see XmlCapable#toXML() | |
94 | */ | |
95 | public String toXML() | |
96 | { | |
97 | RepositoryTags tags = RepositoryTags.getInstance(); | |
98 | String eol = System.getProperty("line.separator"); | |
99 | ||
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 | } |