1 package fr.ove.openmath.jome.ctrl.om;
2
3 import fr.ove.utils.CachingResourcesManager;
4
5 /***
6 *
7 *
8 * @author © 1999 DIRAT Laurent
9 * @version 2.0 30/09/99
10 */
11 public class OMParserResourcesManager extends CachingResourcesManager {
12 /***
13 * The Constructor.
14 * @param resourcesName the name of the resources file.
15 */
16 public OMParserResourcesManager (String resourcesName) {
17 super(resourcesName);
18 }
19
20 /***
21 * Returns the class name corresponding to the specified property.
22 * @param property the specified property
23 */
24 public String getIdentifier(String property) {
25 return accessResource(property, 0);
26 }
27
28 /***
29 * Returns the value associated to corresponding to the specified property.
30 * @param property the specified property
31 */
32 public String getValue(String property) {
33 return accessResource(property, 1);
34 }
35
36 /***
37 * Returns the arity of the symbol associated to the specified property.
38 * @param property the specified property
39 */
40 public byte getArity(String property) {
41 String arity = accessResource(property, 2);
42 byte byteArity = -1;
43 try {
44 byteArity = Byte.parseByte(arity);
45 }
46 catch (NumberFormatException nfe) {
47 nfe.printStackTrace();
48 }
49
50 return byteArity;
51 }
52
53 /***
54 * Returns the list of supported cds.
55 */
56 public String[] getSupportedCDs() {
57 return getResourceStrings("supportedCDs");
58 }
59
60 /***
61 * Checks if the specified cd name is a supported cd.
62 * @param cdName the name of the cd
63 * @return <CODE>true</CODE> if the cd is supported. <CODE>false</CODE> otherwise.
64 */
65 public boolean isSupportedCD(String cdName) {
66 String[] supportedCDs = getResourceStrings("supportedCDs");
67
68 if (supportedCDs.length > 0) {
69 for (int i = 0; i < supportedCDs.length; i++) {
70 if (supportedCDs[i].equals(cdName))
71 return true;
72 }
73 }
74
75 return false;
76 }
77
78 /***
79 * Returns the supported symbols in the specified cd.
80 * @param cdName the name of the cd.
81 */
82 public String[] getSupportedSymbols(String cdName) {
83 if (isSupportedCD(cdName))
84 return getResourceStrings(cdName);
85
86 return new String[0];
87 }
88
89 /***
90 * Cheks the symbol id supported.
91 * @returns <CODE>true</CODE> if the symbol is supported. <CODE>false</CODE> otherwise.
92 */
93 public boolean isSupportedSymbol(String cdName, String symbName) {
94 if (isSupportedCD(cdName)) {
95 String[] supportedSymbols = getResourceStrings(cdName);
96
97 if (supportedSymbols.length > 0) {
98 for (int i = 0; i < supportedSymbols.length; i++) {
99 if (supportedSymbols[i].equals(symbName))
100 return true;
101 }
102 }
103 }
104
105 return false;
106 }
107
108 /***
109 * Cheks the validity of a symbol. Here, validity means :
110 * <UL>
111 * <LI>the specified cd name is supported</LI>
112 * <LI>the specified symbol name is supported (of course, the cd must be supported)</LI>
113 * </UL>
114 * @param cdName the name of the cd in which the symbol should be
115 * @param symbName the name of the symbol
116 * @returns <CODE>true</CODE> if the symbol is valid. <CODE>false</CODE> otherwise.
117 */
118 public boolean isValidSymbol(String cdName, String symbName) {
119 return isSupportedCD(cdName) & isSupportedSymbol(cdName, symbName);
120 }
121 }