class DSpaceControlledVocabulary extends SelfNamedPlugin implements ChoiceAuthority {

    @Override
    public Choices getMatches(String field, String text, Collection collection, int start, int limit, String locale)
    {
    	init();
    	log.debug("Getting matches for '" + text + "'");
        String xpathExpression = "";
        String[] textHierarchy = text.split(hierarchyDelimiter, -1);
        for (int i = 0; i < textHierarchy.length; i++) {
            xpathExpression += String.format(xpathTemplate, textHierarchy[i].replaceAll("'", "&apos;").toLowerCase());
        }
    	XPath xpath = XPathFactory.newInstance().newXPath();
    	Choice[] choices;
    	try {
            NodeList results = (NodeList) xpath.evaluate(xpathExpression,
                    vocabulary, XPathConstants.NODESET);
            String[] authorities = new String[results.getLength()];
            String[] values = new String[results.getLength()];
            String[] labels = new String[results.getLength()];
            for (int i = 0; i < results.getLength(); i++)
            {
                Node node = results.item(i);
                String hierarchy = this.buildString(node);
                if (this.suggestHierarchy)
                {
                    labels[i] = hierarchy;
                }
                else
                {
                    labels[i] = node.getAttributes().getNamedItem("label").getNodeValue();
                }
                if (this.storeHierarchy)
                {
                    values[i] = hierarchy;
                }
                else
                {
                    values[i] = node.getAttributes().getNamedItem("label").getNodeValue();
                }
                Node idAttr = node.getAttributes().getNamedItem("id");
                if (null != idAttr) // 'id' is optional
                    authorities[i] = idAttr.getNodeValue();
            }
            int resultCount = labels.length - start;
            if ((limit > 0) && (resultCount > limit)) // limit = 0 means no limit
                resultCount = limit;
            choices = new Choice[resultCount];
            if (resultCount > 0)
            {
                for (int i = 0; i < resultCount; i++)
                {
                    choices[i] = new Choice(authorities[start + i], values[start
                            + i], labels[start + i]);
                }
            }
    	} catch(XPathExpressionException e) {
    		choices = new Choice[0];
    	}
    	return new Choices(choices, 0, choices.length, Choices.CF_AMBIGUOUS, false);
    }

    public  DSpaceControlledVocabulary();

}