List of usage examples for org.apache.commons.logging Log error
void error(Object message, Throwable t);
From source file:com.amazon.carbonado.repo.replicated.ReplicationTrigger.java
/** * Re-sync the replica to the master. The primary keys of both entries are * assumed to match.//from ww w .j a v a 2s . co m * * @param listener optional * @param replicaEntry current replica entry, or null if none * @param masterEntry current master entry, or null if none * @param reload true to reload master entry */ void resyncEntries(ResyncCapability.Listener<? super S> listener, S replicaEntry, S masterEntry, boolean reload) throws FetchException, PersistException { if (replicaEntry == null && masterEntry == null) { return; } Log log = LogFactory.getLog(ReplicatedRepository.class); setReplicationDisabled(); try { Transaction masterTxn = mRepository.getMasterRepository().enterTransaction(); Transaction replicaTxn = mRepository.getReplicaRepository().enterTransaction(); try { replicaTxn.setForUpdate(true); if (reload) { if (masterEntry == null) { masterEntry = mMasterStorage.prepare(); replicaEntry.copyAllProperties(masterEntry); } if (!masterEntry.tryLoad()) { masterEntry = null; } } final S newReplicaEntry; if (replicaEntry == null) { newReplicaEntry = mReplicaStorage.prepare(); masterEntry.copyAllProperties(newReplicaEntry); log.info("Inserting missing replica entry: " + newReplicaEntry); } else if (masterEntry != null) { if (replicaEntry.equalProperties(masterEntry)) { return; } newReplicaEntry = mReplicaStorage.prepare(); transferToReplicaEntry(replicaEntry, masterEntry, newReplicaEntry); log.info("Updating stale replica entry with: " + newReplicaEntry); } else { newReplicaEntry = null; log.info("Deleting bogus replica entry: " + replicaEntry); } final Object state; if (listener == null) { state = null; } else { if (replicaEntry == null) { state = listener.beforeInsert(newReplicaEntry); } else if (masterEntry != null) { state = listener.beforeUpdate(replicaEntry, newReplicaEntry); } else { state = listener.beforeDelete(replicaEntry); } } try { // Delete old entry. if (replicaEntry != null) { try { replicaEntry.tryDelete(); } catch (PersistException e) { log.error("Unable to delete replica entry: " + replicaEntry, e); if (masterEntry != null) { // Try to update instead. log.info("Updating corrupt replica entry with: " + newReplicaEntry); try { newReplicaEntry.update(); // This disables the insert step, which is not needed now. masterEntry = null; } catch (PersistException e2) { log.error("Unable to update replica entry: " + replicaEntry, e2); resyncFailed(listener, replicaEntry, masterEntry, newReplicaEntry, state); return; } } } } // Insert new entry. if (masterEntry != null && newReplicaEntry != null) { if (!newReplicaEntry.tryInsert()) { // Try to correct bizarre corruption. newReplicaEntry.tryDelete(); newReplicaEntry.tryInsert(); } } if (listener != null) { if (replicaEntry == null) { listener.afterInsert(newReplicaEntry, state); } else if (masterEntry != null) { listener.afterUpdate(newReplicaEntry, state); } else { listener.afterDelete(replicaEntry, state); } } replicaTxn.commit(); } catch (Throwable e) { resyncFailed(listener, replicaEntry, masterEntry, newReplicaEntry, state); ThrowUnchecked.fire(e); } } finally { try { masterTxn.exit(); } finally { // Do second, favoring any exception thrown from it. replicaTxn.exit(); } } } finally { setReplicationEnabled(); } }
From source file:com.mnt.base.stream.netty.NConnectionHandler.java
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof IOException) { Log.debug("ConnectionHandler: ", cause); } else {/*ww w . j a va2 s. c o m*/ Log.error(cause.getMessage(), cause); } }
From source file:com.dhcc.framework.web.context.DhccContextLoader.java
/** * Initialize Spring's web application context for the given servlet context, * using the application context provided at construction time, or creating a new one * according to the "{@link #CONTEXT_CLASS_PARAM contextClass}" and * "{@link #CONFIG_LOCATION_PARAM contextConfigLocation}" context-params. * @param servletContext current servlet context * @return the new WebApplicationContext * @see #ContextLoader(WebApplicationContext) * @see #CONTEXT_CLASS_PARAM//from w ww . j a v a 2s .c o m * @see #CONFIG_LOCATION_PARAM */ public WebApplicationContext initWebApplicationContext(ServletContext servletContext) { if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) { throw new IllegalStateException( "Cannot initialize context because there is already a root application context present - " + "check whether you have multiple ContextLoader* definitions in your web.xml!"); } Log logger = LogFactory.getLog(DhccContextLoader.class); servletContext.log("Initializing Spring root WebApplicationContext"); if (logger.isInfoEnabled()) { logger.info("Root WebApplicationContext: initialization started"); } long startTime = System.currentTimeMillis(); try { // Store context in local instance variable, to guarantee that // it is available on ServletContext shutdown. if (this.context == null) { this.context = createWebApplicationContext(servletContext); } if (this.context instanceof ConfigurableWebApplicationContext) { ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context; if (!cwac.isActive()) { // The context has not yet been refreshed -> provide services such as // setting the parent context, setting the application context id, etc if (cwac.getParent() == null) { // The context instance was injected without an explicit parent -> // determine parent for root web application context, if any. ApplicationContext parent = loadParentContext(servletContext); cwac.setParent(parent); } configureAndRefreshWebApplicationContext(cwac, servletContext); } } servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context); ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl == DhccContextLoader.class.getClassLoader()) { currentContext = this.context; } else if (ccl != null) { currentContextPerThread.put(ccl, this.context); } if (logger.isDebugEnabled()) { logger.debug("Published root WebApplicationContext as ServletContext attribute with name [" + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]"); } if (logger.isInfoEnabled()) { long elapsedTime = System.currentTimeMillis() - startTime; logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms"); } return this.context; } catch (RuntimeException ex) { logger.error("Context initialization failed", ex); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); throw ex; } catch (Error err) { logger.error("Context initialization failed", err); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err); throw err; } }
From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java
/** * Loads a module.// w ww . jav a2 s.c o m */ protected HotBeanModuleInfo loadModule(final String moduleName, final long revision) throws Exception { Log logger = this.getLog(); if (logger.isInfoEnabled()) logger.info("Loading module '" + moduleName + "', revision " + revision + "."); File moduleDirectory = new File(this.moduleRepositoryDirectory, moduleName); File moduleFile = new File(moduleDirectory, revision + MODULE_FILE_SUFFIX); File tempDir = new File(this.temporaryDirectory, moduleName + "." + revision); Manifest manifest = ModuleManifestUtils.readManifest(moduleFile); // Get version from mainfest String version = ModuleManifestUtils.getVersion(manifest); if ((version == null) || (version.trim().length() == 0)) version = "n/a"; // Get description from mainfest String description = ModuleManifestUtils.getDescription(manifest); HotBeanModuleInfo hotBeanModuleInfo = new HotBeanModuleInfo(moduleName, description, revision, version, moduleFile.lastModified()); HotBeanModuleLoader hotBeanModuleLoader = null; HotBeanContext hotBeanContext = null; String errorReason = null; HotBeanModule hotBeanModule = null; try { // Create loader hotBeanModuleLoader = super.createHotBeanModuleLoader(moduleFile, tempDir); // Create context hotBeanContext = super.createHotBeanContext(this, manifest, hotBeanModuleLoader.getClassLoader()); if ((hotBeanContext instanceof ConfigurableApplicationContext) && (this.parentApplicationContext != null)) { if (logger.isInfoEnabled()) logger.info("Setting parent Spring ApplicationContext for HotBeanContext(" + hotBeanContext + ") of module '" + moduleName + "', revision " + revision + "."); ((ConfigurableApplicationContext) hotBeanContext).setParent(this.parentApplicationContext); } // Initialize context hotBeanContext.init(); // Create module hotBeanModule = super.createHotBeanModule(hotBeanModuleInfo, hotBeanModuleLoader, hotBeanContext); // Init loader hotBeanModuleLoader.init(hotBeanModule); } catch (Exception e) { hotBeanModuleLoader = null; hotBeanContext = null; hotBeanModule = null; errorReason = e.getMessage(); logger.error( "Error loading module '" + moduleName + "', revision " + revision + " - " + errorReason + "!", e); } if (hotBeanModule == null) { hotBeanModule = super.createHotBeanModule(hotBeanModuleInfo); hotBeanModule.setError(errorReason); } // Register HotBeanModule super.registerHotBeanModule(hotBeanModule); if ((hotBeanContext != null) && logger.isInfoEnabled()) logger.info("Module '" + moduleName + "', revision " + revision + " loaded."); return hotBeanModuleInfo; }
From source file:com.amazon.carbonado.repo.replicated.ReplicatedRepository.java
@SuppressWarnings("unchecked") private <S extends Storable> void resync(ReplicationTrigger<S> replicationTrigger, Storage<S> replicaStorage, Query<S> replicaQuery, Storage<S> masterStorage, Query<S> masterQuery, ResyncCapability.Listener<? super S> listener, Throttle throttle, double desiredSpeed, Comparator comparator, Transaction replicaTxn) throws RepositoryException { final Log log = LogFactory.getLog(ReplicatedRepository.class); Cursor<S> replicaCursor = null; Cursor<S> masterCursor = null; try {/*from ww w.ja v a 2 s. c o m*/ while (replicaCursor == null) { try { replicaCursor = replicaQuery.fetch(); } catch (CorruptEncodingException e) { S replicaWithKeyOnly = recoverReplicaKey(replicaStorage, e); if (!deleteCorruptEntry(replicationTrigger, replicaWithKeyOnly, e)) { // Cannot delete it, so just give up. throw e; } } } masterCursor = masterQuery.fetch(); S lastReplicaEntry = null; S replicaEntry = null; S masterEntry = null; int count = 0, txnCount = 0; while (true) { if (throttle != null) { try { // 100 millisecond clock precision throttle.throttle(desiredSpeed, 100); } catch (InterruptedException e) { throw new FetchInterruptedException(e); } } if (replicaEntry == null && replicaCursor != null) { int skippedCount = 0; while (replicaCursor.hasNext()) { try { replicaEntry = replicaCursor.next(); if (listener != null) { listener.afterLoad(replicaEntry); } if (skippedCount > 0) { if (skippedCount == 1) { log.warn("Skipped corrupt replica entry before this one: " + replicaEntry); } else { log.warn("Skipped " + skippedCount + " corrupt replica entries before this one: " + replicaEntry); } } break; } catch (CorruptEncodingException e) { // Exception forces cursor to close. Close again to be sure. replicaCursor.close(); replicaCursor = null; S replicaWithKeyOnly = recoverReplicaKey(replicaStorage, e); boolean deleted = deleteCorruptEntry(replicationTrigger, replicaWithKeyOnly, e); // Re-open (if we can) if (lastReplicaEntry == null) { break; } replicaCursor = replicaQuery.fetchAfter(lastReplicaEntry); if (deleted) { // Skip if it cannot be deleted. try { skippedCount = replicaCursor.skipNext(++skippedCount); log.info("Skipped corrupt replica entry", e); if (replicaWithKeyOnly != null) { // Try to update entry which could not be deleted. replicaEntry = replicaWithKeyOnly; if (listener != null) { listener.afterLoad(replicaEntry); } break; } } catch (FetchException e2) { log.error("Unable to skip past corrupt replica entry", e2); throw e; } } } } } if (count++ >= RESYNC_WATERMARK || txnCount >= RESYNC_BATCH_SIZE) { replicaTxn.commit(); if (replicaCursor != null) { // Cursor should auto-close after txn commit, but force // a close anyhow. Cursor is re-opened when it is // allowed to advance. replicaCursor.close(); replicaCursor = null; } count = 0; txnCount = 0; } if (masterEntry == null && masterCursor.hasNext()) { masterEntry = masterCursor.next(); } Runnable resyncTask = null; // Comparator should treat null as high. int compare = comparator.compare(replicaEntry, masterEntry); if (compare < 0) { // Bogus record exists only in replica so delete it. resyncTask = prepareResyncTask(replicationTrigger, listener, replicaEntry, null); // Allow replica to advance. if (replicaCursor == null) { replicaCursor = replicaQuery.fetchAfter(replicaEntry); } lastReplicaEntry = replicaEntry; replicaEntry = null; } else if (compare > 0) { // Replica cursor is missing an entry so copy it. resyncTask = prepareResyncTask(replicationTrigger, listener, null, masterEntry); // Allow master to advance. masterEntry = null; } else { // If compare is zero, replicaEntry and masterEntry are // either both null or both non-null. if (replicaEntry == null && masterEntry == null) { // Both cursors exhausted -- resync is complete. break; } // Both replicaEntry and masterEntry are non-null. if (!replicaEntry.equalProperties(masterEntry)) { // Replica is stale. resyncTask = prepareResyncTask(replicationTrigger, listener, replicaEntry, masterEntry); } // Entries are synchronized so allow both cursors to advance. if (replicaCursor == null) { replicaCursor = replicaQuery.fetchAfter(replicaEntry); } lastReplicaEntry = replicaEntry; replicaEntry = null; masterEntry = null; } if (resyncTask != null) { txnCount++; resyncTask.run(); } } } finally { try { if (masterCursor != null) { masterCursor.close(); } } finally { if (replicaCursor != null) { replicaCursor.close(); } } } }
From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java
/** * Internal method to update a module./* w w w . j a v a 2s .co m*/ */ protected HotBeanModuleInfo updateModuleInternal(String moduleName, final InputStream moduleFileStream, final boolean add) { long revisionNumber = -1; HotBeanModuleInfo hotBeanModuleInfo = null; Log logger = this.getLog(); synchronized (super.getLock()) { // If update - module name must be specified if (!add && ((moduleName == null) || (moduleName.trim().length() == 0))) throw new HotBeansException("Module name not specified!"); RepositoryFileLock fileLock = null; File moduleTempFile = null; InputStream moduleTempFileStream = null; try { // Save module file to temp file moduleTempFile = File.createTempFile("hotBeanModule", ".jar"); FileCopyUtils.copy(moduleFileStream, new FileOutputStream(moduleTempFile)); // Get name from mainfest Manifest manifest = ModuleManifestUtils.readManifest(moduleTempFile); String jarFileModuleName = ModuleManifestUtils.getName(manifest); if (logger.isDebugEnabled()) logger.debug("Module name in module manifest: '" + jarFileModuleName + "'."); // Validate name if (add) { if ((jarFileModuleName == null) || (jarFileModuleName.trim().length() == 0)) throw new InvalidModuleNameException("Module name not specified!"); else if (super.getHotBeanModule(jarFileModuleName) != null) throw new ModuleAlreadyExistsException("Module name already exists!"); } else if (!moduleName.equals(jarFileModuleName)) throw new InvalidModuleNameException( "Module name in jar file doesn't match specified module name!"); moduleName = jarFileModuleName; moduleTempFileStream = new FileInputStream(moduleTempFile); if (add & logger.isInfoEnabled()) logger.info("Adding module '" + moduleName + "'."); fileLock = this.obtainRepositoryFileLock(false); // Obtain lock File moduleDirectory = new File(this.moduleRepositoryDirectory, moduleName); if (!moduleDirectory.exists()) moduleDirectory.mkdirs(); // Get next revision number revisionNumber = this.getLastRevisionOnFileSystem(moduleName); if (logger.isDebugEnabled()) { if (add) logger.debug("Adding module - last revision on file system: " + revisionNumber + "."); else logger.debug("Updating module - last revision on file system: " + revisionNumber + "."); } if (revisionNumber < 0) revisionNumber = 0; File moduleFile = new File(moduleDirectory, revisionNumber + MODULE_FILE_SUFFIX); while (moduleFile.exists()) // This should't really be necessary, but still... { revisionNumber++; moduleFile = new File(moduleDirectory, revisionNumber + MODULE_FILE_SUFFIX); } if (logger.isDebugEnabled()) { if (add) logger.debug("Adding module - revision of new module: " + revisionNumber + "."); else logger.debug("Updating module - revision of new module: " + revisionNumber + "."); } // Save module file FileCopyUtils.copy(moduleTempFileStream, new FileOutputStream(moduleFile)); // Deploy at once hotBeanModuleInfo = this.loadModule(moduleName, revisionNumber); } catch (Exception e) { String moduleNameString = ""; if (moduleName != null) moduleNameString = "'" + moduleName + "' "; if (add) { logger.error("Error adding module " + moduleNameString + "- " + e, e); if (e instanceof HotBeansException) throw (HotBeansException) e; else throw new HotBeansException("Error adding module " + moduleNameString + "- " + e, e); } else { logger.error("Error updating module " + moduleNameString + "- " + e, e); if (e instanceof HotBeansException) throw (HotBeansException) e; else throw new HotBeansException("Error updating module " + moduleNameString + "- " + e, e); } } finally { this.releaseRepositoryFileLock(fileLock); fileLock = null; if (moduleTempFileStream != null) { // Delete temp file try { moduleTempFileStream.close(); } catch (Exception e) { } } if (moduleTempFile != null) FileDeletor.delete(moduleTempFile); } } return hotBeanModuleInfo; }
From source file:net.sourceforge.eclipsetrader.charts.ChartsPlugin.java
public static void saveDefaultChart(Chart chart) { Log logger = LogFactory.getLog(ChartsPlugin.class); SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); //$NON-NLS-1$ try {// w w w .j a va 2 s. co m DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.getDOMImplementation().createDocument(null, "chart", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); Element node = document.createElement("title"); //$NON-NLS-1$ node.appendChild(document.createTextNode(chart.getTitle())); root.appendChild(node); node = document.createElement("compression"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(chart.getCompression()))); root.appendChild(node); node = document.createElement("period"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(chart.getPeriod()))); root.appendChild(node); node = document.createElement("autoScale"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(chart.isAutoScale()))); root.appendChild(node); if (chart.getBeginDate() != null) { node = document.createElement("begin"); //$NON-NLS-1$ node.appendChild(document.createTextNode(dateTimeFormat.format(chart.getBeginDate()))); root.appendChild(node); } if (chart.getEndDate() != null) { node = document.createElement("end"); //$NON-NLS-1$ node.appendChild(document.createTextNode(dateTimeFormat.format(chart.getEndDate()))); root.appendChild(node); } for (int r = 0; r < chart.getRows().size(); r++) { ChartRow row = (ChartRow) chart.getRows().get(r); row.setId(new Integer(r)); Element rowNode = document.createElement("row"); //$NON-NLS-1$ root.appendChild(rowNode); for (int t = 0; t < row.getTabs().size(); t++) { ChartTab tab = (ChartTab) row.getTabs().get(t); tab.setId(new Integer(t)); Element tabNode = document.createElement("tab"); //$NON-NLS-1$ tabNode.setAttribute("label", tab.getLabel()); //$NON-NLS-1$ rowNode.appendChild(tabNode); for (int i = 0; i < tab.getIndicators().size(); i++) { ChartIndicator indicator = (ChartIndicator) tab.getIndicators().get(i); indicator.setId(new Integer(i)); Element indicatorNode = document.createElement("indicator"); //$NON-NLS-1$ indicatorNode.setAttribute("pluginId", indicator.getPluginId()); //$NON-NLS-1$ tabNode.appendChild(indicatorNode); for (Iterator iter = indicator.getParameters().keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); node = document.createElement("param"); //$NON-NLS-1$ node.setAttribute("key", key); //$NON-NLS-1$ node.setAttribute("value", (String) indicator.getParameters().get(key)); //$NON-NLS-1$ indicatorNode.appendChild(node); } } for (int i = 0; i < tab.getObjects().size(); i++) { ChartObject object = (ChartObject) tab.getObjects().get(i); object.setId(new Integer(i)); Element indicatorNode = document.createElement("object"); //$NON-NLS-1$ indicatorNode.setAttribute("pluginId", object.getPluginId()); //$NON-NLS-1$ tabNode.appendChild(indicatorNode); for (Iterator iter = object.getParameters().keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); node = document.createElement("param"); //$NON-NLS-1$ node.setAttribute("key", key); //$NON-NLS-1$ node.setAttribute("value", (String) object.getParameters().get(key)); //$NON-NLS-1$ indicatorNode.appendChild(node); } } } } TransformerFactory factory = TransformerFactory.newInstance(); try { factory.setAttribute("indent-number", new Integer(4)); //$NON-NLS-1$ } catch (Exception e) { } Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); //$NON-NLS-1$ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ transformer.setOutputProperty("{http\u003a//xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$ DOMSource source = new DOMSource(document); File file = ChartsPlugin.getDefault().getStateLocation().append("defaultChart.xml").toFile(); //$NON-NLS-1$ BufferedWriter out = new BufferedWriter(new FileWriter(file)); StreamResult result = new StreamResult(out); transformer.transform(source, result); out.flush(); out.close(); } catch (Exception e) { logger.error(e.toString(), e); } }
From source file:net.sourceforge.eclipsetrader.charts.ChartsPlugin.java
public static Chart createDefaultChart() { Log logger = LogFactory.getLog(ChartsPlugin.class); SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); //$NON-NLS-1$ Chart chart = new Chart(); File file = ChartsPlugin.getDefault().getStateLocation().append("defaultChart.xml").toFile(); //$NON-NLS-1$ if (file.exists() == true) { try {/*from w ww .ja v a2s. c o m*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(file); NodeList firstNode = document.getFirstChild().getChildNodes(); for (int r = 0; r < firstNode.getLength(); r++) { Node item = firstNode.item(r); Node valueNode = item.getFirstChild(); String nodeName = item.getNodeName(); if (valueNode != null) { if (nodeName.equalsIgnoreCase("compression") == true) //$NON-NLS-1$ chart.setCompression(Integer.parseInt(valueNode.getNodeValue())); else if (nodeName.equalsIgnoreCase("period") == true) //$NON-NLS-1$ chart.setPeriod(Integer.parseInt(valueNode.getNodeValue())); else if (nodeName.equalsIgnoreCase("autoScale") == true) //$NON-NLS-1$ chart.setAutoScale(new Boolean(valueNode.getNodeValue()).booleanValue()); else if (nodeName.equalsIgnoreCase("begin") == true) //$NON-NLS-1$ { try { chart.setBeginDate(dateTimeFormat.parse(valueNode.getNodeValue())); } catch (Exception e) { logger.warn(e.toString()); } } else if (nodeName.equalsIgnoreCase("end") == true) //$NON-NLS-1$ { try { chart.setEndDate(dateTimeFormat.parse(valueNode.getNodeValue())); } catch (Exception e) { logger.warn(e.toString()); } } } if (nodeName.equalsIgnoreCase("row")) //$NON-NLS-1$ { ChartRow row = new ChartRow(new Integer(r)); row.setParent(chart); NodeList tabList = item.getChildNodes(); for (int t = 0; t < tabList.getLength(); t++) { item = tabList.item(t); nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("tab")) //$NON-NLS-1$ { ChartTab tab = new ChartTab(new Integer(t)); tab.setParent(row); tab.setLabel(((Node) item).getAttributes().getNamedItem("label").getNodeValue()); //$NON-NLS-1$ NodeList indicatorList = item.getChildNodes(); for (int i = 0; i < indicatorList.getLength(); i++) { item = indicatorList.item(i); nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("indicator")) //$NON-NLS-1$ { ChartIndicator indicator = new ChartIndicator(new Integer(i)); indicator.setParent(tab); indicator.setPluginId(((Node) item).getAttributes().getNamedItem("pluginId") //$NON-NLS-1$ .getNodeValue()); NodeList parametersList = item.getChildNodes(); for (int p = 0; p < parametersList.getLength(); p++) { item = parametersList.item(p); nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("param")) //$NON-NLS-1$ { String key = ((Node) item).getAttributes().getNamedItem("key") //$NON-NLS-1$ .getNodeValue(); String value = ((Node) item).getAttributes().getNamedItem("value") //$NON-NLS-1$ .getNodeValue(); indicator.getParameters().put(key, value); } } tab.getIndicators().add(indicator); } else if (nodeName.equalsIgnoreCase("object")) //$NON-NLS-1$ { ChartObject object = new ChartObject(new Integer(i)); object.setParent(tab); object.setPluginId(((Node) item).getAttributes().getNamedItem("pluginId") //$NON-NLS-1$ .getNodeValue()); NodeList parametersList = item.getChildNodes(); for (int p = 0; p < parametersList.getLength(); p++) { item = parametersList.item(p); nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("param")) //$NON-NLS-1$ { String key = ((Node) item).getAttributes().getNamedItem("key") //$NON-NLS-1$ .getNodeValue(); String value = ((Node) item).getAttributes().getNamedItem("value") //$NON-NLS-1$ .getNodeValue(); object.getParameters().put(key, value); } } tab.getObjects().add(object); } } row.getTabs().add(tab); } } chart.getRows().add(row); } } } catch (Exception e) { logger.error(e.toString(), e); } } chart.clearChanged(); return chart; }
From source file:byps.test.TestUtils.java
@SuppressWarnings("rawtypes") public static void internalAssertEquals(Log log, String msg, Object a, Object b, Set<Object> alreadyCheckedObjs) { if (a != null) { if (alreadyCheckedObjs.contains(a)) return; alreadyCheckedObjs.add(a);/*from ww w . java 2 s . c o m*/ } if (b instanceof Date) { if (a == null) { a = new Date(0); } } try { if (a != b) { if (a == null && b != null) { if (!(b instanceof String)) { throw new AssertionError(msg + " a is null <> b is {" + b + "}"); } } else if (a != null && b == null) { if (!(a instanceof String)) { throw new AssertionError(msg + " a is {" + a + "} <> b is null"); } } else if (a instanceof boolean[]) { boolean[] x = (boolean[]) a; boolean[] y = (boolean[]) b; if (x.length != y.length) { throw new AssertionError(msg + " a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof byte[]) { byte[] x = (byte[]) a; byte[] y = (byte[]) b; if (x.length != y.length) { throw new AssertionError(msg + " a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof char[]) { char[] x = (char[]) a; char[] y = (char[]) b; if (x.length != y.length) { throw new AssertionError(msg + " a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof short[]) { short[] x = (short[]) a; short[] y = (short[]) b; if (x.length != y.length) { throw new AssertionError(msg + " a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof int[]) { int[] x = (int[]) a; int[] y = (int[]) b; if (x.length != y.length) { throw new AssertionError(msg + "a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof long[]) { long[] x = (long[]) a; long[] y = (long[]) b; if (x.length != y.length) { throw new AssertionError(msg + "a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof float[]) { float[] x = (float[]) a; float[] y = (float[]) b; if (x.length != y.length) { throw new AssertionError(msg + "a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof double[]) { double[] x = (double[]) a; double[] y = (double[]) b; if (x.length != y.length) { throw new AssertionError(msg + "a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof String[]) { String[] x = (String[]) a; String[] y = (String[]) b; if (x.length != y.length) { throw new AssertionError(msg + " a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof Object[]) { Object[] x = (Object[]) a; Object[] y = (Object[]) b; if (x.length != y.length) { throw new AssertionError(msg + "a[].length != b[].length"); } for (int i = 0; i < x.length; i++) { internalAssertEquals(log, msg + "[" + i + "]", x[i], y[i], alreadyCheckedObjs); } } else if (a instanceof List) { List x = (List) a; List y = (List) b; if (x.size() != y.size()) { throw new AssertionError(msg + "a[].length != b[].length"); } for (int i = 0; i < x.size(); i++) { internalAssertEquals(log, msg + "[" + i + "]", x.get(i), y.get(i), alreadyCheckedObjs); } } else if (a instanceof Set) { Set x = (Set) a; Set y = (Set) b; if (x.size() != y.size()) { throw new AssertionError(msg + "a[].length != b[].length"); } for (Iterator i = x.iterator(); i.hasNext();) { Object v = i.next(); if (y.contains(v)) continue; if (v.getClass() == PrimitiveTypes.class) { boolean found = false; for (Iterator j = y.iterator(); j.hasNext();) { found = compare((PrimitiveTypes) v, (PrimitiveTypes) j.next()); if (found) break; } Assert.assertTrue(msg + "[" + v + "] is missing", found); continue; } if (v.getClass() == Actor.class) { boolean found = false; for (Iterator j = y.iterator(); j.hasNext();) { found = compare((Actor) v, (Actor) j.next()); if (found) break; } Assert.assertTrue(msg + "[" + v + "] is missing", found); continue; } Assert.assertTrue(msg + "[" + v + "] is missing", y.contains(v)); } } else if (a instanceof Map) { Map x = (Map) a; Map y = (Map) b; if (x.size() != y.size()) { throw new AssertionError(msg + " a[].length != b[].length"); } for (Iterator i = x.keySet().iterator(); i.hasNext();) { Object k = i.next(); internalAssertEquals(log, msg + "[" + k + "]", x.get(k), y.get(k), alreadyCheckedObjs); } } else if (a instanceof InputStream) { // geht nicht, stream a wurde in BWire.putStream geschlossen } else if (a instanceof ByteBuffer) { ByteBuffer x = (ByteBuffer) a; ByteBuffer y = (ByteBuffer) b; Assert.assertEquals("ByteBuffer.remaining", x.remaining(), y.remaining()); for (int i = 0; i < x.remaining(); i++) { Assert.assertEquals("ByteBuffer.get(" + i + ")", x.get(), y.get()); } } else { Class<?> classA = a.getClass(); Class<?> classB = b.getClass(); if (classA != classB) { throw new AssertionError("different class"); } try { Class<?> clazz = classA; if (clazz == Boolean.class || clazz == Byte.class || clazz == Character.class || clazz == Short.class || clazz == Integer.class || clazz == Long.class || clazz == Float.class || clazz == Double.class || clazz == Date.class || clazz == String.class) { Assert.assertEquals(msg, a, b); } else if (clazz == Date.class) { assertEqualDates(log, msg, (Date) a, (Date) b); } else if (clazz == PrimitiveTypes.class) { if (!compare((PrimitiveTypes) a, (PrimitiveTypes) b)) { throw new AssertionError("different objects"); } } else if (clazz == Actor.class) { if (!compare((Actor) a, (Actor) b)) { throw new AssertionError("different objects"); } } else { for (Field f : clazz.getDeclaredFields()) { f.setAccessible(true); internalAssertEquals(log, msg + "." + f.getName(), f.get(a), f.get(b), alreadyCheckedObjs); } } } catch (IllegalAccessException e) { throw new AssertionError(e); } } } String astr = a != null ? a.toString() : null; String bstr = b != null ? b.toString() : null; if (astr != null && astr.length() > 100) astr = astr.substring(0, 100); if (bstr != null && bstr.length() > 100) bstr = bstr.substring(0, 100); if (log != null) log.info("assertEquals: " + msg + ", a=" + astr + ", b=" + bstr + ", true"); } catch (AssertionError e) { log.error("assertEquals: " + msg + ", a=" + a + ", b=" + b + ", false", e); throw e; } }
From source file:net.sourceforge.vulcan.spring.SpringEventHandler.java
private void logErrorEvent(ErrorEvent event) { Log log = LogFactory.getLog(event.getSource().getClass()); log.error(appCtx.getMessage(event.getKey(), event.getArgs(), null), event.getError()); }