Example usage for org.apache.commons.logging Log error

List of usage examples for org.apache.commons.logging Log error

Introduction

In this page you can find the example usage for org.apache.commons.logging Log error.

Prototype

void error(Object message);

Source Link

Document

Logs a message with error log level.

Usage

From source file:org.eclipse.smila.search.templates.TemplateRegistryController.java

/**
 * Returns the template for the given index. These attempts are made in this order: 1. cache; 2. file 3. dummy
 * // w w  w . j  ava 2  s .  co m
 * @param indexName
 *          Index name.
 * @return Field templates.
 * @throws TemplateException
 *           Unable to resolve field templates.
 */
public static DFieldTemplates getFieldTemplates(String indexName) throws TemplateException {
    final Log log = LogFactory.getLog(TemplateRegistryController.class);

    checkIndexExistance(indexName);

    synchronized (s_fieldTemplates) {
        // try to get from cache
        if (s_fieldTemplates.containsKey(indexName)) {
            return s_fieldTemplates.get(indexName);
        } else {
            DFieldTemplates templates = null;
            final File file = getFieldTemplateFile(indexName);

            // create dummy (empty) template
            if (!file.exists()) {
                templates = new DFieldTemplates();
                templates.setIndexName(indexName);

                // create templatefile
                saveTemplateToDisk(templates);
            } else {
                // load template file
                try {
                    final Document doc = XMLUtils.parse(file, new XMLUtilsConfig());
                    templates = DFieldTemplatesCodec.decode(doc.getDocumentElement());
                } catch (final XMLUtilsException e) {
                    log.error(e.getMessage());
                    throw new TemplateException("unable to parse templates file [" + file.getName() + "]", e);
                } catch (final DFieldTemplatesException e) {
                    log.error("unable to load templates file [" + file.getName() + "]: " + e.getMessage(), e);
                    throw new TemplateException("unable to decode templates file [" + file.getName() + "]", e);
                }
            }
            // register file
            s_fieldTemplates.put(indexName, templates);
            return templates;
        }
    }
}

From source file:org.eclipse.smila.search.utils.advsearch.AdvSearchAccess.java

public static AdvSearchAccess getInstance() {
    final Log log = LogFactory.getLog(AdvSearchAccess.class);
    AdvSearchAccess[] types;//from  w w  w  .  j a  v a2 s.  c  om
    try {
        types = getTypes();
        if (types.length != 1) {
            if (log.isWarnEnabled()) {
                log.warn("invalid index structure access count [" + types.length + "]");
            }
            return null;
        }
        return types[0];
    } catch (final AdvSearchException e) {
        if (log.isErrorEnabled()) {
            log.error(e);
        }
        return null;
    }
}

From source file:org.eclipse.smila.search.utils.advsearch.AdvSearchAccess.java

/**
 * Get all available IRM types.//from  ww  w. jav  a  2s.  com
 * 
 * @return IRM types.
 */
public static AdvSearchAccess[] getTypes() throws AdvSearchException {

    if (s_cachedAdvSearchAccess != null) {
        return s_cachedAdvSearchAccess;
    }

    final Log log = LogFactory.getLog(AdvSearchAccess.class);

    final List<AdvSearchAccess> found = new ArrayList<AdvSearchAccess>();
    // TODO: Check why the next line is needed.
    // found.add(UNKNOWN);
    final IExtension[] extensions = Platform.getExtensionRegistry()
            .getExtensionPoint(EXTENSION_POINT_NAME_ADV_SEARCH_ACCESS).getExtensions();
    for (int i = 0; i < extensions.length; i++) {
        final IExtension extension = extensions[i];
        final IConfigurationElement[] configElements = extension.getConfigurationElements();

        for (int j = 0; j < configElements.length; j++) {
            final IConfigurationElement configurationElement = configElements[j];
            final String typeName = parseType(configurationElement, found.size());

            AdvSearchAccess clazz = null;
            try {
                final Object obj = configurationElement.createExecutableExtension("Clazz");
                clazz = (AdvSearchAccess) obj;
            } catch (final Exception exception) {
                if (log.isErrorEnabled()) {
                    if (configurationElement != null) {
                        log.error("Failed to instantiate adv. search access");
                    } else {
                        log.error("Unknown!");
                    }
                }
                throw new AdvSearchException("unable to load adv. search access", exception);
            }

            if (clazz != null) {
                found.add(clazz);
            }
        }
    }

    s_cachedAdvSearchAccess = found.toArray(new AdvSearchAccess[0]);
    return s_cachedAdvSearchAccess;
}

From source file:org.eclipse.smila.search.utils.indexstructure.IndexStructureAccess.java

public static IndexStructureAccess getInstance() {

    final Log log = LogFactory.getLog(IndexStructureAccess.class);

    IndexStructureAccess[] types;//from w  w w .j  a v a  2  s  . co  m
    try {
        types = getTypes();
        if (types.length != 1) {
            if (log.isWarnEnabled()) {
                log.warn("invalid index structure access count [" + types.length + "]");
            }
            return null;
        }
        return types[0];
    } catch (final ISException e) {
        if (log.isErrorEnabled()) {
            log.error(e);
        }
        return null;
    }
}

From source file:org.eclipse.smila.search.utils.indexstructure.IndexStructureAccess.java

/**
 * Get all available IRM types./*from  w w  w . j  av  a 2  s . co  m*/
 * 
 * @return IRM types.
 * @throws ISException
 *           -
 */
public static IndexStructureAccess[] getTypes() throws ISException {

    if (s_cachedIndexStructureAccess != null) {
        return s_cachedIndexStructureAccess;
    }

    final Log log = LogFactory.getLog(IndexStructureAccess.class);

    final List<IndexStructureAccess> found = new ArrayList<IndexStructureAccess>();
    // TODO: Check why the next line is needed.
    // found.add(UNKNOWN);
    final IExtension[] extensions = Platform.getExtensionRegistry()
            .getExtensionPoint(EXTENSION_POINT_NAME_INDEX_STRUCTURE_ACCESS).getExtensions();
    for (int i = 0; i < extensions.length; i++) {
        final IExtension extension = extensions[i];
        final IConfigurationElement[] configElements = extension.getConfigurationElements();

        for (int j = 0; j < configElements.length; j++) {
            final IConfigurationElement configurationElement = configElements[j];
            final String typeName = parseType(configurationElement, found.size());

            IndexStructureAccess clazz = null;
            try {
                final Object obj = configurationElement.createExecutableExtension("Clazz");
                clazz = (IndexStructureAccess) obj;
            } catch (final Exception exception) {
                if (log.isErrorEnabled()) {
                    if (configurationElement != null) {
                        log.error("Failed to instantiate index structure access");
                    } else {
                        log.error("Unknown!");
                    }
                }
                throw new ISException("unable to load index structure access", exception);
            }

            if (clazz != null) {
                found.add(clazz);
            }
        }
    }

    s_cachedIndexStructureAccess = found.toArray(new IndexStructureAccess[0]);
    return s_cachedIndexStructureAccess;
}

From source file:org.eclipse.smila.search.utils.param.def.DParameterDefinition.java

public static void main(String[] arg) {
    final Log log = LogFactory.getLog(DParameterDefinition.class);
    try {/* w ww .j a  v a  2s.co  m*/
        final org.w3c.dom.Document d = XMLUtils
                .parse(new java.io.File("d:/anyfinder/af-engine-sdk/xml/param-testcase.xml"), true);
        final DParameterDefinition pset = DParameterDefinitionCodec.decode(d.getDocumentElement());

        final org.w3c.dom.Document d2 = XMLUtils.getDocument("top");
        final org.w3c.dom.Element e = d2.getDocumentElement();
        final org.w3c.dom.Element pelement = DParameterDefinitionCodec.encode(pset, e);

        XMLUtils.stream(pelement, false, "UTF-8", System.err);
    } catch (final Exception e) {
        if (log.isErrorEnabled()) {
            log.error(e);
        }
    }
}

From source file:org.eclipse.smila.search.utils.param.ParameterSet.java

public static void main(String[] arg) {
    final Log log = LogFactory.getLog(ParameterSet.class);
    try {//from   w ww .ja  v a  2s .c  o  m

        // DParameterSet einlesen
        org.w3c.dom.Document d = XMLUtils
                .parse(new java.io.File("d:/anyfinder/af-engine-sdk/xml/param-testcase.xml"), true);
        final DParameterSet pset = DParameterSetCodec.decode(d.getDocumentElement());

        org.w3c.dom.Document d2 = XMLUtils.getDocument("top");
        org.w3c.dom.Element e = d2.getDocumentElement();
        org.w3c.dom.Element pelement = DParameterSetCodec.encode(pset, e);

        XMLUtils.stream(pelement, false, "UTF-8", System.err);

        // DParameterDefinition einlesen
        d = XMLUtils.parse(new java.io.File("d:/anyfinder/af-engine-sdk/xml/paramdef-testcase.xml"), true);
        final DParameterDefinition pdef = DParameterDefinitionCodec.decode(d.getDocumentElement());

        d2 = XMLUtils.getDocument("top");
        e = d2.getDocumentElement();
        pelement = DParameterDefinitionCodec.encode(pdef, e);

        XMLUtils.stream(pelement, false, "UTF-8", System.err);

        // ParameterSet erzeugen
        final ParameterSet ps = new ParameterSet(pset, pdef);

        final Enumeration en = ps.getParameterNames();
        for (; en.hasMoreElements();) {
            final String pname = (String) en.nextElement();
            final String ptype = ps.getParameterType(pname);
            Object value = ps.getParameter(pname);
            if (ptype.indexOf("List") >= 0) {
                String newValue = "";

                for (int i = 0; true; i++) {
                    try {
                        newValue += Array.get(value, i);
                        Array.get(value, i + 1);
                        newValue += ", ";
                    } catch (final ArrayIndexOutOfBoundsException iae) {
                        break;
                    }
                }
                value = newValue;
            }
            if (log.isInfoEnabled()) {
                log.info(pname + "(" + ptype + "):\t" + value);
            }
        }
    } catch (final Exception e) {
        if (log.isErrorEnabled()) {
            log.error(e);
        }
    }
}

From source file:org.eclipse.smila.search.utils.search.SearchAccess.java

public static SearchAccess getInstance() {

    final Log log = LogFactory.getLog(SearchAccess.class);

    SearchAccess[] types;// w w w  .ja v a2s  .  c o  m
    try {
        types = getTypes();
        if (types.length != 1) {
            if (log.isWarnEnabled()) {
                log.warn("invalid index structure access count [" + types.length + "]");
            }
            return null;
        }
        return types[0];
    } catch (final DSearchException e) {
        if (log.isErrorEnabled()) {
            log.error(e);
        }
        return null;
    }
}

From source file:org.eclipse.smila.search.utils.search.SearchAccess.java

/**
 * Get all available IRM types.//from  w  w w .j a va  2s  .  c  o  m
 * 
 * @return IRM types.
 */
public static SearchAccess[] getTypes() throws DSearchException {

    if (s_cachedSearchAccess != null) {
        return s_cachedSearchAccess;
    }

    final Log log = LogFactory.getLog(SearchAccess.class);

    final List<SearchAccess> found = new ArrayList<SearchAccess>();
    // TODO: Check why the next line is needed.
    // found.add(UNKNOWN);
    final IExtension[] extensions = Platform.getExtensionRegistry()
            .getExtensionPoint(EXTENSION_POINT_NAME_SEARCH_ACCESS).getExtensions();
    for (int i = 0; i < extensions.length; i++) {
        final IExtension extension = extensions[i];
        final IConfigurationElement[] configElements = extension.getConfigurationElements();

        for (int j = 0; j < configElements.length; j++) {
            final IConfigurationElement configurationElement = configElements[j];
            final String typeName = parseType(configurationElement, found.size());

            SearchAccess clazz = null;
            try {
                final Object obj = configurationElement.createExecutableExtension("Clazz");
                clazz = (SearchAccess) obj;
            } catch (final Exception exception) {
                if (log.isErrorEnabled()) {
                    if (configurationElement != null) {
                        log.error("Failed to instantiate search access");
                    } else {
                        log.error("Unknown!");
                    }
                }
                throw new DSearchException("unable to load search access", exception);
            }

            if (clazz != null) {
                found.add(clazz);
            }
        }
    }

    s_cachedSearchAccess = found.toArray(new SearchAccess[0]);
    return s_cachedSearchAccess;
}

From source file:org.eclipse.smila.utils.jaxb.JaxbUtils.java

/**
 * Creates the validation event handler.
 * //from w  ww  .java2  s. c o  m
 * @return the validation event handler
 */
public static ValidationEventHandler createValidationEventHandler() {
    return new ValidationEventHandler() {
        public boolean handleEvent(final ValidationEvent ve) {
            final Log log = LogFactory.getLog(JaxbUtils.class);
            if (ve.getSeverity() != ValidationEvent.WARNING) {
                final ValidationEventLocator vel = ve.getLocator();
                if (log.isErrorEnabled()) {
                    log.error("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + "]:"
                            + ve.getMessage());
                }
                return false;
            }
            return true;
        }
    };
}