1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
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
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.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
32
package com.sun.grid.cull;
36
import java.util.logging.Logger;
41
public class CullDefinition {
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;
48
private Logger logger = Logger.getLogger("cullconv");
50
/** Creates a new instance of AbstractCullContext */
51
public CullDefinition() {
54
protected Elem createElem() {
58
public void addFile(String file) throws IOException, ParseException {
59
addFile(new File(file));
62
public void addFile(File file) throws IOException, ParseException {
64
FileInputStream in = new FileInputStream(file);
65
CullFile cullFile = Cull.parse(in);
66
cullFile.setSource(file);
68
for (int i = 0; i < cullFile.getCullObjectCount(); i++) {
69
addCullObject(cullFile.getCullObject(i), file);
71
for (int i = 0; i < cullFile.getNameSpaceCount(); i++) {
72
addNameSpace(cullFile.getNameSpace(i), file);
74
for (int i = 0; i < cullFile.getEnumCount(); i++) {
75
addEnum(cullFile.getEnum(i), file);
80
* Verify the cull definition
81
* @return number of errors
86
for (String name : getObjectNames()) {
87
CullObject obj = getCullObject(name);
88
if (obj.isRootObject()) {
89
if (obj.getIdlName() == null) {
91
logger.severe("Root object " + obj.getName() + " has not idl name");
95
if (obj.getParentName() != null) {
96
CullObject baseObj = getCullObject(obj.getParentName());
97
if (baseObj == null) {
99
logger.severe("Base type " + obj.getParentName() + " of object " + obj.getName() + "not found");
101
obj.setParentObject(baseObj);
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);
112
logger.severe(obj.getName() + "." + attr.getName() + ": type " + attr.getType() + " is not a JGDI_MAP_OBJ");
122
public void addNameSpace(CullNameSpace obj, File source) {
123
File f = getSource(obj.getNameSpace());
126
System.err.println("Warning: duplicate definition of name space object " + obj.getNameSpace());
127
System.err.println(" --> " + f);
128
System.err.println(" --> " + source);
130
NameElem elem = new NameElem();
132
elem.source = source;
133
nameObjectMap.put(obj.getNameSpace(), elem);
136
public Set<String> getNameSpaceNameSet() {
137
return nameObjectMap.keySet();
140
public CullNameSpace getNameSpace(String name) {
141
NameElem ret = (NameElem) nameObjectMap.get(name);
148
public File getNameSource(String name) {
149
NameElem elem = (NameElem) nameObjectMap.get(name);
156
public void addCullObject(CullObject obj, File source) {
157
File f = getSource(obj.getName());
160
System.err.println("Warning: duplicate definition of cull object " + obj.getName());
161
System.err.println(" --> " + f);
162
System.err.println(" --> " + source);
164
Elem elem = createElem();
166
elem.source = source;
168
cullObjectMap.put(obj.getName(), elem);
171
public Set<String> getObjectNames() {
172
return Collections.unmodifiableSet(cullObjectMap.keySet());
176
public CullObject getCullObject(String name) {
177
Elem ret = (Elem) cullObjectMap.get(name);
185
public File getSource(String name) {
186
Elem ret = (Elem) cullObjectMap.get(name);
194
public static class Elem {
199
public static class NameElem {
204
public static class EnumElem {
209
public String getPackageName() {
213
public void setPackageName(String packageName) {
214
this.packageName = packageName;
217
public void addEnum(CullEnum aEnum, File file) {
218
EnumElem elem = new EnumElem();
221
enumMap.put(aEnum.getName(), elem);
224
public Set<String> getEnumNames() {
225
return Collections.unmodifiableSet(enumMap.keySet());
228
public CullEnum getEnum(String name) {
229
return enumMap.get(name).obj;