Source Code Cross Referenced for SchemaClassDefinition.java in  » Web-Framework » roma-webwizard » org » romaframework » core » schema » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » roma webwizard » org.romaframework.core.schema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.romaframework.core.schema;
018:
019:        import java.util.ArrayList;
020:        import java.util.HashMap;
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import java.util.Map;
024:        import java.util.Map.Entry;
025:
026:        import org.romaframework.aspect.authentication.UserObjectPermissionListener;
027:        import org.romaframework.core.Utility;
028:        import org.romaframework.core.flow.Controller;
029:        import org.romaframework.core.flow.UserObjectEventListener;
030:        import org.romaframework.core.util.DynaBean;
031:
032:        public abstract class SchemaClassDefinition extends SchemaFeatures {
033:
034:            protected Map<String, SchemaField> fields;
035:            protected Map<String, SchemaAction> actions;
036:            protected Map<String, SchemaEvent> events;
037:
038:            protected List<SchemaField> orderedFields;
039:            protected List<SchemaAction> orderedActions;
040:
041:            public SchemaClassDefinition() {
042:                fields = new HashMap<String, SchemaField>();
043:                actions = new HashMap<String, SchemaAction>();
044:                events = new HashMap<String, SchemaEvent>();
045:
046:                orderedFields = new ArrayList<SchemaField>();
047:                orderedActions = new ArrayList<SchemaAction>();
048:            }
049:
050:            public abstract SchemaClass getSchemaClass();
051:
052:            public SchemaField getField(String iFieldName) {
053:                String fieldName;
054:                int sepPos = iFieldName.indexOf(Utility.PACKAGE_SEPARATOR);
055:                if (sepPos == -1)
056:                    fieldName = iFieldName;
057:                else
058:                    fieldName = iFieldName.substring(0, sepPos);
059:
060:                SchemaField field = fields.get(fieldName);
061:
062:                if (sepPos > -1)
063:                    field = field.getComplexClass().getField(
064:                            iFieldName.substring(sepPos + 1));
065:
066:                return field;
067:            }
068:
069:            public Iterator<SchemaField> getFieldIterator() {
070:                return orderedFields.iterator();
071:            }
072:
073:            public SchemaAction getAction(String iActionName) {
074:                String actionName;
075:                Map<String, SchemaAction> localActions = null;
076:
077:                int sepPos = iActionName.indexOf(Utility.PACKAGE_SEPARATOR);
078:                if (sepPos == -1) {
079:                    localActions = actions;
080:                    actionName = iActionName;
081:                } else {
082:                    // FOLLOW THE PATH UNTIL LAST FIELD AND THEN GET THE ACTION
083:                    SchemaField field = getField(iActionName.substring(0,
084:                            sepPos));
085:                    if (field == null)
086:                        return null;
087:
088:                    localActions = field.getComplexClass().actions;
089:                    actionName = iActionName.substring(sepPos + 1);
090:                }
091:
092:                SchemaAction action = localActions.get(actionName);
093:
094:                return action;
095:            }
096:
097:            public Iterator<SchemaAction> getActionIterator() {
098:                return orderedActions.iterator();
099:            }
100:
101:            public SchemaEvent getEvent(String iEventName) {
102:                return events.get(iEventName);
103:            }
104:
105:            public Iterator<SchemaEvent> getEventIterator() {
106:                return events.values().iterator();
107:            }
108:
109:            /**
110:             * Copy the definition from class schema.
111:             * 
112:             * @param iSource
113:             */
114:            public void copyDefinition(SchemaClassDefinition iSource) {
115:                try {
116:                    // COPY ALL FEATURES FROM PARENT ENTITY
117:                    DynaBean features;
118:                    for (Entry<String, DynaBean> entry : iSource
119:                            .getAllFeatures().entrySet()) {
120:                        features = (DynaBean) entry.getValue().clone();
121:                        allFeatures.put(entry.getKey(), features);
122:                    }
123:
124:                    boolean allowed;
125:
126:                    // COPY ALL FIELDS FROM PARENT ENTITY
127:                    SchemaField field;
128:                    SchemaField sourceSchemaField;
129:                    for (Iterator<SchemaField> it = iSource.getFieldIterator(); it
130:                            .hasNext();) {
131:                        sourceSchemaField = it.next();
132:
133:                        // CHECK IF ALLOWED
134:                        List<UserObjectPermissionListener> listeners = Controller
135:                                .getInstance().getListeners(
136:                                        UserObjectPermissionListener.class);
137:                        if (listeners != null) {
138:                            synchronized (listeners) {
139:                                allowed = true;
140:                                for (UserObjectPermissionListener listener : listeners) {
141:                                    if (!listener.allowField(getSchemaClass()
142:                                            .getClazz(), sourceSchemaField)) {
143:                                        // NOT ALLOWED
144:                                        allowed = false;
145:                                        break;
146:                                    }
147:                                }
148:                            }
149:
150:                            if (!allowed)
151:                                continue;
152:                        }
153:
154:                        field = (SchemaField) sourceSchemaField.clone();
155:                        field.entity = this ;
156:                        setField(field.getName(), field);
157:                    }
158:
159:                    // COPY ALL ACTIONS FROM PARENT ENTITY
160:                    SchemaAction action;
161:                    SchemaElement sourceSchemaAction;
162:                    for (Iterator<SchemaAction> it = iSource
163:                            .getActionIterator(); it.hasNext();) {
164:                        sourceSchemaAction = it.next();
165:
166:                        // CHECK IF ALLOWED
167:                        List<UserObjectPermissionListener> listeners = Controller
168:                                .getInstance().getListeners(
169:                                        UserObjectPermissionListener.class);
170:                        if (listeners != null) {
171:                            synchronized (listeners) {
172:                                allowed = true;
173:                                for (UserObjectPermissionListener listener : listeners) {
174:                                    if (!listener.allowAction(getSchemaClass()
175:                                            .getClazz(), sourceSchemaAction)) {
176:                                        // NOT ALLOWED
177:                                        allowed = false;
178:                                        break;
179:                                    }
180:                                }
181:                            }
182:
183:                            if (!allowed)
184:                                continue;
185:                        }
186:
187:                        action = (SchemaAction) sourceSchemaAction.clone();
188:                        action.entity = this ;
189:                        setAction(action.getName(), action);
190:                    }
191:
192:                    // COPY ALL EVENTS FROM PARENT ENTITY
193:                    SchemaEvent event;
194:                    for (Iterator<SchemaEvent> it = iSource.getEventIterator(); it
195:                            .hasNext();) {
196:                        event = (SchemaEvent) it.next().clone();
197:                        event.entity = this ;
198:                        setEvent(event.getName(), event);
199:                    }
200:                } catch (CloneNotSupportedException e) {
201:                }
202:            }
203:
204:            public void setField(String iFieldName, SchemaField iField) {
205:                if (fields.containsKey(iFieldName)) {
206:                    // REPLACE IT
207:                    for (int i = 0; i < orderedFields.size(); ++i) {
208:                        if (orderedFields.get(i).getName().equals(iFieldName)) {
209:                            orderedFields.remove(i);
210:                            break;
211:                        }
212:                    }
213:                }
214:
215:                orderedFields.add(iField);
216:                fields.put(iFieldName, iField);
217:            }
218:
219:            public void setAction(String iActionName, SchemaAction iAction) {
220:                if (actions.containsKey(iActionName)) {
221:                    // REPLACE IT
222:                    for (int i = 0; i < orderedActions.size(); ++i) {
223:                        if (orderedActions.get(i).getName().equals(iActionName)) {
224:                            orderedActions.remove(i);
225:                            break;
226:                        }
227:                    }
228:                }
229:
230:                orderedActions.add(iAction);
231:                actions.put(iActionName, iAction);
232:            }
233:
234:            public void setEvent(String iEventName, SchemaEvent iEvent) {
235:                events.put(iEventName, iEvent);
236:            }
237:
238:            public void setOrderFields(List<SchemaField> iFields) {
239:                orderedFields = iFields;
240:            }
241:
242:            public void setOrderActions(List<SchemaAction> iActions) {
243:                orderedActions = iActions;
244:            }
245:
246:            public Map<String, SchemaField> getFields() {
247:                return fields;
248:            }
249:
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.