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.List;
021:
022: import org.jpox.util.StringUtils;
023:
024: /**
025: * Abstract representation of an ORM constraint.
026: * @version $Revision: 1.6 $
027: */
028: public class AbstractConstraintMetaData extends MetaData {
029: /** the constraint name */
030: protected String name;
031:
032: /** the constraint table name. Name of the table to which this applies (null implies the enclosing class' table). */
033: protected String table;
034:
035: /** Contains the metadata for fields/properties. */
036: protected AbstractMemberMetaData[] memberMetaData;
037:
038: /** Contains the metadata for columns */
039: protected ColumnMetaData[] columnMetaData;
040:
041: // -------------------------------------------------------------------------
042: // Fields below here are used in the metadata parse process where the parser
043: // dynamically adds fields/columns as it encounters them in the MetaData files.
044: // They are typically cleared at the point of initialise() and not used thereafter.
045:
046: /** The fields/properties for this constraint. */
047: protected List members = new ArrayList();
048:
049: /** The columns for this constraint. */
050: protected List columns = new ArrayList();
051:
052: /**
053: * Constructor.
054: * @param parent Parent (if required to be set)
055: * @param name Name of the constraint
056: * @param table Name of table for the constraint
057: */
058: public AbstractConstraintMetaData(MetaData parent, String name,
059: String table) {
060: super (parent);
061:
062: this .name = (StringUtils.isWhitespace(name) ? null : name);
063: this .table = (StringUtils.isWhitespace(table) ? null : table);
064: }
065:
066: /**
067: * Add a new member that is part of this constraint.
068: * @param mmd MetaData for the field/property
069: */
070: public void addMember(AbstractMemberMetaData mmd) {
071: members.add(mmd);
072: }
073:
074: /**
075: * Add a new ColumnMetaData element
076: * @param colmd MetaData for the column
077: */
078: public void addColumn(ColumnMetaData colmd) {
079: columns.add(colmd);
080: }
081:
082: /**
083: * Mutator for the constraint name.
084: * @param name Name of the constraint.
085: */
086: public void setName(String name) {
087: this .name = name;
088: }
089:
090: /**
091: * Accessor for the name of the constraint
092: * @return Returns the name.
093: */
094: public final String getName() {
095: return name;
096: }
097:
098: /**
099: * Accessor for the name of the table
100: * @return Returns the table.
101: */
102: public final String getTable() {
103: return table;
104: }
105:
106: /**
107: * Accessor for metadata for all fields/properties that this constraint relates to.
108: * @return Returns the memberMetaData.
109: */
110: public final AbstractMemberMetaData[] getMemberMetaData() {
111: return memberMetaData;
112: }
113:
114: /**
115: * Accessor for columnMetaData
116: * @return Returns the columnMetaData.
117: */
118: public final ColumnMetaData[] getColumnMetaData() {
119: return columnMetaData;
120: }
121:
122: /**
123: * Accessor for the number of fields/properties for this constraint.
124: * @return Number of fields/properties
125: */
126: public int getNumberOfMembers() {
127: if (members != null) {
128: return members.size();
129: } else if (memberMetaData != null) {
130: return memberMetaData.length;
131: }
132: return 0;
133: }
134:
135: /**
136: * Accessor for the number of columns for this constraint.
137: * @return Number of columns
138: */
139: public int getNumberOfColumns() {
140: if (columns != null) {
141: return columns.size();
142: } else if (columnMetaData != null) {
143: return columnMetaData.length;
144: }
145: return 0;
146: }
147: }
|