summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java
blob: c48188112e60cf8af2e93cefb4c72671798ec92b (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
/*
 * 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.    
 */
package org.apache.tuscany.sca.binding.ejb.java2idl;

import java.util.HashMap;
import java.util.Map;

/**
 * Type class for primitive types.
 */
public class PrimitiveType extends ClassType {

    public final static PrimitiveType voidType = new PrimitiveType(void.class, "void", "void");
    public final static PrimitiveType booleanType = new PrimitiveType(boolean.class, "boolean", "boolean");
    public final static PrimitiveType charType = new PrimitiveType(char.class, "wchar", "char");
    public final static PrimitiveType byteType = new PrimitiveType(byte.class, "octet", "byte");
    public final static PrimitiveType shortType = new PrimitiveType(short.class, "short", "short");
    public final static PrimitiveType intType = new PrimitiveType(int.class, "long", "int");
    public final static PrimitiveType longType = new PrimitiveType(long.class, "long_long", "long");
    public final static PrimitiveType floatType = new PrimitiveType(float.class, "float", "float");
    public final static PrimitiveType doubleType = new PrimitiveType(double.class, "double", "double");

    private final static Map types = new HashMap();
    static {
        types.put(void.class, voidType);
        types.put(boolean.class, booleanType);
        types.put(byte.class, byteType);
        types.put(char.class, charType);
        types.put(short.class, shortType);
        types.put(int.class, intType);
        types.put(long.class, longType);
        types.put(float.class, floatType);
        types.put(double.class, doubleType);
    }

    private PrimitiveType(Class cls, String idlName, String javaName) {
        super(cls, idlName, javaName);
    }

    /**
     * Get a singleton instance representing one of the peimitive types.
     */
    public final static PrimitiveType getPrimitiveType(Class cls) {
        PrimitiveType type = (PrimitiveType)types.get(cls);
        if (type == null)
            throw new IllegalArgumentException(cls + " is not a primitive type");
        return type;
    }

}