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.ojb.broker.metadata.fieldaccess.PersistentField;
019 import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldFactory;
020
021 import java.io.Serializable;
022
023 /**
024 * Is the base class for all other attribute descriptors.
025 * It holds basic the mapping information for a specific attribute.
026 *
027 * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
028 * @version $Id: AttributeDescriptorBase.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $
029 */
030 public class AttributeDescriptorBase extends DescriptorBase implements Serializable
031 {
032 private static final long serialVersionUID = -818671542770428043L;
033
034 protected PersistentField m_PersistentField = null;
035 protected ClassDescriptor m_ClassDescriptor = null;
036
037 /**
038 * Constructor declaration
039 */
040 public AttributeDescriptorBase(ClassDescriptor descriptor)
041 {
042 this.m_ClassDescriptor = descriptor;
043 }
044
045 /**
046 * @throws MetadataException if an error occours when setting the PersistenteField
047 */
048 public void setPersistentField(Class c, String fieldname)
049 {
050 m_PersistentField = PersistentFieldFactory.createPersistentField(c, fieldname);
051 }
052
053 public void setPersistentField(PersistentField pf)
054 {
055 m_PersistentField = pf;
056 }
057
058 /**
059 *
060 */
061 public PersistentField getPersistentField()
062 {
063 return m_PersistentField;
064 }
065
066 /**
067 * @return the name of the Attribute
068 */
069 public String getAttributeName()
070 {
071 return getPersistentField().getName();
072 }
073
074 /**
075 * Gets the classDescriptor.
076 * @return Returns a ClassDescriptor
077 */
078 public ClassDescriptor getClassDescriptor()
079 {
080 return m_ClassDescriptor;
081 }
082
083 /**
084 * Sets the classDescriptor.
085 * @param classDescriptor The classDescriptor to set
086 */
087 public void setClassDescriptor(ClassDescriptor classDescriptor)
088 {
089 m_ClassDescriptor = classDescriptor;
090 }
091
092 public String toString()
093 {
094 StringBuffer buf = new StringBuffer();
095 buf.append(m_PersistentField);
096 buf.append(", field_belongs_to " + m_ClassDescriptor.getClassNameOfObject());
097 buf.append(", "+super.toString());
098 return buf.toString();
099 }
100 }