KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > map > Attribute


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20
21 package org.apache.cayenne.map;
22
23 import java.io.Serializable JavaDoc;
24
25 import org.apache.cayenne.util.CayenneMapEntry;
26 import org.apache.cayenne.util.XMLEncoder;
27 import org.apache.cayenne.util.XMLSerializable;
28
29 /**
30  * Defines a property descriptor that is a part of an Entity. Two examples of things that
31  * are described by attributes are Java class properties and database table columns.
32  *
33  * @author Andrus Adamchik
34  */

35 public abstract class Attribute implements CayenneMapEntry, XMLSerializable, Serializable JavaDoc {
36
37     protected String JavaDoc name;
38     protected Entity entity;
39
40     /**
41      * Creates an unnamed Attribute.
42      */

43     public Attribute() {
44     }
45
46     /**
47      * Creates a named Attribute.
48      */

49     public Attribute(String JavaDoc name) {
50         this.name = name;
51     }
52     
53     public abstract void encodeAsXML(XMLEncoder encoder);
54
55     /**
56      * Returns parent entity that holds this attribute.
57      */

58     public Entity getEntity() {
59         return entity;
60     }
61
62     /**
63      * Sets parent entity that holds this attribute.
64      */

65     public void setEntity(Entity entity) {
66         this.entity = entity;
67     }
68
69     public String JavaDoc getName() {
70         return name;
71     }
72
73     public void setName(String JavaDoc name) {
74         this.name = name;
75     }
76
77     public Object JavaDoc getParent() {
78         return getEntity();
79     }
80
81     public void setParent(Object JavaDoc parent) {
82         if (parent != null && !(parent instanceof Entity)) {
83             throw new IllegalArgumentException JavaDoc("Expected null or Entity, got: " + parent);
84         }
85
86         setEntity((Entity) parent);
87     }
88 }
89
Popular Tags