001: /*
002: * PropertyClassNameUtil to rematch CM model type
003: */
004:
005: package com.icesoft.jsfmeta.eclipse;
006:
007: import com.icesoft.jsfmeta.util.ConfigStorage;
008: import com.icesoft.jsfmeta.util.GeneratorUtil;
009: import java.util.Arrays;
010: import java.util.HashMap;
011: import java.util.HashSet;
012: import java.util.Iterator;
013: import java.util.Map;
014: import java.util.Properties;
015: import java.util.Set;
016:
017: public class PropertyClassNameUtil {
018:
019: private Properties properties;
020: private Map propertyNameToTypeMap = new HashMap();
021: private Map propertyClassToTypeMap = new HashMap();
022: private Map propertyCategoryToTypeMap = new HashMap();
023:
024: public PropertyClassNameUtil() {
025: properties = loadProperties();
026: initMapping();
027: }
028:
029: public Properties loadProperties() {
030:
031: String filePath = GeneratorUtil.getWorkingFolder()
032: + "conf/eclipse.schema/cm_type.properties";
033: Properties props = ConfigStorage.getInstance(filePath)
034: .loadProperties();
035: for (Iterator iterator = props.keySet().iterator(); iterator
036: .hasNext();) {
037: Object nextKey = iterator.next();
038: }
039: return props;
040: }
041:
042: public void initMapping() {
043: String[] propertyNames = new String[] { "style", "styleClass",
044: "bgcolor", "binding" };
045: String[] propertyTypes = new String[] { "CSSSTYLE", "CSSCLASS",
046: "COLOR", "PROPERTYBINDING" };
047:
048: for (int i = 0; i < propertyNames.length; i++) {
049: propertyNameToTypeMap.put(propertyNames[i],
050: propertyTypes[i]);
051: }
052:
053: String[] propertyClasses = new String[] {
054: "com.icesoft.faces.context.effects.Effect", "boolean",
055: "java.lang.Object", "javax.faces.el.MethodBinding" };
056: String[] propertyClassesToTypes = new String[] {
057: "METHODBINDING", "BOOLEAN", "METHODBINDING",
058: "METHODBINDING" };
059:
060: for (int i = 0; i < propertyClasses.length; i++) {
061: propertyClassToTypeMap.put(propertyClasses[i],
062: propertyClassesToTypes[i]);
063: }
064:
065: String[] propertyCategories = new String[] { "javascript" };
066: String[] propertyCategroiesToTypes = new String[] { "JAVASCRIPT" };
067:
068: for (int i = 0; i < propertyCategories.length; i++) {
069: propertyClassToTypeMap.put(propertyCategories[i],
070: propertyCategroiesToTypes[i]);
071: }
072:
073: }
074:
075: //vwp metadata
076: private final static Set propertyClassHashSet = new HashSet(Arrays
077: .asList(new String[] { "boolean",
078: "com.icesoft.faces.context.effects.Effect", "int",
079: "java.lang.Object", "java.lang.String",
080: "java.util.List", "javax.faces.convert.Converter",
081: "javax.faces.el.MethodBinding" }));
082:
083: //eclipse cm model property type keywords
084: private final static Set propertyTypeHashSet = new HashSet(Arrays
085: .asList(new String[] { "BOOLEAN", "COLOR", "CSSCLASS",
086: "CSSSTYLE", "ENUMERATED", "JAVASCRIPT",
087: "METHODBINDING", "NAMED-BOOLEAN",
088: "PROPERTYBINDING", "RELATIVEPATH", "WEBPATH" }));
089:
090: public static boolean isPropertyType(String name) {
091: return propertyTypeHashSet.contains(name);
092: }
093:
094: public static boolean isPropertyClass(String name) {
095: return propertyClassHashSet.contains(name);
096: }
097:
098: //eclipse a separate marker for editor class yet, so type is associated with editor
099: //
100: public String getMatchedName(String propertyClassName,
101: String propertyCategoryName, String propertyName,
102: String propertyEditor) {
103:
104: if (propertyClassName != null) {
105: propertyClassName = propertyClassName.trim();
106: }
107:
108: if (propertyCategoryName != null) {
109: propertyCategoryName = propertyCategoryName.trim();
110: }
111:
112: if (propertyName != null) {
113: propertyName = propertyName.trim();
114: }
115:
116: if ((String) propertyNameToTypeMap.get(propertyName) != null) {
117: return (String) propertyNameToTypeMap.get(propertyName);
118: }
119:
120: if ((String) propertyClassToTypeMap.get(propertyClassName) != null) {
121: return (String) propertyClassToTypeMap
122: .get(propertyClassName);
123: }
124:
125: if ((String) propertyCategoryToTypeMap
126: .get(propertyCategoryName) != null) {
127: return (String) propertyCategoryToTypeMap
128: .get(propertyCategoryName);
129: }
130:
131: if (propertyEditor != null
132: && (String) properties.get(propertyEditor) != null) {
133: return (String) properties.get(propertyEditor);
134: }
135:
136: return null;
137: }
138:
139: }
|