View Javadoc

1   /*
2    * Copyright 2006 Outsource Cafe, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the 'License')
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an 'AS IS' BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.javagen.agile.oo.model;
17  
18  import javax.xml.bind.annotation.XmlIDREF;
19  import javax.xml.bind.annotation.XmlRootElement;
20  
21  
22  /***
23   * Models a Object-Oriented class reference by extending a class property.  
24   * <p>
25   * References are between model classes, if the class
26   * you are referencing is in a external library, you must at least provide a Class with a name in 
27   * order to model a reference.
28   *
29   * @author Richard Easterling
30   */
31  @XmlRootElement
32  public class Reference extends Property {
33  
34      public static final String DEFAULT_MODEL_TYPE = "REFERENCE";
35  
36      public enum LocalCardinality {ONE, MANY };
37  	
38  	protected Reference reverse;
39  	protected Class targetType;
40  
41  	public Reference() {
42          setModelType(DEFAULT_MODEL_TYPE);
43  	}
44  	
45      public LocalCardinality getCardinality() {
46  		return collectionType==null ? LocalCardinality.ONE : LocalCardinality.MANY;
47  	}
48  
49      @XmlIDREF
50  	public Reference getReverse() {
51  		return reverse;
52  	}
53  
54  	public void setReverse(Reference reverse) {
55  		this.reverse = reverse;
56  	}
57  
58      @XmlIDREF
59  	public Class getTargetType() {
60  		return targetType;
61  	}
62  
63  	public void setTargetType(Class targetType) {
64  		this.targetType = targetType;
65  	}
66  
67      @Override
68      public String getType() {
69          if (super.getType()==null && getTargetType()!=null) {
70              setType(getTargetType().getName());
71          }
72          return super.getType();
73      }
74  
75  }