~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/CullConstantConverter.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.File;
 
35
import java.util.logging.Level;
 
36
 
 
37
/**
 
38
 *
 
39
 */
 
40
public class CullConstantConverter extends AbstractCullToJavaConverter {
 
41
 
 
42
    static {
 
43
        System.loadLibrary("drmaa");
 
44
    }
 
45
 
 
46
    /** Creates a new instance of CullConstantConverter */
 
47
    public CullConstantConverter() {
 
48
    }
 
49
 
 
50
    public void convert(CullDefinition cullDef) throws java.io.IOException {
 
51
 
 
52
        String packagename = getPackagename();
 
53
        String className = "CullConstants";
 
54
        File file = getFileForClass(className);
 
55
        boolean dirty = false;
 
56
 
 
57
        if (file.exists()) {
 
58
            for (String nss : cullDef.getNameSpaceNameSet()) {
 
59
                CullNameSpace ns = cullDef.getNameSpace(nss);
 
60
                File defFile = cullDef.getNameSource(ns.getNameSpace());
 
61
                if (defFile == null) {
 
62
                    logger.log(Level.WARNING, "no source file for namespace " + ns.getNameSpace() + " found");
 
63
                } else if (defFile.lastModified() > file.lastModified()) {
 
64
                    logger.log(Level.FINE, "namespace " + ns.getNameSpace() + " is dirty (defined in " + defFile + ")");
 
65
                    dirty = true;
 
66
                    break;
 
67
                } else {
 
68
                    logger.log(Level.FINE, "namespace " + ns.getNameSpace() + " is up to date");
 
69
                }
 
70
            }
 
71
        } else {
 
72
            dirty = true;
 
73
        }
 
74
 
 
75
        if (dirty) {
 
76
            Printer p = new Printer(file);
 
77
 
 
78
            p.println("/* Generated by " + getClass().getName());
 
79
            p.println("*/");
 
80
            if (packagename != null) {
 
81
                p.print("package ");
 
82
                p.print(packagename);
 
83
                p.println(";");
 
84
            }
 
85
 
 
86
            p.print("public interface ");
 
87
            p.println(className);
 
88
            p.println(" {");
 
89
            p.indent();
 
90
 
 
91
            for (String nss : cullDef.getNameSpaceNameSet()) {
 
92
                CullNameSpace ns = cullDef.getNameSpace(nss);
 
93
                writeNameSpace(ns, p);
 
94
                p.println();
 
95
            }
 
96
 
 
97
            p.deindent();
 
98
            p.println("}");
 
99
            p.flush();
 
100
        }
 
101
    }
 
102
 
 
103
    private void writeNameSpace(CullNameSpace ns, Printer p) {
 
104
 
 
105
        for (String name : ns.getNames()) {
 
106
            p.print("public static final int ");
 
107
//          p.print( ns.getNameSpace() );
 
108
//          p.print( '_' );
 
109
            p.print(name);
 
110
            p.print(" = ");
 
111
            p.print(strToNm(name));
 
112
            p.println(";");
 
113
        }
 
114
    }
 
115
 
 
116
    private native int strToNm(String name);
 
117
}