summaryrefslogtreecommitdiffstats
path: root/tags/native-sca-1.0.incubating-M3-RC4/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Configuration.java
blob: 246a489c9cdfe0e8ca1d363d45683f5a01ef0f3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
 *
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

/* @version $Rev$ $Date$ */


/*
 *  Branched from the original class that was also contributed to the 
 *  org.apache.axis.tools.common package.
 */
package org.apache.tuscany.sca.cpp.tools.common;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Encapsulates the tool's configuration file
 */
public class Configuration {
    private static Set files = new HashSet();

    private static Set classes = new HashSet();

    private static Set methods = new HashSet();

    private static Set macros = new HashSet();

    private static Set defines = new HashSet();

    private static Set attributes = new HashSet();

    private static Map others = new HashMap();

    /**
     * No one creates an instance of this class.
     */
    private Configuration() {
    }

    /**
     * Reads in the configuration file
     */
    public static void initialise(String filename) throws Exception {
        File file = new File(filename);
        FileReader fr = new FileReader(file);
        BufferedReader br = new BufferedReader(fr);
        String line = br.readLine();
        for (int lineno = 1; null != line; lineno++, line = br.readLine()) {
            // Ignore lines starting with a # (comments) and blank lines
            if (line.startsWith("#"))
                continue;
            boolean blank = true;
            for (int i = 0; i < line.length() && blank; i++)
                if (!Character.isWhitespace(line.charAt(i)))
                    blank = false;
            if (blank)
                continue;

            int equals = line.indexOf("=");
            if (-1 == equals)
                Utils.rude("Bad line in configuration file " + filename
                        + " lineno " + lineno);
            String key = line.substring(0, equals).trim();
            String value = line.substring(equals + 1).trim();
            if ("excludefile".equals(key)) {
                files.add(value);
            } else if ("excludeclass".equals(key)) {
                classes.add(value);
            } else if ("excludemethod".equals(key)) {
                methods.add(value);
            } else if ("macro".equals(key)) {
                macros.add(value);
            } else if ("define".equals(key)) {
                defines.add(value);
            } else if ("attribute".equals(key)) {
                attributes.add(value);
            } else {
                others.put(key, value);
            }
        }
    }

    public static boolean fileExcluded(String s) {
        return files.contains(s);
    }

    public static boolean classExcluded(String s) {
        return classes.contains(s);
    }

    public static boolean methodExcluded(String className, String method) {
        return methods.contains(className + "::" + method);
    }

    public static boolean isMacro(String s) {
        return macros.contains(s);
    }

    public static boolean isDefine(String s) {
        return defines.contains(s);
    }

    public static boolean isAttribute(String s) {
        return attributes.contains(s);
    }

    public static String getConfigured(String key) {
        return (String) others.get(key);
    }
}