001: package org.apache.ojb.broker.metadata;
002:
003: /* Copyright 2002-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.SystemUtils;
019:
020: import java.util.Vector;
021: import java.io.Serializable;
022:
023: /**
024: *
025: *
026: * @version $Id: IndexDescriptor.java,v 1.12.2.1 2005/12/21 22:26:10 tomdz Exp $
027: */
028: public class IndexDescriptor implements XmlCapable, Serializable {
029: private static final long serialVersionUID = -1722513568634970108L;
030: private String name;
031: private boolean unique;
032: private Vector indexColumns = new Vector();
033:
034: public boolean isUnique() {
035: return unique;
036: }
037:
038: public void setUnique(boolean unique) {
039: this .unique = unique;
040: }
041:
042: public String getName() {
043: return name;
044: }
045:
046: public void setName(String name) {
047: this .name = name;
048: }
049:
050: public Vector getIndexColumns() {
051: return this .indexColumns;
052: }
053:
054: public void setIndexColumns(Vector indexColumns) {
055: this .indexColumns = indexColumns;
056: }
057:
058: /*
059: * @see XmlCapable#toXML()
060: */
061: public String toXML() {
062: RepositoryTags tags = RepositoryTags.getInstance();
063: String eol = SystemUtils.LINE_SEPARATOR;
064:
065: //opening tag + attributes
066: StringBuffer result = new StringBuffer(1024);
067: result.append(" <");
068: result.append(tags.getTagById(INDEX_DESCRIPTOR));
069: result.append(" ");
070:
071: // index name
072: result.append(tags.getAttribute(NAME, getName()));
073: result.append(" ");
074:
075: // unique attribute
076: result.append(tags.getAttribute(UNIQUE, "" + isUnique()));
077: result.append(">");
078: result.append(eol);
079:
080: // index columns
081: for (int i = 0; i < indexColumns.size(); i++) {
082: String l_name = (String) indexColumns.elementAt(i);
083: result.append(" ");
084: result.append(tags
085: .getOpeningTagNonClosingById(INDEX_COLUMN));
086: result.append(" ");
087: result.append(tags.getAttribute(NAME, l_name));
088: result.append(" />");
089: result.append(eol);
090: }
091:
092: // closing tag
093: result.append(" ");
094: result.append(tags.getClosingTagById(INDEX_DESCRIPTOR));
095: result.append(" ");
096: result.append(eol);
097:
098: return result.toString();
099: }
100:
101: }
|