001: /**********************************************************************
002: Copyright (c) 2007 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: ...
017: **********************************************************************/package org.jpox.metadata;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.jpox.util.StringUtils;
024:
025: /**
026: * FetchPlan defined in MetaData.
027: *
028: * @since 1.1
029: * @version $Revision: 1.12 $
030: */
031: public class FetchPlanMetaData extends MetaData {
032: /** Name of the FetchPlan. */
033: final String name;
034:
035: /** Max fetch depth for this FetchPlan. */
036: protected int maxFetchDepth = -1;
037:
038: /** Fetch Size for use when querying using this FetchPlan. */
039: protected int fetchSize = -1;
040:
041: /** Series of Fetch Groups used in this FetchPlan. Only used during construction. */
042: protected List fetchGroups = new ArrayList();
043:
044: /**
045: * Constructor.
046: * @param parent The parent MetaData
047: * @param name Name of fetch plan
048: * @param depth Max fetch depth
049: * @param size Fetch size for this fetch plan
050: */
051: public FetchPlanMetaData(MetaData parent, String name,
052: String depth, String size) {
053: super (parent);
054:
055: this .name = name;
056: if (!StringUtils.isWhitespace(depth)) {
057: try {
058: this .maxFetchDepth = (new Integer(depth)).intValue();
059: } catch (NumberFormatException nfe) {
060: this .maxFetchDepth = -1;
061: }
062: }
063: if (!StringUtils.isWhitespace(size)) {
064: try {
065: this .fetchSize = (new Integer(size)).intValue();
066: } catch (NumberFormatException nfe) {
067: this .fetchSize = -1;
068: }
069: }
070: }
071:
072: /**
073: * Accessor for name
074: * @return Returns the name.
075: */
076: public final String getName() {
077: return name;
078: }
079:
080: /**
081: * Accessor for the maximum fetch depth.
082: * @return Returns the max fetch depth
083: */
084: public final int getMaxFetchDepth() {
085: return maxFetchDepth;
086: }
087:
088: /**
089: * Accessor for the fetch size.
090: * @return Returns the fetch size
091: */
092: public final int getFetchSize() {
093: return fetchSize;
094: }
095:
096: /**
097: * Accessor for fetchGroupMetaData
098: * @return Returns the fetchGroupMetaData.
099: */
100: public final FetchGroupMetaData[] getFetchGroupMetaData() {
101: return (FetchGroupMetaData[]) fetchGroups
102: .toArray(new FetchGroupMetaData[fetchGroups.size()]);
103: }
104:
105: /**
106: * Add a new FetchGroupMetaData
107: * @param fgmd the fetch group
108: */
109: public void addFetchGroup(FetchGroupMetaData fgmd) {
110: fetchGroups.add(fgmd);
111: }
112:
113: // ----------------------------- Utilities ------------------------------------
114:
115: /**
116: * Returns a string representation of the object.
117: * This can be used as part of a facility to output a MetaData file.
118: * @param prefix prefix string
119: * @param indent indent string
120: * @return a string representation of the object.
121: */
122: public String toString(String prefix, String indent) {
123: StringBuffer sb = new StringBuffer();
124: sb.append(prefix).append(
125: "<fetch-plan name=\"" + name + "\""
126: + " max-fetch-depth=\"" + maxFetchDepth + "\""
127: + " fetch-size=\"" + fetchSize + "\"\n");
128:
129: // Add fetch-groups
130: Iterator iter = fetchGroups.iterator();
131: while (iter.hasNext()) {
132: FetchGroupMetaData fgmd = (FetchGroupMetaData) iter.next();
133: sb.append(fgmd.toString(prefix + indent, indent));
134: }
135:
136: sb.append(prefix + "</fetch-plan>\n");
137: return sb.toString();
138: }
139: }
|