~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/CullDefinition.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.io.*;
 
35
import java.util.*;
 
36
import java.util.logging.Logger;
 
37
 
 
38
/**
 
39
 *
 
40
 */
 
41
public class CullDefinition {
 
42
 
 
43
    private Map<String, Elem> cullObjectMap = new HashMap<String, Elem>();
 
44
    private Map<String, NameElem> nameObjectMap = new HashMap<String, NameElem>();
 
45
    private Map<String, EnumElem> enumMap = new HashMap<String, EnumElem>();
 
46
    private String packageName;
 
47
 
 
48
    private Logger logger = Logger.getLogger("cullconv");
 
49
 
 
50
    /** Creates a new instance of AbstractCullContext */
 
51
    public CullDefinition() {
 
52
    }
 
53
 
 
54
    protected Elem createElem() {
 
55
        return new Elem();
 
56
    }
 
57
 
 
58
    public void addFile(String file) throws IOException, ParseException {
 
59
        addFile(new File(file));
 
60
    }
 
61
 
 
62
    public void addFile(File file) throws IOException, ParseException {
 
63
 
 
64
        FileInputStream in = new FileInputStream(file);
 
65
        CullFile cullFile = Cull.parse(in);
 
66
        cullFile.setSource(file);
 
67
 
 
68
        for (int i = 0; i < cullFile.getCullObjectCount(); i++) {
 
69
            addCullObject(cullFile.getCullObject(i), file);
 
70
        }
 
71
        for (int i = 0; i < cullFile.getNameSpaceCount(); i++) {
 
72
            addNameSpace(cullFile.getNameSpace(i), file);
 
73
        }
 
74
        for (int i = 0; i < cullFile.getEnumCount(); i++) {
 
75
            addEnum(cullFile.getEnum(i), file);
 
76
        }
 
77
    }
 
78
 
 
79
    /**
 
80
     *  Verify the cull definition
 
81
     *  @return number of errors
 
82
     */
 
83
    public int verify() {
 
84
 
 
85
        int errors = 0;
 
86
        for (String name : getObjectNames()) {
 
87
            CullObject obj = getCullObject(name);
 
88
            if (obj.isRootObject()) {
 
89
                if (obj.getIdlName() == null) {
 
90
                    errors++;
 
91
                    logger.severe("Root object " + obj.getName() + " has not idl name");
 
92
                }
 
93
            }
 
94
 
 
95
            if (obj.getParentName() != null) {
 
96
                CullObject baseObj = getCullObject(obj.getParentName());
 
97
                if (baseObj == null) {
 
98
                    errors++;
 
99
                    logger.severe("Base type " + obj.getParentName() + " of object " + obj.getName() + "not found");
 
100
                } else {
 
101
                    obj.setParentObject(baseObj);
 
102
                }
 
103
            }
 
104
            for (int i = 0; i < obj.getAttrCount(); i++) {
 
105
                CullAttr attr = obj.getAttr(i);
 
106
                if (attr instanceof CullMapAttr) {
 
107
                    CullObject mapObj = getCullObject(attr.getType());
 
108
                    if (mapObj.getType() == CullObject.TYPE_MAP) {
 
109
                        ((CullMapAttr) attr).setMapType(mapObj);
 
110
                    } else {
 
111
                        errors++;
 
112
                        logger.severe(obj.getName() + "." + attr.getName() + ": type " + attr.getType() + " is not a JGDI_MAP_OBJ");
 
113
                    }
 
114
                }
 
115
            }
 
116
        }
 
117
 
 
118
        return errors;
 
119
    }
 
120
 
 
121
 
 
122
    public void addNameSpace(CullNameSpace obj, File source) {
 
123
        File f = getSource(obj.getNameSpace());
 
124
 
 
125
        if (f != null) {
 
126
            System.err.println("Warning: duplicate definition of name space object " + obj.getNameSpace());
 
127
            System.err.println("         --> " + f);
 
128
            System.err.println("         --> " + source);
 
129
        }
 
130
        NameElem elem = new NameElem();
 
131
        elem.obj = obj;
 
132
        elem.source = source;
 
133
        nameObjectMap.put(obj.getNameSpace(), elem);
 
134
    }
 
135
 
 
136
    public Set<String> getNameSpaceNameSet() {
 
137
        return nameObjectMap.keySet();
 
138
    }
 
139
 
 
140
    public CullNameSpace getNameSpace(String name) {
 
141
        NameElem ret = (NameElem) nameObjectMap.get(name);
 
142
        if (ret != null) {
 
143
            return ret.obj;
 
144
        }
 
145
        return null;
 
146
    }
 
147
 
 
148
    public File getNameSource(String name) {
 
149
        NameElem elem = (NameElem) nameObjectMap.get(name);
 
150
        if (elem != null) {
 
151
            return elem.source;
 
152
        }
 
153
        return null;
 
154
    }
 
155
 
 
156
    public void addCullObject(CullObject obj, File source) {
 
157
        File f = getSource(obj.getName());
 
158
 
 
159
        if (f != null) {
 
160
            System.err.println("Warning: duplicate definition of cull object " + obj.getName());
 
161
            System.err.println("         --> " + f);
 
162
            System.err.println("         --> " + source);
 
163
        }
 
164
        Elem elem = createElem();
 
165
        elem.obj = obj;
 
166
        elem.source = source;
 
167
 
 
168
        cullObjectMap.put(obj.getName(), elem);
 
169
    }
 
170
 
 
171
    public Set<String> getObjectNames() {
 
172
        return Collections.unmodifiableSet(cullObjectMap.keySet());
 
173
    }
 
174
 
 
175
 
 
176
    public CullObject getCullObject(String name) {
 
177
        Elem ret = (Elem) cullObjectMap.get(name);
 
178
        if (ret != null) {
 
179
            return ret.obj;
 
180
        } else {
 
181
            return null;
 
182
        }
 
183
    }
 
184
 
 
185
    public File getSource(String name) {
 
186
        Elem ret = (Elem) cullObjectMap.get(name);
 
187
        if (ret != null) {
 
188
            return ret.source;
 
189
        } else {
 
190
            return null;
 
191
        }
 
192
    }
 
193
 
 
194
    public static class Elem {
 
195
        CullObject obj;
 
196
        File source;
 
197
    }
 
198
 
 
199
    public static class NameElem {
 
200
        CullNameSpace obj;
 
201
        File source;
 
202
    }
 
203
 
 
204
    public static class EnumElem {
 
205
        CullEnum obj;
 
206
        File source;
 
207
    }
 
208
 
 
209
    public String getPackageName() {
 
210
        return packageName;
 
211
    }
 
212
 
 
213
    public void setPackageName(String packageName) {
 
214
        this.packageName = packageName;
 
215
    }
 
216
 
 
217
    public void addEnum(CullEnum aEnum, File file) {
 
218
        EnumElem elem = new EnumElem();
 
219
        elem.obj = aEnum;
 
220
        elem.source = file;
 
221
        enumMap.put(aEnum.getName(), elem);
 
222
    }
 
223
 
 
224
    public Set<String> getEnumNames() {
 
225
        return Collections.unmodifiableSet(enumMap.keySet());
 
226
    }
 
227
 
 
228
    public CullEnum getEnum(String name) {
 
229
        return enumMap.get(name).obj;
 
230
    }
 
231
}