aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/JREDesc.java
blob: 14736cd29a9b5e01d9cba91dd4e1ae262743f721 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright (C) 2001-2003 Jon A. Maxwell (JAM)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

package net.sourceforge.jnlp;

import static net.sourceforge.jnlp.runtime.Translator.R;

import java.net.*;
import java.util.*;

/**
 * The J2SE/Java element.
 *
 * @author <a href="mailto:jmaxwell@users.sourceforge.net">Jon A. Maxwell (JAM)</a> - initial author
 * @version $Revision: 1.5 $
 */
public class JREDesc {

    /** the platform version or the product version if location is not null */
    final private Version version;

    /** the location of a JRE product or null */
    final private URL location;

    /** inital heap size */
    final private String initialHeapSize;

    /** maximum head size */
    final private String maximumHeapSize;

    /** args to pass to the vm */
    final private String vmArgs;

    /** list of ResourceDesc objects */
    final private List<ResourcesDesc> resources;

    /**
     * Create a JRE descriptor.
     *
     * @param version the platform version or the product version
     * if location is not null
     * @param location the location of a JRE product or null
     * @param initialHeapSize inital heap size
     * @param maximumHeapSize maximum head size
     * @param resources list of ResourceDesc objects
     */
    public JREDesc(Version version, URL location,
            String vmArgs, String initialHeapSize,
            String maximumHeapSize, List<ResourcesDesc> resources) throws ParseException {
        this.version = version;
        this.location = location;
        this.vmArgs = vmArgs;
        checkHeapSize(initialHeapSize);
        this.initialHeapSize = initialHeapSize;
        checkHeapSize(maximumHeapSize);
        this.maximumHeapSize = maximumHeapSize;
        this.resources = resources;
    }

    /**
     * Returns the JRE version.  Use isPlatformVersion to
     * determine if this version corresponds to a platform or
     * product version.
     */
    public Version getVersion() {
        return version;
    }

    /**
     * Returns true if the JRE version is a Java platform version
     * (java.specification.version property) or false if it is a
     * product version (java.version property).
     */
    public boolean isPlatformVersion() {
        return getLocation() == null;
    }

    /**
     * Returns the JRE version string.
     */
    public URL getLocation() {
        return location;
    }

    /**
     * Returns the maximum heap size in bytes.
     */
    public String getMaximumHeapSize() {
        return maximumHeapSize;
    }

    /**
     * Returns the initial heap size in bytes.
     */
    public String getInitialHeapSize() {
        return initialHeapSize;
    }

    /**
     * Returns the resources defined for this JRE.
     */
    public List<ResourcesDesc> getResourcesDesc() {
        return resources;
    }

    /**
     * Returns the additional arguments to pass to the Java VM
     * Can be null
     */
    public String getVMArgs() {
        return vmArgs;
    }

    /**
     * Check for valid heap size string
     * @throws ParseException if heapSize is invalid
     */
    static private void checkHeapSize(String heapSize) throws ParseException {
        // need to implement for completeness even though not used in netx
        if (heapSize == null) {
            return;
        }

        boolean lastCharacterIsDigit = true;
        // the last character must be 0-9 or k/K/m/M
        char lastChar = Character.toLowerCase(heapSize.charAt(heapSize.length() - 1));
        if ((lastChar < '0' || lastChar > '9')) {
            lastCharacterIsDigit = false;
            if (lastChar != 'k' && lastChar != 'm') {
                throw new ParseException(R("PBadHeapSize", heapSize));
            }
        }

        int indexOfLastDigit = heapSize.length() - 1;
        if (!lastCharacterIsDigit) {
            indexOfLastDigit = indexOfLastDigit - 1;
        }

        String size = heapSize.substring(0, indexOfLastDigit);
        try {
            // check that the number is a number!
            Integer.valueOf(size);
        } catch (NumberFormatException numberFormat) {
            throw new ParseException(R("PBadHeapSize", heapSize), numberFormat);
        }

    }

}