From: <mwl...@us...> - 2008-09-23 17:30:55
|
Revision: 812 http://cishell.svn.sourceforge.net/cishell/?rev=812&view=rev Author: mwlinnem Date: 2008-09-23 17:30:40 +0000 (Tue, 23 Sep 2008) Log Message: ----------- Extended Preference AD and OCD interfaces to facilitate type prefix lookup. Modified Paths: -------------- trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/PreferenceAD.java trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/PreferenceOCD.java trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/PreferenceADImpl.java trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/PreferenceOCDImpl.java trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/TypePrefixes.java Modified: trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/PreferenceAD.java =================================================================== --- trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/PreferenceAD.java 2008-09-22 20:31:59 UTC (rev 811) +++ trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/PreferenceAD.java 2008-09-23 17:30:40 UTC (rev 812) @@ -29,6 +29,8 @@ public abstract int getType(); public abstract int getPreferenceType(); + + public abstract String getPreferenceTypePrefix(); public abstract String validate(String value); Modified: trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/PreferenceOCD.java =================================================================== --- trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/PreferenceOCD.java 2008-09-22 20:31:59 UTC (rev 811) +++ trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/PreferenceOCD.java 2008-09-23 17:30:40 UTC (rev 812) @@ -14,6 +14,8 @@ //use to get at the special preference attribute goodness. public abstract PreferenceAD[] getPreferenceAttributeDefinitions( int filter); + + public abstract PreferenceAD getAttributeByID(String attributeID); public abstract String getDescription(); Modified: trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/PreferenceADImpl.java =================================================================== --- trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/PreferenceADImpl.java 2008-09-22 20:31:59 UTC (rev 811) +++ trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/PreferenceADImpl.java 2008-09-23 17:30:40 UTC (rev 812) @@ -34,7 +34,7 @@ private int inferPreferenceType(AttributeDefinition realAD) { int preferenceType; - if (realAD.getType() == AttributeDefinition.STRING) { + if (realAD.getType() != PreferenceAD.TEXT) { String defaultVal = realAD.getDefaultValue()[0]; if (defaultVal.startsWith(TypePrefixes.DIRECTORY_PREFIX)) { @@ -194,6 +194,10 @@ public int getPreferenceType() { return this.preferenceType; } + + public String getPreferenceTypePrefix() { + return TypePrefixes.getPrefPrefixFromPrefTypeID(new Integer(this.getPreferenceType())); + } /* (non-Javadoc) * @see org.cishell.service.prefadmin.shouldbeelsewhere.PreferenceAttributeDefinition#validate(java.lang.String) @@ -201,5 +205,4 @@ public String validate(String value) { return this.realAD.validate(value); } - } Modified: trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/PreferenceOCDImpl.java =================================================================== --- trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/PreferenceOCDImpl.java 2008-09-22 20:31:59 UTC (rev 811) +++ trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/PreferenceOCDImpl.java 2008-09-23 17:30:40 UTC (rev 812) @@ -90,4 +90,23 @@ return this.realOCD.getName(); } + public PreferenceAD getAttributeByID(String attributeID) { + PreferenceAD adWeAreLookingFor = null; + + PreferenceAD[] ads = this.getPreferenceAttributeDefinitions(ObjectClassDefinition.ALL); + for (int ii = 0; ii < ads.length; ii++) { + PreferenceAD ad = ads[ii]; + + if (ad.getID().equals(attributeID)) { + adWeAreLookingFor = ad; + break; + } + } + + if (adWeAreLookingFor != null) { + return adWeAreLookingFor; + } else { + return null; + } + } } Modified: trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/TypePrefixes.java =================================================================== --- trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/TypePrefixes.java 2008-09-22 20:31:59 UTC (rev 811) +++ trunk/core/org.cishell.reference.prefs.admin/src/org/cishell/reference/prefs/admin/internal/TypePrefixes.java 2008-09-23 17:30:40 UTC (rev 812) @@ -1,5 +1,9 @@ package org.cishell.reference.prefs.admin.internal; +import java.util.HashMap; +import java.util.Map; + +import org.cishell.reference.prefs.admin.PreferenceAD; import org.osgi.service.metatype.AttributeDefinition; public class TypePrefixes { @@ -10,8 +14,49 @@ public static final String PATH_PREFIX = "path:"; public static final String COLOR_PREFIX = "color:"; + private static Map prefixToTypeID = new HashMap(); + static { + prefixToTypeID.put(FONT_PREFIX, new Integer(PreferenceAD.FONT)); + prefixToTypeID.put(DIRECTORY_PREFIX, new Integer(PreferenceAD.DIRECTORY)); + prefixToTypeID.put(FILE_PREFIX, new Integer(PreferenceAD.FILE)); + prefixToTypeID.put(PATH_PREFIX, new Integer(PreferenceAD.PATH)); + prefixToTypeID.put(COLOR_PREFIX, new Integer(PreferenceAD.COLOR)); + } + + private static Map typeIDToPrefix = new HashMap(); + static { + typeIDToPrefix.put(new Integer(PreferenceAD.FONT), FONT_PREFIX); + typeIDToPrefix.put(new Integer(PreferenceAD.DIRECTORY), DIRECTORY_PREFIX); + typeIDToPrefix.put(new Integer(PreferenceAD.FILE), FILE_PREFIX); + typeIDToPrefix.put(new Integer(PreferenceAD.PATH), PATH_PREFIX); + typeIDToPrefix.put(new Integer(PreferenceAD.COLOR), COLOR_PREFIX); + typeIDToPrefix.put(new Integer(PreferenceAD.CHOICE), ""); + typeIDToPrefix.put(new Integer(PreferenceAD.PATH), ""); + typeIDToPrefix.put(new Integer(PreferenceAD.TEXT), ""); + } public static boolean hasPrefix(AttributeDefinition prefAD, String prefix) { return prefAD.getDefaultValue()[0].startsWith(prefix); } + + //Will return "" for unrecognized prefixes + public static String getPrefPrefixFromPrefTypeID(Integer typeID) { + String prefix = (String) typeIDToPrefix.get(typeID); + if (prefix != null) { + return prefix; + } else { + return ""; + } + } + + //Will return -1 for unrecognized type IDs. + public static Integer getPrefTypeIDFromPrefix(String prefix) { + Integer typeID = (Integer) prefixToTypeID.get(prefix); + if (typeID != null) { + return typeID; + } else { + System.err.println("Warning: unable to return valid type ID for prefix '" + prefix + "' in TypePrefix.prefPrefixToPrefTypeID"); + return new Integer(-1); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |