List of usage examples for org.apache.commons.logging Log error
void error(Object message, Throwable t);
From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java
/** * Parses the data dictionary./* w w w.j a v a2 s . co m*/ * * @param is * the is * @param log * the log * * @return the d any finder data dictionary * * @throws DataDictionaryException * the data dictionary exception */ private static DAnyFinderDataDictionary parseDataDictionary(final InputStream is, final Log log) throws DataDictionaryException { try { final Document doc = XMLUtils.parse(is, new XMLUtilsConfig()); return DAnyFinderDataDictionaryCodec.decode(doc.getDocumentElement()); } catch (final XMLUtilsException e) { log.error("Unable parse DataDictionary!", e); throw new DataDictionaryException("Unable parse DataDictionary!"); } catch (final DDException e) { log.error("unable to load data dictionary", e); throw new DataDictionaryException("Unable to decode XML into DataDictionary"); } finally { IOUtils.closeQuietly(is); } }
From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java
/** * Save./*from w w w . jav a2s .c o m*/ * * @throws DataDictionaryException * the data dictionary exception */ private static void save() throws DataDictionaryException { final Log log = LogFactory.getLog(DataDictionaryController.class); // resolve datadictionary name File workspaceFolder; try { workspaceFolder = WorkspaceHelper.createWorkingDir(BUNDLE); } catch (final IOException e) { throw new DataDictionaryException(e); } // save datadictionary try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new File(workspaceFolder, CONFIG_NAME)); } catch (final DDException e) { log.error("unable to save data dictionary", e); try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); log.debug( "invalid data dictionary\n" + new String(XMLUtils.stream(doc.getDocumentElement(), false))); } catch (final Throwable ex) { ; // do nothing } throw new DataDictionaryException("unable to update data dictionary"); } catch (final XMLUtilsException e) { log.error("Unable to stream DataDictionary!", e); try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); log.debug( "invalid data dictionary\n" + new String(XMLUtils.stream(doc.getDocumentElement(), false))); } catch (final Throwable ex) { ; // do nothing } throw new DataDictionaryException("Unable to stream DataDictionary!"); } }
From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java
/** * Sets the index configuration.//from ww w . j a va2s . c o m * * @param indexName * the index name * @param dConfiguration * the d configuration * * @throws DataDictionaryException * the data dictionary exception */ public static void setIndexConfiguration(final String indexName, final DConfiguration dConfiguration) throws DataDictionaryException { final Log log = LogFactory.getLog(DataDictionaryController.class); synchronized (mutex) { ensureLoaded(); if (!hasIndex(indexName)) { throw new DataDictionaryException("index does not exist in data dictionary [" + indexName + "]"); } // check validity of configuration final DIndex dIndex = dd.getIndex(indexName); final DIndexStructure dIS = dIndex.getIndexStructure(); validateConfiguration(dConfiguration, dIS); dIndex.setConfiguration(dConfiguration); // validate data dictionary try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new ByteArrayOutputStream()); } catch (final DDException e) { log.error("unable to save data dictionary", e); try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); log.debug("invalid data dictionary\n" + new String(XMLUtils.stream(doc.getDocumentElement(), false))); } catch (final Throwable ex) { ; // do nothing } throw new DataDictionaryException("invalid data dictionary"); } catch (final XMLUtilsException e) { log.error("Unable to stream DataDictionary!", e); try { final Document doc = DAnyFinderDataDictionaryCodec.encode(dd); log.debug("invalid data dictionary\n" + new String(XMLUtils.stream(doc.getDocumentElement(), false))); } catch (final Throwable ex) { ; // do nothing } throw new DataDictionaryException("invalid data dictionary while streaming"); } save(); } }
From source file:org.eclipse.smila.search.datadictionary.messages.ddconfig.DFieldConfigCodec.java
/** * Decode standard values of a field config. * /*from www . j a v a 2 s.co m*/ * @param dField * Field config. * @param element * Element. * @throws ConfigurationException * Unable to decode field config. */ public static void decodeStandardValues(DFieldConfig dField, Element element) throws ConfigurationException { final Log log = LogFactory.getLog(DFieldConfigCodec.class); if (element.hasAttribute("Weight")) { dField.setWeight(new Integer(element.getAttribute("Weight"))); } if (element.hasAttribute("FieldTemplate")) { dField.setFieldTemplate(element.getAttribute("FieldTemplate")); } if (element.hasAttribute("Constraint")) { dField.setConstraint(element.getAttribute("Constraint")); } final NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { if (!(nl.item(i) instanceof Element)) { continue; } final Element el = (Element) nl.item(i); if ("Transformer".equals(el.getLocalName())) { try { dField.setTransformer(DTransformerCodec.decode(el)); } catch (final DSearchException e) { log.error("Unable to decode Transformer: " + e.getMessage(), e); throw new ConfigurationException("Unable to decode Transformer: " + e.getMessage()); } } else if ("NodeTransformer".equals(el.getLocalName())) { try { dField.setNodeTransformer(DNodeTransformerCodec.decode(el)); } catch (final DSearchException e) { log.error("Unable to decode NodeTransformer: " + e.getMessage(), e); throw new ConfigurationException("Unable to decode NodeTransformer: " + e.getMessage()); } } } }
From source file:org.eclipse.smila.search.datadictionary.messages.ddconfig.DFieldConfigCodec.java
/** * Decode standard values of a field config. * /*from w ww . j a va2 s.co m*/ * @param dField * Field config. * @param element * Element. * @throws ConfigurationException * Unable to decode standard values. */ public static void encodeStandardValues(DFieldConfig dField, Element element) throws ConfigurationException { final Log log = LogFactory.getLog(DFieldConfigCodec.class); if (dField.getWeight() != null) { element.setAttribute("Weight", dField.getWeight() + ""); } if (dField.getFieldTemplate() != null) { element.setAttribute("FieldTemplate", dField.getFieldTemplate()); } if (dField.getConstraint() != null) { element.setAttribute("Constraint", dField.getConstraint()); } if (dField.getNodeTransformer() != null) { try { DNodeTransformerCodec.encode(dField.getNodeTransformer(), element); } catch (final DSearchException e) { log.error("Unable to encode NodeTransformer: " + e.getMessage(), e); throw new ConfigurationException("Unable to encode NodeTransformer: " + e.getMessage()); } } if (dField.getTransformer() != null) { try { DTransformerCodec.encode(dField.getTransformer(), element); } catch (final DSearchException e1) { log.error("Unable to encode Transformer: " + e1.getMessage(), e1); throw new ConfigurationException("Unable to encode Transformer: " + e1.getMessage()); } } }
From source file:org.eclipse.smila.search.datadictionary.messages.ddconfig.DHighlightingTransformerCodec.java
public static DHighlightingTransformer decode(Element element) throws ConfigurationException { final Log log = LogFactory.getLog(DHighlightingTransformerCodec.class); final DHighlightingTransformer dHighlightingTransformer = new DHighlightingTransformer(); dHighlightingTransformer.setName(element.getAttribute("Name")); final NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { if ("ParameterSet".equals(nl.item(i).getLocalName())) { try { dHighlightingTransformer.setParameterSet(DParameterSetCodec.decode((Element) nl.item(i))); } catch (final ParameterException e) { log.error("Unable to decode parameters for HighlightingTransformer: " + e.getMessage(), e); throw new ConfigurationException( "Unable to decode parameters for HighlightingTransformer: " + e.getMessage()); }/*from w ww .jav a 2 s . c o m*/ } } return dHighlightingTransformer; }
From source file:org.eclipse.smila.search.datadictionary.messages.ddconfig.DHighlightingTransformerCodec.java
public static Element encode(DHighlightingTransformer dHighlightingTransformer, Element element) throws ConfigurationException { final Log log = LogFactory.getLog(DHighlightingTransformerCodec.class); final Document doc = element.getOwnerDocument(); final Element el = doc.createElementNS(DConfigurationCodec.NS, "HighlightingTransformer"); el.setAttribute("Name", dHighlightingTransformer.getName()); try {//from w w w.java2 s .c o m DParameterSetCodec.encode(dHighlightingTransformer.getParameterSet(), el); } catch (final ParameterException e) { log.error("Unable to encode parameters for HighlightingTransformer: " + e.getMessage(), e); throw new ConfigurationException( "Unable to encode parameters for HighlightingTransformer: " + e.getMessage()); } element.appendChild(el); return el; }
From source file:org.eclipse.smila.search.index.IndexCleaner.java
/** * {@inheritDoc}//www .j a v a 2 s . c o m * * @see java.lang.Runnable#run() */ @Override public void run() { final Log log = LogFactory.getLog(getClass()); while (true) { try { sleep(SLEEP_TIME); IndexManager.doGarbageCollection(); } catch (final InterruptedException e) { log.error("unable to set cleaner into wait state", e.fillInStackTrace()); } } }
From source file:org.eclipse.smila.search.index.IndexConnection.java
/** * Performs a search for a fully complex query expression. * //from w w w . j a v a2s . c o m * @param dQuery * - * @return LuceneSearchResult * @throws IndexException * - */ public LuceneSearchResult doQuery(final DQuery dQuery) throws IndexException { final Log log = LogFactory.getLog(getClass()); validateQuery(dQuery); try { final DTemplate dTemplate = TemplateRegistryController.getTemplate(dQuery); IQueryExpression dQE = null; if (dTemplate != null) { if (log.isInfoEnabled()) { log.info("using template [" + dQuery.getIndexName() + ";" + dTemplate.getName() + "]"); } dQE = TemplateRegistryController.applyTemplate(dQuery, dTemplate, this); } else { // transform dQE = getSimpleSearchQuery(dQuery); } final LuceneSearchResult searchResult = doQuery(dQE, (dQuery.getStartHits() != null ? dQuery.getStartHits().intValue() : 0)); // add result attributes if (dQuery.getResultFields() != null) { addResultAttributes(dQuery.getResultFields(), searchResult); } // add highlight attributes if (dQuery.getHighlightFields() != null) { addHighlightResultAttributes(dQuery.getHighlightFields(), searchResult, dQE); } return searchResult; } catch (final TemplateException e) { log.error("error while NQE transformation", e); throw new IndexException("unable to apply templates", e); } catch (final NodeTransformerException e) { log.error("unable to perform node transformation", e); throw new IndexException("unable to perform node transformation", e); } }
From source file:org.eclipse.smila.search.index.IndexManager.java
/** * Returns the instance of a requested IndexConnection by the IndexName. This method implements a pooling mechanism * for these Object ensuring that: - onyl one IndexConnection is used at a time - there no more than the max. # of * IndexConections per Index alive.//from w w w.j a v a 2 s. c o m * * @param indexName * Index name. * * @return Index connection. * * @throws IndexException * Unable to get instance of index connection. */ public static IndexConnection getInstance(final String indexName) throws IndexException { final Log log = LogFactory.getLog(IndexManager.class); if (s_cleaner != null) { ; // remove compiler warning for cleaning thread. } IndexConnection indexConnection = null; DIndex dIndex = null; try { dIndex = DataDictionaryController.getIndex(indexName); } catch (final DataDictionaryException e) { throw new IndexException(e.getMessage()); } if (dIndex == null) { throw new IndexException("index not in data dictionary [" + indexName + "]"); } final DConnection dConnection = dIndex.getConnection(); IndexConnectionUsage indexConUsage = null; IndexUsage iu = null; while (indexConnection == null) { iu = getIndexUsage(indexName); synchronized (iu) { // check if iu in SINGLE_USAGE if (iu._usage != Usage.Multi) { throw new IndexSingleUseException("index is not in multi use mode [" + indexName + "]"); } // try to find iu that is not at work final Iterator<IndexConnectionUsage> it = iu._indexConnectionUsages.iterator(); while (it.hasNext()) { indexConUsage = it.next(); if (!indexConUsage._atWork) { indexConnection = indexConUsage._indexConnection; indexConUsage._atWork = true; break; } } // no available iu exist, create new if not exceeds max if (indexConnection == null) { if (dConnection.getMaxConnections() > iu._indexConnectionUsages.size()) { indexConUsage = new IndexConnectionUsage(); indexConUsage._atWork = true; indexConUsage._idleSince = System.currentTimeMillis(); final Plugin plugin = PluginFactory.getPlugin(); indexConUsage._indexConnection = plugin.getIndexAccess().getIndexConnection(indexName); indexConnection = indexConUsage._indexConnection; iu._indexConnectionUsages.add(indexConUsage); } } } // sync iu if (indexConnection == null) { try { Thread.sleep(5); } catch (final Exception e) { log.error("SLEEP!", e); } } } if (log.isDebugEnabled()) { log.debug("get index [" + indexConnection + "]"); } return indexConnection; }