~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jgdi/cullconv/src/com/sun/grid/cull/CullObject.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 *
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 *
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 *
 
9
 *
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 *
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 *
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 *
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
package com.sun.grid.cull;
 
33
 
 
34
import java.util.*;
 
35
import java.util.logging.Logger;
 
36
 
 
37
/**
 
38
 *
 
39
 */
 
40
public class CullObject {
 
41
    
 
42
    private Logger logger = Logger.getLogger("cullconv");
 
43
    
 
44
    private String name;
 
45
    private ArrayList attrs = new ArrayList();
 
46
    private ArrayList params = new ArrayList();
 
47
    private String    idlName;
 
48
    
 
49
    private boolean hasAddOperation;
 
50
    private boolean hasModifyOperation;
 
51
    private boolean hasDeleteOperation;
 
52
    private boolean hasGetOperation;
 
53
    private boolean hasGetListOperation;
 
54
    
 
55
    private boolean hasAddEvent;
 
56
    private boolean hasModifyEvent;
 
57
    private boolean hasDeleteEvent;
 
58
    private boolean hasGetListEvent;
 
59
    
 
60
    private String addEventName;
 
61
    private String modifyEventName;
 
62
    private String deleteEventName;
 
63
    private String getListEventName;
 
64
    
 
65
    private boolean rootObject;
 
66
    private String  listName;
 
67
    
 
68
    public static final int TYPE_SIMPLE    = 1;
 
69
    public static final int TYPE_PRIMITIVE = 2;
 
70
    public static final int TYPE_MAP       = 3;
 
71
    public static final int TYPE_MAPPED    = 4;
 
72
    
 
73
         private int type = TYPE_SIMPLE;
 
74
    
 
75
    private CullObject parentObject;
 
76
    private String     parentName;
 
77
    
 
78
    private String keyAttrName;
 
79
    private String valueAttrName;
 
80
    private String implClass;
 
81
    
 
82
    private String contentAttrName;
 
83
    
 
84
    /** Creates a new instance of CullObject */
 
85
    public CullObject() {
 
86
    }
 
87
    
 
88
    /**
 
89
     * Getter for property name.
 
90
     * @return Value of property name.
 
91
     */
 
92
    public java.lang.String getName() {
 
93
        return name;
 
94
    }
 
95
    
 
96
    /**
 
97
     * Setter for property name.
 
98
     * @param name New value of property name.
 
99
     */
 
100
    public void setName(java.lang.String name) {
 
101
        this.name = name;
 
102
    }
 
103
    
 
104
    
 
105
    public void addParam(String param ) {
 
106
        params.add(param);
 
107
    }
 
108
    
 
109
    public int getParamCount() {
 
110
        return params.size();
 
111
    }
 
112
    
 
113
    public String getParam(int index) {
 
114
        return (String)params.get(index);
 
115
    }
 
116
    
 
117
    public void addAttr( CullAttr attr ) {
 
118
        if(!attr.isHidden()) {
 
119
            logger.fine(getName() + ": add attr " + attr.getName());
 
120
            attrs.add( attr );
 
121
            attr.setParent( this );
 
122
            attrList = null;
 
123
            primaryKeyAttrList = null;
 
124
        }
 
125
    }
 
126
    
 
127
    private List attrList;
 
128
    
 
129
    private void initAttrList() {
 
130
        if(attrList == null) {
 
131
            attrList = new ArrayList();
 
132
            if(getParentObject() != null) {
 
133
                attrList.addAll(getParentObject().getAttrList());
 
134
            }
 
135
            attrList.addAll(attrs);
 
136
        }
 
137
    }
 
138
    
 
139
    /**
 
140
     *  Get the number of attributes of this cull object
 
141
     *  incl. the attributes of the parent object
 
142
     *  return number of attributes
 
143
     */
 
144
    public int getAttrCount() {
 
145
        initAttrList();
 
146
        return attrList.size();
 
147
    }
 
148
    
 
149
    /**
 
150
     *  Get a list of all attributes of this cull object including
 
151
     *  the attributes of the parent object
 
152
     *  @return list of all attributes
 
153
     */
 
154
    public List getAttrList() {
 
155
        initAttrList();
 
156
        return Collections.unmodifiableList(attrList);
 
157
    }
 
158
    
 
159
    /**
 
160
     *  Get the attributes at index i
 
161
     *  @param i   index of the attributes
 
162
     *  @return  the attributes
 
163
     */
 
164
    public CullAttr getAttr( int i ) {
 
165
        initAttrList();
 
166
        return (CullAttr)attrList.get(i);
 
167
    }
 
168
    
 
169
    /**
 
170
     *  Get a attribute by its name
 
171
     *  @param name the name of the attribute
 
172
     *  @return the attributes
 
173
     */
 
174
    public CullAttr getAttr(String name) {
 
175
        initAttrList();
 
176
        CullAttr ret = null;
 
177
        for(int i = 0; i < attrList.size(); i++ ) {
 
178
            CullAttr tmp = (CullAttr)attrList.get(i);
 
179
            if( tmp.getName().equals(name)) {
 
180
                ret = tmp;
 
181
                break;
 
182
            }
 
183
        }
 
184
        if(ret == null) {
 
185
            throw new IllegalArgumentException("attribute " + name + " not found in cull object " + getName() );
 
186
        }
 
187
        return ret;
 
188
    }
 
189
    
 
190
    public int getOwnAttrCount() {
 
191
        return attrs.size();
 
192
    }
 
193
    
 
194
    public List getOwnAttrList() {
 
195
        return Collections.unmodifiableList(attrs);
 
196
    }
 
197
    
 
198
    public CullAttr getOwnAttr(int i) {
 
199
        return (CullAttr)attrs.get(i);
 
200
    }
 
201
    
 
202
    public String getIdlName() {
 
203
        return idlName;
 
204
    }
 
205
    
 
206
    public void setIdlName(String idlName) {
 
207
        this.idlName = idlName;
 
208
    }
 
209
    
 
210
    
 
211
    private List primaryKeyAttrList;
 
212
    
 
213
    private void initPrimaryKeyAttrList() {
 
214
        if(primaryKeyAttrList == null) {
 
215
            
 
216
            int type = this.type;
 
217
            if(getParentObject() != null) {
 
218
                type = getParentObject().getType();
 
219
            }
 
220
            
 
221
            if(type == TYPE_PRIMITIVE || type == TYPE_MAPPED) {
 
222
                primaryKeyAttrList = Collections.EMPTY_LIST;
 
223
            } else {
 
224
                primaryKeyAttrList = new ArrayList();
 
225
                
 
226
                for(int i = 0; i < getAttrCount(); i++) {
 
227
                    CullAttr attr = getAttr(i);
 
228
                    if( attr.isPrimaryKey() ) {
 
229
                        primaryKeyAttrList.add(attr);
 
230
                    }
 
231
                }
 
232
            }
 
233
        }
 
234
    }
 
235
    
 
236
    public CullAttr getFirstPrimaryKeyAttr() {
 
237
        initPrimaryKeyAttrList();
 
238
        if(!primaryKeyAttrList.isEmpty()) {
 
239
            return (CullAttr)primaryKeyAttrList.get(0);
 
240
        }
 
241
        return null;
 
242
    }
 
243
    
 
244
    
 
245
    public List getPrimaryKeyAttrs() {
 
246
        initPrimaryKeyAttrList();
 
247
        return Collections.unmodifiableList(primaryKeyAttrList);
 
248
    }
 
249
    
 
250
    public int getPrimaryKeyCount() {
 
251
        initPrimaryKeyAttrList();
 
252
        return primaryKeyAttrList.size();
 
253
    }
 
254
    
 
255
    public CullAttr getPrimaryKeyAttr(int i) {
 
256
        initPrimaryKeyAttrList();
 
257
        return (CullAttr)primaryKeyAttrList.get(i);
 
258
    }
 
259
    
 
260
    
 
261
    public boolean hasAddOperation() {
 
262
        return hasAddOperation;
 
263
    }
 
264
    
 
265
    public void setHasAddOperation(boolean hasAddOperation) {
 
266
        this.hasAddOperation = hasAddOperation;
 
267
    }
 
268
    
 
269
    public boolean hasModifyOperation() {
 
270
        return hasModifyOperation;
 
271
    }
 
272
    
 
273
    public void setHasModifyOperation(boolean hasModifyOperation) {
 
274
        this.hasModifyOperation = hasModifyOperation;
 
275
    }
 
276
    
 
277
    public boolean hasDeleteOperation() {
 
278
        return hasDeleteOperation;
 
279
    }
 
280
    
 
281
    public void setHasDeleteOperation(boolean hasDeleteOperation) {
 
282
        this.hasDeleteOperation = hasDeleteOperation;
 
283
    }
 
284
    
 
285
    public boolean hasGetOperation() {
 
286
        return hasGetOperation;
 
287
    }
 
288
    
 
289
    public void setHasGetOperation(boolean hasGetOperation) {
 
290
        this.hasGetOperation = hasGetOperation;
 
291
    }
 
292
    
 
293
    public boolean hasGetListOperation() {
 
294
        return hasGetListOperation;
 
295
    }
 
296
    
 
297
    public void setHasGetListOperation(boolean hasGetListOperation) {
 
298
        this.hasGetListOperation = hasGetListOperation;
 
299
    }
 
300
    
 
301
    public String getOperationString() {
 
302
        StringBuffer ret = new StringBuffer();
 
303
        if(hasGetOperation()) {
 
304
            ret.append("GET ");
 
305
        }
 
306
        if(hasGetListOperation()) {
 
307
            ret.append("GET_LIST ");
 
308
        }
 
309
        if(hasAddOperation()) {
 
310
            ret.append("ADD ");
 
311
        }
 
312
        if(hasModifyOperation()) {
 
313
            ret.append("MODIFY ");
 
314
        }
 
315
        if(hasDeleteOperation()) {
 
316
            ret.append("DELETE ");
 
317
        }
 
318
        return ret.toString();
 
319
    }
 
320
    
 
321
    public boolean isRootObject() {
 
322
        return rootObject;
 
323
    }
 
324
    
 
325
    public void setRootObject(boolean rootObject) {
 
326
        this.rootObject = rootObject;
 
327
    }
 
328
    
 
329
    public int getType() {
 
330
        if(getParentObject() != null) {
 
331
            return getParentObject().getType();
 
332
        }
 
333
        return type;
 
334
    }
 
335
    
 
336
    public void setType(int type) {
 
337
        this.type = type;
 
338
    }
 
339
    
 
340
    public CullObject getParentObject() {
 
341
        return parentObject;
 
342
    }
 
343
    
 
344
    public void setParentObject(CullObject parentObject) {
 
345
        this.parentObject = parentObject;
 
346
        attrList = null;
 
347
        primaryKeyAttrList = null;
 
348
    }
 
349
    
 
350
    public String getParentName() {
 
351
        return parentName;
 
352
    }
 
353
    
 
354
    public void setParentName(String parentName) {
 
355
        this.parentName = parentName;
 
356
    }
 
357
    
 
358
    public String getKeyAttrName() {
 
359
        String ret = keyAttrName;
 
360
        if(ret == null && getParentObject() != null) {
 
361
            ret = getParentObject().getKeyAttrName();
 
362
        }
 
363
        return ret;
 
364
    }
 
365
    
 
366
    public void setKeyAttrName(String keyAttrName) {
 
367
        this.keyAttrName = keyAttrName;
 
368
    }
 
369
    
 
370
    public CullAttr getKeyAttr() {
 
371
        return getAttr(getKeyAttrName());
 
372
    }
 
373
    
 
374
    public String getValueAttrName() {
 
375
        String ret = valueAttrName;
 
376
        if(ret == null && getParentObject() != null) {
 
377
            ret = getParentObject().getValueAttrName();
 
378
        }
 
379
        return ret;
 
380
    }
 
381
    
 
382
    public CullAttr getValueAttr() {
 
383
        return getAttr(getValueAttrName());
 
384
    }
 
385
    
 
386
    public void setValueAttrName(String valueAttrName) {
 
387
        this.valueAttrName = valueAttrName;
 
388
    }
 
389
    
 
390
    public String getImplClass() {
 
391
        String ret = implClass;
 
392
        if(ret == null && getParentObject() != null) {
 
393
            ret = getParentObject().getImplClass();
 
394
        }
 
395
        return ret;
 
396
    }
 
397
    
 
398
    public void setImplClass(String implClass) {
 
399
        this.implClass = implClass;
 
400
    }
 
401
    
 
402
    public String getContentAttrName() {
 
403
        String ret = contentAttrName;
 
404
        if(ret == null && getParentObject() != null) {
 
405
            ret = getParentObject().getContentAttrName();
 
406
        }
 
407
        return ret;
 
408
    }
 
409
    
 
410
    public void setContentAttrName(String contentAttrName) {
 
411
        this.contentAttrName = contentAttrName;
 
412
    }
 
413
    
 
414
    public CullAttr getContentAttr() {
 
415
        return getAttr(getContentAttrName());
 
416
    }
 
417
    
 
418
    public String getListName() {
 
419
        return listName;
 
420
    }
 
421
    
 
422
    public void setListName(String listName) {
 
423
        this.listName = listName;
 
424
    }
 
425
    
 
426
    public boolean hasEvents() {
 
427
        return hasAddEvent || hasModifyEvent || hasDeleteEvent || hasGetListEvent;
 
428
    }
 
429
    
 
430
    public boolean hasAddEvent() {
 
431
        return hasAddEvent;
 
432
    }
 
433
    
 
434
    public void setHasAddEvent(boolean hasAddEvent) {
 
435
        this.hasAddEvent = hasAddEvent;
 
436
    }
 
437
    
 
438
    public boolean hasModifyEvent() {
 
439
        return hasModifyEvent;
 
440
    }
 
441
    
 
442
    public void setHasModifyEvent(boolean hasModifyEvent) {
 
443
        this.hasModifyEvent = hasModifyEvent;
 
444
    }
 
445
    
 
446
    public boolean hasDeleteEvent() {
 
447
        return hasDeleteEvent;
 
448
    }
 
449
    
 
450
    public void setHasDeleteEvent(boolean hasDeleteEvent) {
 
451
        this.hasDeleteEvent = hasDeleteEvent;
 
452
    }
 
453
    
 
454
    public boolean hasGetListEvent() {
 
455
        return hasGetListEvent;
 
456
    }
 
457
    
 
458
    public void setHasGetListEvent(boolean hasGetListEvent) {
 
459
        this.hasGetListEvent = hasGetListEvent;
 
460
    }
 
461
    
 
462
    public String getAddEventName() {
 
463
        return addEventName;
 
464
    }
 
465
    
 
466
    public void setAddEventName(String addEventName) {
 
467
        this.addEventName = addEventName;
 
468
    }
 
469
    
 
470
    public String getModifyEventName() {
 
471
        return modifyEventName;
 
472
    }
 
473
    
 
474
    public void setModifyEventName(String modifyEventName) {
 
475
        this.modifyEventName = modifyEventName;
 
476
    }
 
477
    
 
478
    public String getDeleteEventName() {
 
479
        return deleteEventName;
 
480
    }
 
481
    
 
482
    public void setDeleteEventName(String deleteEventName) {
 
483
        this.deleteEventName = deleteEventName;
 
484
    }
 
485
    
 
486
    public String getGetListEventName() {
 
487
        return getListEventName;
 
488
    }
 
489
    
 
490
    public void setGetListEventName(String getListEventName) {
 
491
        this.getListEventName = getListEventName;
 
492
    }
 
493
    
 
494
}