KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > metadata > DeleteProcedureDescriptor


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 JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 /**
24  * An DeleteProcedureDescriptor contains information that is related to the
25  * procedure/function that is used to handle the deleting of existing records.
26  * <br>
27  * Note: Be careful when use DeleteProcedureDescriptor variables or caching
28  * DeleteProcedureDescriptor 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: DeleteProcedureDescriptor.java,v 1.7.2.3 2005/12/21 22:26:11 tomdz Exp $
33  */

34 public class DeleteProcedureDescriptor extends ProcedureDescriptor
35     implements Serializable JavaDoc, XmlCapable
36 {
37     private static final long serialVersionUID = -1265854095889157172L;
38     //---------------------------------------------------------------
39
/**
40      * The value that indicates if the argument list for this procedure
41      * includes only the field-descriptors from the related class-descriptor
42      * that are identified as being part of the primary key.
43      */

44     private boolean includePkFieldsOnly;
45
46     //---------------------------------------------------------------
47

48     /**
49      * Constructor declaration
50      */

51     public DeleteProcedureDescriptor(ClassDescriptor classDescriptor,
52             String JavaDoc name, boolean includePkFieldsOnly)
53     {
54         super(classDescriptor, name);
55         if (includePkFieldsOnly)
56         {
57             addArguments(getClassDescriptor().getPkFields());
58             addArguments(getClassDescriptor().getLockingFields());
59         }
60         this.includePkFieldsOnly = includePkFieldsOnly;
61     }
62
63     //---------------------------------------------------------------
64
/**
65      * Retrieve the value that indicates if the argument list for this
66      * procedure includes only the field-descriptors from the related
67      * class-descriptor that are identified as being part of the primary
68      * key.
69      *
70      * @return The current value
71      */

72     public boolean getIncludePkFieldsOnly()
73     {
74         return this.includePkFieldsOnly;
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 #getIncludePkFieldsOnly() include just the
83      * primary key fields}.
84      */

85     public final void addArgument(ArgumentDescriptor argument)
86     {
87         if (!this.getIncludePkFieldsOnly())
88         {
89             super.addArgument(argument);
90         }
91     }
92
93     /*
94      * @see XmlCapable#toXML()
95      */

96     public String JavaDoc toXML()
97     {
98         RepositoryTags tags = RepositoryTags.getInstance();
99         String JavaDoc eol = System.getProperty( "line.separator" );
100
101         // The result
102
StringBuffer JavaDoc result = new StringBuffer JavaDoc( 1024 );
103         result.append( eol );
104         result.append( " " );
105
106         // Opening tag and attributes
107
result.append( " " );
108         result.append( tags.getOpeningTagNonClosingById( DELETE_PROCEDURE ) );
109         result.append( " " );
110         result.append( tags.getAttribute( NAME, this.getName() ) );
111         if( this.hasReturnValue() )
112         {
113             result.append( " " );
114             result.append( tags.getAttribute( RETURN_FIELD_REF, this.getReturnValueFieldRefName() ) );
115         }
116         result.append( " " );
117         result.append( tags.getAttribute( INCLUDE_PK_FIELDS_ONLY, String.valueOf( this.getIncludePkFieldsOnly() ) ) );
118         result.append( ">" );
119         result.append( eol );
120
121         // Write all arguments only if we're not including all fields.
122
if( !this.getIncludePkFieldsOnly() )
123         {
124             Iterator JavaDoc args = this.getArguments().iterator();
125             while( args.hasNext() )
126             {
127                 result.append( ( ( ArgumentDescriptor ) args.next() ).toXML() );
128             }
129         }
130
131         // Closing tag
132
result.append( " " );
133         result.append( tags.getClosingTagById( DELETE_PROCEDURE ) );
134         result.append( eol );
135         return result.toString();
136     }
137
138     //---------------------------------------------------------------
139
/**
140      * Provide a string representation of this object
141      *
142      * @return a string representation of this object
143      */

144     public String JavaDoc toString()
145     {
146         ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
147         buf.append("name", this.getName());
148         buf.append("includePkFieldsOnly", this.getIncludePkFieldsOnly());
149         if (this.hasReturnValue())
150         {
151             buf.append("returnFieldRefName", this.getReturnValueFieldRefName());
152         }
153         return buf.toString();
154     }
155 }
156
Popular Tags