Java Code Examples for org.jfree.util.Log#warn()

The following examples show how to use org.jfree.util.Log#warn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyFileConfiguration.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads the properties stored in the given file. This method does nothing if
 * the file does not exist or is unreadable. Appends the contents of the loaded
 * properties to the already stored contents.
 *
 * @param in the input stream used to read the properties.
 */
public void load(final InputStream in)
{
  if (in == null)
  {
    throw new NullPointerException();
  }

  try
  {
    final BufferedInputStream bin = new BufferedInputStream(in);
    final Properties p = new Properties();
    p.load(bin);
    this.getConfiguration().putAll(p);
    bin.close();
  }
  catch (IOException ioe)
  {
    Log.warn("Unable to read configuration", ioe);
  }

}
 
Example 2
Source File: AbstractXmlReadHandler.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method is called at the start of an element.
 *
 * @param tagName  the tag name.
 * @param attrs  the attributes.
 *
 * @throws SAXException if there is a parsing error.
 * @throws XmlReaderException if there is a reader error.
 */
public final void startElement(final String tagName, final Attributes attrs)
    throws XmlReaderException, SAXException {
    if (this.firstCall) {
        if (!this.tagName.equals(tagName)) {
            throw new SAXException("Expected <" + this.tagName + ">, found <" + tagName + ">");
        }
        this.firstCall = false;
        startParsing(attrs);
    }
    else {
        final XmlReadHandler childHandler = getHandlerForChild(tagName, attrs);
        if (childHandler == null) {
            Log.warn ("Unknown tag <" + tagName + ">");
            return;
        }
        childHandler.init(getRootHandler(), tagName);
        this.rootHandler.recurse(childHandler, tagName, attrs);
    }
}
 
Example 3
Source File: URLObjectDescription.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the parameters of this description object to match the supplied object.
 *
 * @param o  the object (should be an instance of <code>URL</code>).
 *
 * @throws ObjectFactoryException if the object is not an instance of <code>URL</code>.
 */
public void setParameterFromObject(final Object o) throws ObjectFactoryException {
    if (!(o instanceof URL)) {
        throw new ObjectFactoryException("Is no instance of java.net.URL");
    }

    final URL comp = (URL) o;
    final String baseURL = getConfig().getConfigProperty(Parser.CONTENTBASE_KEY);
    try {
        final URL bURL = new URL(baseURL);
        setParameter("value", IOUtils.getInstance().createRelativeURL(comp, bURL));
    }
    catch (Exception e) {
        Log.warn("BaseURL is invalid: ", e);
    }
    setParameter("value", comp.toExternalForm());
}
 
Example 4
Source File: CollectionObjectDescription.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates an object based on the description.
 *
 * @return The object.
 */
public Object createObject() {
    try {
        final Collection l = (Collection) getObjectClass().newInstance();
        int counter = 0;
        while (getParameterDefinition(String.valueOf(counter)) != null) {
            final Object value = getParameter(String.valueOf(counter));
            if (value == null) {
                break;
            }

            l.add(value);
            counter += 1;
        }
        return l;
    }
    catch (Exception ie) {
        Log.warn("Unable to instantiate Object", ie);
        return null;
    }
}
 
Example 5
Source File: AbstractModelReader.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads the given class, and ignores all exceptions which may occur
 * during the loading. If the class was invalid, null is returned instead.
 *
 * @param className the name of the class to be loaded.
 * @return the class or null.
 */
protected Class loadClass(final String className) {
    if (className == null) {
        return null;
    }
    if (className.startsWith("::")) {
        return BasicTypeSupport.getClassRepresentation(className);
    }
    try {
        return ObjectUtilities.getClassLoader(getClass()).loadClass(className);
    }
    catch (Exception e) {
        // ignore buggy classes for now ..
        Log.warn("Unable to load class", e);
        return null;
    }
}
 
Example 6
Source File: ObjectFactoryLoader.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Starts a object definition. The object definition collects all properties of
 * an bean-class and defines, which constructor should be used when creating the
 * class.
 *
 * @param className the class name of the defined object
 * @param register the (optional) register name, to lookup and reference the object later.
 * @param ignore  ignore?
 * 
 * @return true, if the definition was accepted, false otherwise.
 * @throws ObjectDescriptionException if an unexpected error occured.
 */
protected boolean startObjectDefinition(final String className, final String register, final boolean ignore)
    throws ObjectDescriptionException {

    if (ignore) {
        return false;
    }
    this.target = loadClass(className);
    if (this.target == null) {
        Log.warn(new Log.SimpleMessage("Failed to load class ", className));
        return false;
    }
    this.registerName = register;
    this.propertyDefinition = new ArrayList();
    this.attributeDefinition = new ArrayList();
    this.constructorDefinition = new ArrayList();
    this.lookupDefinitions = new ArrayList();
    this.orderedNames = new ArrayList();
    return true;
}
 
Example 7
Source File: PackageState.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Configures the module and raises the state to STATE_CONFIGURED if the
 * module is not yet configured.
 *
 * @param subSystem  the sub-system.
 * 
 * @return true, if the module was configured, false otherwise.
 */
public boolean configure(final SubSystem subSystem)
{
  if (this.state == STATE_NEW)
  {
    try
    {
      this.module.configure(subSystem);
      this.state = STATE_CONFIGURED;
      return true;
    }
    catch (NoClassDefFoundError noClassDef)
    {
      Log.warn (new Log.SimpleMessage("Unable to load module classes for ",
              this.module.getName(), ":", noClassDef.getMessage()));
      this.state = STATE_ERROR;
    }
    catch (Exception e)
    {
      if (Log.isDebugEnabled())
      {
        // its still worth a warning, but now we are more verbose ...
        Log.warn("Unable to configure the module " + this.module.getName(), e);
      }
      else if (Log.isWarningEnabled())
      {
        Log.warn("Unable to configure the module " + this.module.getName());
      }
      this.state = STATE_ERROR;
    }
  }
  return false;
}
 
Example 8
Source File: JavaSourceCollector.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads a class by its fully qualified name.
 * 
 * @param name  the class name.
 * 
 * @return The class (or <code>null</code> if there was a problem loading the class).
 */
protected Class loadClass(final String name) {
    try {
        return ObjectUtilities.getClassLoader(JavaSourceCollector.class).loadClass(name);
    }
    catch (Exception e) {
        Log.warn (new Log.SimpleMessage("Do not process: Failed to load class:", name));
        return null;
    }
}
 
Example 9
Source File: AbstractModelReader.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parses the given specification and loads all includes specified in the files.
 * This implementation does not check for loops in the include files.
 *
 * @param resource  the url of the xml specification.
 * @param isInclude  an include?
 * 
 * @throws org.jfree.xml.util.ObjectDescriptionException if an error occured which prevented the
 * loading of the specifications.
 */
protected void parseXmlDocument(final URL resource, final boolean isInclude)
    throws ObjectDescriptionException {
    
    try {
        final InputStream in = new BufferedInputStream(resource.openStream());
        final SAXParserFactory factory = SAXParserFactory.newInstance();
        final SAXParser saxParser = factory.newSAXParser();
        final XMLReader reader = saxParser.getXMLReader();

        final SAXModelHandler handler = new SAXModelHandler(resource, isInclude);
        try {
            reader.setProperty
                ("http://xml.org/sax/properties/lexical-handler",
                    getCommentHandler());
        }
        catch (SAXException se) {
            Log.debug("Comments are not supported by this SAX implementation.");
        }
        reader.setContentHandler(handler);
        reader.setDTDHandler(handler);
        reader.setErrorHandler(handler);
        reader.parse(new InputSource(in));
        in.close();
    }
    catch (Exception e) {
        // unable to init
        Log.warn("Unable to load factory specifications", e);
        throw new ObjectDescriptionException("Unable to load object factory specs.", e);
    }
}
 
Example 10
Source File: ReadTestCaseExecutionMedia.java    From cerberus-source with GNU General Public License v3.0 5 votes vote down vote up
private void returnPDF(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) {

        File pdfFile = null;
        filePath = StringUtil.addSuffixIfNotAlready(filePath, File.separator);
        pdfFile = new File(filePath + tc.getFileName());
        response.setContentType("application/pdf");
        response.setContentLength((int) pdfFile.length());
        try {
            Files.copy(pdfFile, response.getOutputStream());
        } catch (IOException e) {
            Log.warn(e);
        }

    }
 
Example 11
Source File: ReadTestCaseExecutionMedia.java    From cerberus-source with GNU General Public License v3.0 5 votes vote down vote up
private void returnMP4(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) {

        File mp4File = null;
        filePath = StringUtil.addSuffixIfNotAlready(filePath, File.separator);
        mp4File = new File(filePath + tc.getFileName());
        response.setContentType("video/mp4");
        response.setContentLength((int) mp4File.length());
        response.setHeader("Content-Range",  "bytes start-end/length");
        try {
            Files.copy(mp4File, response.getOutputStream());
        } catch (IOException e) {
            Log.warn(e);
        }

    }
 
Example 12
Source File: XmlUtil.java    From cerberus-source with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a {@link Document} from the given {@link Node}
 *
 * @param node to transform to {@link Document}
 * @return a {@link Document} from the given {@link Node}
 * @throws XmlUtilException if an error occurs
 */
public static Document fromNode(Node node) throws XmlUtilException {
    try {
        Document document = XmlUtil.newDocument();
        document.appendChild(document.adoptNode(node.cloneNode(true)));
        return document;
    } catch (DOMException e) {
        Log.warn("Unable to create document from node " + node, e);
        return null;
    }
}
 
Example 13
Source File: PackageState.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initializes the contained module and raises the set of the module to
 * STATE_INITIALIZED, if the module was not yet initialized. In case of an
 * error, the module state will be set to STATE_ERROR and the module will
 * not be available.
 *
 * @param subSystem  the sub-system.
 * 
 * @return true, if the module was successfully initialized, false otherwise.
 */
public boolean initialize(final SubSystem subSystem)
{
  if (this.state == STATE_CONFIGURED)
  {
    try
    {
        this.module.initialize(subSystem);
        this.state = STATE_INITIALIZED;
        return true;
    }
    catch (NoClassDefFoundError noClassDef)
    {
      Log.warn (new Log.SimpleMessage("Unable to load module classes for ",
              this.module.getName(), ":", noClassDef.getMessage()));
      this.state = STATE_ERROR;
    }
    catch (ModuleInitializeException me)
    {
      if (Log.isDebugEnabled())
      {
        // its still worth a warning, but now we are more verbose ...
        Log.warn("Unable to initialize the module " + this.module.getName(), me);
      }
      else if (Log.isWarningEnabled())
      {
        Log.warn("Unable to initialize the module " + this.module.getName());
      }
      this.state = STATE_ERROR;
    }
    catch (Exception e)
    {
      if (Log.isDebugEnabled())
      {
        // its still worth a warning, but now we are more verbose ...
        Log.warn("Unable to initialize the module " + this.module.getName(), e);
      }
      else if (Log.isWarningEnabled())
      {
        Log.warn("Unable to initialize the module " + this.module.getName());
      }
      this.state = STATE_ERROR;
    }
  }
  return false;
}
 
Example 14
Source File: GenericWriteHandler.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Performs the writing of a generic object.
 *
 * @param tagName  the tag name.
 * @param object  the generic object.
 * @param writer  the writer.
 * @param mPlexAttribute  ??.
 * @param mPlexValue  ??.
 * 
 * @throws IOException if there is an I/O error.
 * @throws XMLWriterException if there is a writer error.
 */
public void write(final String tagName, final Object object, final XMLWriter writer,
                  final String mPlexAttribute, final String mPlexValue)
    throws IOException, XMLWriterException {

    try {
        this.factory.readProperties(object);

        final AttributeList attributes = new AttributeList();
        if (mPlexAttribute != null) {
            attributes.setAttribute(mPlexAttribute, mPlexValue);
        }
        final AttributeDefinition[] attribDefs = this.factory.getAttributeDefinitions();
        final ArrayList properties = new ArrayList();
        for (int i = 0; i < attribDefs.length; i++) {
            final AttributeDefinition adef = attribDefs[i];
            final String pName = adef.getAttributeName();
            final Object propValue = this.factory.getProperty(adef.getPropertyName());
            if (propValue != null) {
                Log.debug(
                    "Here: " + this.factory.getBaseClass() + " -> " + adef.getPropertyName()
                );
                final String value = adef.getHandler().toAttributeValue(propValue);
                if (value != null) {
                    attributes.setAttribute(pName, value);
                }
            }
            properties.add(adef.getPropertyName());
        }
        writer.writeTag(tagName, attributes, false);
        writer.startBlock();

        final PropertyDefinition[] propertyDefs = this.factory.getPropertyDefinitions();
        final RootXmlWriteHandler rootHandler = getRootHandler();
        for (int i = 0; i < propertyDefs.length; i++) {
            final PropertyDefinition pDef = propertyDefs[i];
            final String elementName = pDef.getElementName();
            rootHandler.write
                (elementName, this.factory.getProperty(pDef.getPropertyName()),
                        this.factory.getTypeForTagName(elementName), writer);
        }
        writer.endBlock();
        writer.writeCloseTag(tagName);
    }
    catch (ObjectDescriptionException ode) {
        Log.warn ("Unable to write element", ode);
        throw new IOException(ode.getMessage());
    }
}
 
Example 15
Source File: CSVFileReader.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public DataRowReader getDataRowReader(final List<Attribute> attributeList) throws IOException {
	DataRowReader dataRowReader = new DataRowReader() {

		private Iterator<String[]> iterator = getDataReader();

		private int columnCount = attributeList.size();

		private Attribute[] attributes = new Attribute[columnCount];
		{
			attributes = attributeList.toArray(attributes);
		}

		@Override
		public boolean hasNext() {
			return iterator.hasNext();
		}

		@Override
		public DataRow next() {
			String[] valueLine = iterator.next();
			double[] values = new double[columnCount];
			for (int i = 0; i < columnCount; i++) {
				values[i] = Double.NaN;
			}
			for (int i = 0; i < valueLine.length; i++) {
				if (i >= valueLine.length) {
					Log.warn("Metadata was not correctly specified.");
					continue;
				}
				if (valueLine[i] == null || valueLine[i].isEmpty()) {
					continue;
				}
				if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(attributes[i].getValueType(), Ontology.NUMERICAL)) {
					try {
						values[i] = numberFormat.parse(valueLine[i]).doubleValue();
					} catch (ParseException e) {
						System.err.println("cannot parse");
					}
					continue;
				}
				if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(attributes[i].getValueType(), Ontology.NOMINAL)) {
					values[i] = attributes[i].getMapping().mapString(valueLine[i]);
					continue;
				}
			}
			return new DoubleArrayDataRow(values);
		}

		@Override
		public void remove() {
			throw new UnsupportedOperationException("Can not remove data rows from reader.");
		}
	};
	return dataRowReader;
}