KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmfCommon > CreateController


1 package ist.coach.coachEmfCommon;
2
3 import org.omg.CosNaming.NameComponent JavaDoc;
4 import intt.itu.itut_x780.UIDType;
5 import intt.itu.itut_x780.CreateError;
6 import intt.itu.itut_x780.ApplicationError;
7
8
9 public class CreateController {
10
11     public static synchronized CreateBindingInfo checkNameBinding(String JavaDoc nameBinding_str)
12     throws CreateError{
13
14         short deletePolicy = -1;
15         boolean managerMayCreatePolicy = false;
16         String JavaDoc objectKind = new String JavaDoc();
17
18         CreateBindingInfo info = new CreateBindingInfo();
19
20         try {
21             Class JavaDoc deletePolicyClass =
22                 Class.forName(nameBinding_str + ".deletePolicy");
23
24             deletePolicy =
25                 deletePolicyClass.getDeclaredField("value").getShort(null);
26
27             Class JavaDoc managerMayCreatePolicyClass =
28                     Class.forName(nameBinding_str + ".managersMayCreate");
29             managerMayCreatePolicy =
30                 managerMayCreatePolicyClass.getDeclaredField("value").getBoolean(null);
31
32             Class JavaDoc objectKindClass =
33                      Class.forName(nameBinding_str + ".kind");
34             objectKind = ((String JavaDoc) objectKindClass.getDeclaredField("value").get(null)).trim();
35
36            // System.err.println("deletePolicy = " + deletePolicy +
37
// "managerMayCreatePolicy = " + managerMayCreatePolicy +
38
// "objectKind = " + objectKind);
39
}
40         catch(java.lang.ClassNotFoundException JavaDoc ex) {
41             System.err.println(nameBinding_str + " can not be found!" + ex.getMessage());
42             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
43             error_code.error = new UIDType(
44                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
45                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
46                error_code.details = ExceptionMessages.namebinding_exists_error;
47             throw new CreateError(error_code);
48         }
49         catch(java.lang.NoSuchFieldException JavaDoc ex_field) {
50             System.err.println("java.lang.NoSuchFieldException caught " +
51                     ex_field.getMessage());
52             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
53             error_code.error = new UIDType(
54                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
55                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
56
57             error_code.details = ExceptionMessages.namebinding_field_error;
58             throw new CreateError(error_code);
59         }
60         catch(java.lang.IllegalAccessException JavaDoc ex_acc) {
61             System.err.println("java.lang.IllegalAccessException caught " +
62                     ex_acc.getMessage());
63             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
64             error_code.error = new UIDType(
65                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
66                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
67
68             error_code.details = ExceptionMessages.namebinding_field_error;
69             throw new CreateError(error_code);
70         }
71
72         info.objectKind = objectKind;
73         info.deletePolicy = deletePolicy;
74         return info;
75         //return new CreateBindingInfo(deletePolicy, objectKind);
76
}
77
78     public static synchronized String JavaDoc autoCreateId(NameComponent JavaDoc[][] siblings) {
79
80         String JavaDoc allocatedId = new String JavaDoc();
81
82         //System.err.println("Auto-naming gets activated..");
83
//System.err.println("Parent has " + siblings.length +
84
// " children");
85

86         boolean idFound = false;
87         int id = 0, name_length = 0;
88
89         while(! idFound) {
90             id++;
91             int i = 0;
92             for(i = 0; i < siblings.length; i++) {
93                 if (siblings[i] !=null && (name_length=siblings[i].length) > 0) {
94                    // -fset update to allow fancy autonaming (prepending description)
95
// if (siblings[i][name_length -2].id.equals(Integer.toString(id))) {
96
if (siblings[i][name_length -2].id.indexOf(Integer.toString(id)) >= 0) {
97                         break;
98                     }
99                 }
100             }
101             if (i >= siblings.length) {
102                 idFound = true;
103             }
104         }
105         allocatedId = Integer.toString(id);
106         return allocatedId;
107     }
108
109
110     public static synchronized NameComponent JavaDoc[] createFullName(NameComponent JavaDoc[] superior,
111                                         String JavaDoc allocatedId,
112                                         String JavaDoc facade_name,
113                                         String JavaDoc objectKind) {
114
115         org.omg.CosNaming.NameComponent JavaDoc[] name;
116
117         int index = 0;
118         if (superior.length == 1) {
119             name = new org.omg.CosNaming.NameComponent JavaDoc[superior.length + 2];
120                 index = 1;
121         }
122         else {
123             name = new org.omg.CosNaming.NameComponent JavaDoc[superior.length + 1];
124                 index = superior.length - 1;
125         }
126         int i = 0;
127         for(i = 0; i < index; i++)
128             name[i] = superior[i];
129             // the before-last name component, contains the element's id info
130
name[i++] = new org.omg.CosNaming.NameComponent JavaDoc(allocatedId, objectKind);
131
132             // the last component contains the facade's info;
133
name[i] = new org.omg.CosNaming.NameComponent JavaDoc("", facade_name);
134
135         return name;
136     }
137
138 };
139
Popular Tags