Source code: com/gammastream/validity/GSVEOEntity.java
1 package com.gammastream.validity;
2
3 import com.webobjects.foundation.*;
4 import com.webobjects.appserver.*;
5 import com.webobjects.eocontrol.*;
6 import com.webobjects.eoaccess.*;
7 import java.io.*;
8
9 public class GSVEOEntity {
10
11 private GSVEOModel model = null;
12 private NSDictionary entity = null;
13 private NSArray attributes = null;
14 private NSArray gsveoAttributes = null;
15 private NSArray attributesUsedForLocking = null;
16 private String className = null;
17 private String name = null;
18 private String externalName = null;
19 private NSArray classProperties = null;
20 private NSArray primaryKeyAttributes = null;
21 private NSArray relationships = null;
22
23 public GSVEOEntity(GSVEOModel m, String n){
24 model = m;
25 name = n;
26 try{
27 File f = new File(model.path()+"/"+n+".plist");
28 FileInputStream fis = new FileInputStream(f);
29 byte[] bytes = new byte[(int)f.length()];
30 fis.read(bytes);
31 entity = (NSDictionary)NSPropertyListSerialization.propertyListFromString(new String(bytes));
32 }catch(IOException e){System.out.println(e);}
33 }
34
35 public String name(){
36 return name;
37 }
38
39 public NSArray attributes(){
40 if(attributes != null)
41 return attributes;
42 attributes = (NSArray)entity.objectForKey("attributes");
43 return attributes;
44 }
45
46 public NSArray gsveoAttributes(){
47 if(gsveoAttributes != null)
48 return gsveoAttributes;
49 NSMutableArray temp = new NSMutableArray();
50 if(attributes()!=null){
51 for(int i=0;i<attributes().count();i++)
52 temp.addObject(new GSVEOAttribute(this, (NSDictionary)(attributes().objectAtIndex(i))));
53 gsveoAttributes = temp;
54 }else{
55 gsveoAttributes = new NSArray();
56 }
57 return gsveoAttributes;
58 }
59
60 public NSArray attributesUsedForLocking(){
61 if(attributesUsedForLocking != null)
62 return attributesUsedForLocking;
63 attributesUsedForLocking = (NSArray)entity.objectForKey("attributesUsedForLocking");
64 return attributesUsedForLocking;
65 }
66
67 public NSArray classProperties(){
68 if(classProperties != null)
69 return classProperties;
70 classProperties = (NSArray)entity.objectForKey("classProperties");
71 return classProperties;
72 }
73
74 public String className(){
75 if(className != null)
76 return className;
77 className = (String)entity.objectForKey("className");
78 return className;
79 }
80
81 public String externalName(){
82 if(externalName != null)
83 return externalName;
84 externalName = (String)entity.objectForKey("externalName");
85 return externalName;
86 }
87
88 public NSArray primaryKeyAttributes(){
89 if(primaryKeyAttributes != null)
90 return primaryKeyAttributes;
91 primaryKeyAttributes = (NSArray)entity.objectForKey("primaryKeyAttributes");
92 return primaryKeyAttributes;
93 }
94
95 public NSArray relationships(){
96 if(relationships != null)
97 return relationships;
98 relationships = (NSArray)entity.objectForKey("relationships");
99 return relationships;
100 }
101
102 public GSVEOModel model(){
103 return model;
104 }
105
106 public GSVEOAttribute attributeNamed(String name){
107 NSDictionary currentAttribute = null;
108 for(int i=0;i<this.attributes().count();i++){
109 currentAttribute = (NSDictionary)this.attributes().objectAtIndex(i);
110 if(currentAttribute.objectForKey("name").equals(name))
111 return new GSVEOAttribute(this,currentAttribute);
112 }
113 return null;
114 }
115
116
117 }