KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > wocompat > EOObjEntity


1 /* ====================================================================
2  *
3  * The ObjectStyle Group Software License, version 1.1
4  * ObjectStyle Group - http://objectstyle.org/
5  *
6  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
7  * of the software. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any,
22  * must include the following acknowlegement:
23  * "This product includes software developed by independent contributors
24  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
29  * or promote products derived from this software without prior written
30  * permission. For written permission, email
31  * "andrus at objectstyle dot org".
32  *
33  * 5. Products derived from this software may not be called "ObjectStyle"
34  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
35  * names without prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals and hosted on ObjectStyle Group web site. For more
53  * information on the ObjectStyle Group, please see
54  * <http://objectstyle.org/>.
55  */

56 package org.objectstyle.cayenne.wocompat;
57
58 import java.util.ArrayList JavaDoc;
59 import java.util.Collection JavaDoc;
60 import java.util.Collections JavaDoc;
61 import java.util.Map JavaDoc;
62
63 import org.objectstyle.cayenne.exp.Expression;
64 import org.objectstyle.cayenne.map.ObjEntity;
65 import org.objectstyle.cayenne.query.Query;
66
67 /**
68  * An EOObjEntity is a mapping descriptor of a Java class property with added fields for
69  * WebObjects EOModel. It is an informal "decorator" of Cayenne ObjEntity to provide
70  * access to the extra information of WebObjects EOEntity.
71  *
72  * @author Dario Bagatto
73  */

74 public class EOObjEntity extends ObjEntity {
75
76     // flag that indicates whether this Entity represents a client java class
77
protected boolean isClientEntity;
78     // flag that indicates whether this Entity has a superclass set in the eonmodel
79
protected boolean hasSuperClass;
80     // flag that indicates whether this Entity is set as abstract in the eomodel
81
protected boolean isAbstractEntity;
82
83     private Collection JavaDoc filteredQueries;
84
85     public EOObjEntity() {
86         super();
87     }
88
89    
90     public EOObjEntity(String JavaDoc s) {
91         super(s);
92     }
93     
94     /**
95      * Sets the the superclass state.
96      *
97      * @param value
98      */

99     public void setHasSuperClass(boolean value) {
100         hasSuperClass = value;
101     }
102
103     /**
104      * Returns the superclass state.
105      *
106      * @return true when there is a superclass defined in the eomodel.
107      */

108     public boolean getHasSuperClass() {
109         return hasSuperClass;
110     }
111
112     /**
113      * Sets the client entity state.
114      *
115      * @param value
116      */

117     public void setIsClientEntity(boolean value) {
118         isClientEntity = value;
119     }
120
121     /**
122      * Returns the client entity flag
123      *
124      * @return true when this entity object represents a client java class.
125      */

126     public boolean getIsClientEntity() {
127         return isClientEntity;
128     }
129
130     /**
131      * Sets the abstract entity flag.
132      *
133      * @param value
134      */

135     public void setIsAbstractEntity(boolean value) {
136         isAbstractEntity = value;
137     }
138
139     /**
140      * Returns the abstract Entity state
141      *
142      * @return true if this entity is set as abstract int the eomodel.
143      */

144     public boolean getIsAbstractEntity() {
145         return isAbstractEntity;
146     }
147
148     /**
149      * Translates query name local to the ObjEntity to the global name. This translation
150      * is needed since EOModels store queries by entity, while Cayenne DataMaps store them
151      * globally.
152      *
153      * @since 1.1
154      */

155     public String JavaDoc qualifiedQueryName(String JavaDoc queryName) {
156         return getName() + "_" + queryName;
157     }
158
159     /**
160      * @since 1.1
161      */

162     public String JavaDoc localQueryName(String JavaDoc qualifiedQueryName) {
163         return (qualifiedQueryName != null && qualifiedQueryName.startsWith(getName()
164                 + "_"))
165                 ? qualifiedQueryName.substring(getName().length() + 1)
166                 : qualifiedQueryName;
167     }
168
169     /**
170      * Returns stored EOQuery.
171      *
172      * @since 1.1
173      */

174     public EOQuery getEOQuery(String JavaDoc queryName) {
175         Query query = getDataMap().getQuery(qualifiedQueryName(queryName));
176         if (query instanceof EOQuery) {
177             return (EOQuery) query;
178         }
179
180         return null;
181     }
182
183     /**
184      * Returns a collection of queries for this entity.
185      *
186      * @since 1.1
187      */

188     public Collection JavaDoc getEOQueries() {
189         if (filteredQueries == null) {
190             Collection JavaDoc queries = getDataMap().getQueries();
191             if (queries.isEmpty()) {
192                 filteredQueries = Collections.EMPTY_LIST;
193             } else {
194                 Map JavaDoc params = Collections.singletonMap("root", EOObjEntity.this);
195                 Expression filter = Expression
196                         .fromString("root = $root")
197                         .expWithParameters(params);
198
199                 filteredQueries = filter.filter(queries, new ArrayList JavaDoc());
200             }
201         }
202
203         return filteredQueries;
204     }
205     
206 }
Popular Tags