00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.xml;
00032
00033 import org.objectweb.proactive.core.descriptor.xml.ProActiveDescriptorConstants;
00034
00035
00042 public class VariableContractType {
00043 static final public VariableContractType DescriptorVariable = new VariableContractType(0,
00044 new String[] { "Descriptor", "Program" },
00045 new String[] { "Descriptor" }, new String[] { "Program" });
00046 static final public VariableContractType ProgramVariable = new VariableContractType(1,
00047 new String[] { "Program", "Descriptor" },
00048 new String[] { "Program" }, new String[] { "Descriptor" });
00049 static final public VariableContractType JavaPropertyVariable = new VariableContractType(2,
00050 new String[] {"JavaProperty"}, new String[] {"JavaProperty"}, new String[] { "Program", "Descriptor" } );
00051 static final public VariableContractType ProgramDefaultVariable = new VariableContractType(3,
00052 new String[] { "Descriptor", "Program" },
00053 new String[] { "Descriptor", "Program" }, new String[0]);
00054 static final public VariableContractType DescriptorDefaultVariable = new VariableContractType(4,
00055 new String[] { "Program", "Descriptor" },
00056 new String[] { "Descriptor", "Program" }, new String[0]);
00057 static final public VariableContractType JavaPropertyDescriptorDefault = new VariableContractType(5,
00058 new String[] {"JavaProperty","Descriptor","Program"}, new String[] {"JavaProperty", "Descriptor", "Program"},
00059 new String[] {"Program"});
00060 static final public VariableContractType JavaPropertyProgramDefault = new VariableContractType(6,
00061 new String[] {"JavaProperty","Program","Descriptor"}, new String[] {"JavaProperty","Program","Descriptor"},
00062 new String[] {"Descriptor"});
00063 private int type;
00064 private String[] priority;
00065 private String[] setAbility;
00066 private String[] setEmptyAbility;
00067
00075 private VariableContractType(int type, String[] priority,
00076 String[] setAbility, String[] setEmptyAbility) {
00077 this.type = type;
00078 this.priority = priority;
00079 this.setAbility = setAbility;
00080 this.setEmptyAbility = setEmptyAbility;
00081 }
00082
00083 public boolean equals(Object o) {
00084 return equals((VariableContractType) o);
00085 }
00086
00087 public boolean equals(VariableContractType b) {
00088 return this.type == b.type;
00089 }
00090
00091 public String toString() {
00092 if (type == 0) {
00093 return ProActiveDescriptorConstants.VARIABLES_DESCRIPTOR_TAG;
00094 }
00095 if (type == 1) {
00096 return ProActiveDescriptorConstants.VARIABLES_PROGRAM_TAG;
00097 }
00098 if (type == 2) {
00099 return ProActiveDescriptorConstants.VARIABLES_JAVAPROPERTY_TAG;
00100 }
00101 if (type == 3) {
00102 return ProActiveDescriptorConstants.VARIABLES_PROGRAM_DEFAULT_TAG;
00103 }
00104 if (type == 4) {
00105 return ProActiveDescriptorConstants.VARIABLES_DESCRIPTOR_DEFAULT_TAG;
00106 }
00107 if (type == 5) {
00108 return ProActiveDescriptorConstants.VARIABLES_JAVAPROPERTY_DESCRIPTOR_TAG;
00109 }
00110 if (type == 6) {
00111 return ProActiveDescriptorConstants.VARIABLES_JAVAPROPERTY_PROGRAM_TAG;
00112 }
00113
00114 return "UnkownVariable";
00115 }
00116
00117 public static VariableContractType getType(String type) {
00118 if (type.equals(ProActiveDescriptorConstants.VARIABLES_DESCRIPTOR_TAG)) {
00119 return DescriptorVariable;
00120 }
00121 if (type.equals(ProActiveDescriptorConstants.VARIABLES_PROGRAM_TAG)) {
00122 return ProgramVariable;
00123 }
00124 if (type.equals(ProActiveDescriptorConstants.VARIABLES_JAVAPROPERTY_TAG)) {
00125 return JavaPropertyVariable;
00126 }
00127 if (type.equals(
00128 ProActiveDescriptorConstants.VARIABLES_PROGRAM_DEFAULT_TAG)) {
00129 return ProgramDefaultVariable;
00130 }
00131 if (type.equals(
00132 ProActiveDescriptorConstants.VARIABLES_DESCRIPTOR_DEFAULT_TAG)) {
00133 return DescriptorDefaultVariable;
00134 }
00135 if (type.equals(ProActiveDescriptorConstants.VARIABLES_JAVAPROPERTY_DESCRIPTOR_TAG)) {
00136 return JavaPropertyDescriptorDefault;
00137 }
00138 if (type.equals(ProActiveDescriptorConstants.VARIABLES_JAVAPROPERTY_PROGRAM_TAG)) {
00139 return JavaPropertyProgramDefault;
00140 }
00141
00142 return null;
00143 }
00144
00150 public boolean hasSetAbility(String from) {
00151 for (int i = 0; i < setAbility.length; i++)
00152 if (from.equalsIgnoreCase(setAbility[i])) {
00153 return true;
00154 }
00155
00156 return false;
00157 }
00158
00164 public boolean hasSetEmptyAbility(String from) {
00165 for (int i = 0; i < setEmptyAbility.length; i++)
00166 if (from.equalsIgnoreCase(setEmptyAbility[i])) {
00167 return true;
00168 }
00169
00170 return false;
00171 }
00172
00179 public boolean hasPriority(String current, String candidate) {
00180 int i;
00181 int j;
00182
00183
00184 for (i = 0; i < priority.length; i++)
00185 if (current.equalsIgnoreCase(priority[i])) {
00186 break;
00187 }
00188
00189
00190 for (j = 0; j < priority.length; j++)
00191 if (candidate.equalsIgnoreCase(priority[j])) {
00192 break;
00193 }
00194
00195 return j <= i;
00196 }
00197
00198 public String getEmptyErrorMessage(String name){
00199
00200 String canSetValue="nobody";
00201 for(int i=0;i<setAbility.length;i++){
00202 canSetValue=setAbility[i]+" ";
00203 }
00204
00205 return "Empty value for variable"+ this.toString() +" "+name+
00206 " value can be set by: "+canSetValue;
00207 }
00208 }