All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javolution.xml.XMLContext Maven / Gradle / Ivy

Go to download

Only the Java Core part of Javolution library, with slight modifications for use in MSFTBX.

There is a newer version: 6.11.8
Show newest version
/*
 * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
 * Copyright (C) 2012 - Javolution (http://javolution.org/)
 * All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute this software is
 * freely granted, provided that this notice is preserved.
 */
package javolution.xml;

import javolution.context.AbstractContext;
import javolution.context.FormatContext;
import javolution.osgi.internal.OSGiServices;
import javolution.text.TextFormat;

/**
 * 

A context for XML parsing/formatting. This context provides * the {@link javolution.xml.XMLFormat XMLFormat} to parse/format objects * of any class. If not superseded, the XML format for a class is specified * by the {@link javolution.xml.DefaultXMLFormat DefaultXMLFormat} * annotation.

*

A XML context always returns the most specialized format. If a class * has no default format annotation (inherited or not), then the default * {@link java.lang.Object} format (with "value" attribute is * parsed/formatted using {@link javolution.text.TextContext current * text format}) is returned. * A predefined format exists for the following standard types: *

    *
  • java.lang.Object (attribute "value" parsed/formatted using {@link TextFormat})
  • *
  • java.util.Collection
  • *
  • java.util.Map
  • *
*

* * @author Jean-Marie Dautelle * @version 6.0 December 12, 2012 */ public abstract class XMLContext extends FormatContext { /** * Default constructor. */ protected XMLContext() {} /** * Enters and returns a new xml context instance. */ public static XMLContext enter() { return (XMLContext) XMLContext.currentXMLContext().enterInner(); } /** * Returns the xml format for the specified type; if none defined * the default object xml format (based on {@link TextFormat}) is returned. */ public static XMLFormat getFormat(Class type) { return XMLContext.currentXMLContext().searchFormat(type); } /** * Sets the xml format for the specified type (and its sub-types). */ public abstract void setFormat(Class type, XMLFormat format); /** * Searches the xml format for the specified type. */ protected abstract XMLFormat searchFormat( Class type); /** * Returns the current xml context. */ private static XMLContext currentXMLContext() { XMLContext ctx = AbstractContext.current(XMLContext.class); if (ctx != null) return ctx; return OSGiServices.getXMLContext(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy