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.1 2007-08-24 22:17:29 ewestfal Exp $
027     */
028    public class IndexDescriptor implements XmlCapable, Serializable
029    {
030            private static final long serialVersionUID = -1722513568634970108L;
031        private String name;
032        private boolean unique;
033        private Vector indexColumns = new Vector();
034    
035        public boolean isUnique()
036        {
037            return unique;
038        }
039    
040        public void setUnique(boolean unique)
041        {
042            this.unique = unique;
043        }
044    
045        public String getName()
046        {
047            return name;
048        }
049    
050        public void setName(String name)
051        {
052            this.name = name;
053        }
054    
055        public Vector getIndexColumns()
056        {
057            return this.indexColumns;
058        }
059    
060        public void setIndexColumns(Vector indexColumns)
061        {
062            this.indexColumns = indexColumns;
063        }
064    
065        /*
066         * @see XmlCapable#toXML()
067         */
068        public String toXML()
069        {
070            RepositoryTags tags = RepositoryTags.getInstance();
071            String eol = SystemUtils.LINE_SEPARATOR;
072    
073            //opening tag + attributes
074            StringBuffer result = new StringBuffer( 1024 );
075            result.append( "      <" );
076            result.append( tags.getTagById( INDEX_DESCRIPTOR ) );
077            result.append( " " );
078    
079            // index name
080            result.append( tags.getAttribute( NAME, getName() ) );
081            result.append( " " );
082    
083            // unique attribute
084            result.append( tags.getAttribute( UNIQUE, "" + isUnique() ) );
085            result.append( ">" );
086            result.append( eol );
087    
088            // index columns
089            for( int i = 0; i < indexColumns.size(); i++ )
090            {
091                String l_name = ( String ) indexColumns.elementAt( i );
092                result.append( "                " );
093                result.append( tags.getOpeningTagNonClosingById( INDEX_COLUMN ) );
094                result.append( " " );
095                result.append( tags.getAttribute( NAME, l_name ) );
096                result.append( " />" );
097                result.append( eol );
098            }
099    
100            // closing tag
101            result.append( "      " );
102            result.append( tags.getClosingTagById( INDEX_DESCRIPTOR ) );
103            result.append( " " );
104            result.append( eol );
105    
106            return result.toString();
107        }
108    
109    }