Javolution 6.0.0 java
javolution.xml.internal.XMLContextImpl Class Reference
Inheritance diagram for javolution.xml.internal.XMLContextImpl:
[legend]
Collaboration diagram for javolution.xml.internal.XMLContextImpl:
[legend]

Public Member Functions

void exit ()
 

Static Public Member Functions

static XMLContext enter ()
 
static< T extends AbstractContext > T enter (Class< T > custom)
 
static< T > XMLFormat< T > getFormat (Class<? extends T > type)
 
static AbstractContext current ()
 
static void inherit (AbstractContext ctx)
 

Protected Member Functions

XMLContext inner ()
 
AbstractContext enterInner ()
 
AbstractContext getOuter ()
 

Static Protected Member Functions

static< T extends AbstractContext > T current (Class< T > type)
 

Package Functions

protected< T > XMLFormat< T > searchFormat (Class<? extends T > type)
 
public< T > void setFormat (Class<? extends T > type, XMLFormat< T > format)
 

Static Private Member Functions

static XMLContext currentXMLContext ()
 

Private Attributes

final FastMap< Class<?>, XMLFormat<?> > formats = new FastMap<Class<?>, XMLFormat<?>>()
 
AbstractContext outer
 

Static Private Attributes

static final XMLFormat OBJECT_XML = new XMLFormat.Default()
 
static final XMLFormat COLLECTION_XML
 
static final XMLFormat MAP_XML
 
static final ThreadLocal< AbstractContextCURRENT = new ThreadLocal<AbstractContext>()
 

Detailed Description

Holds the default implementation of XMLContext.

Author
Jean-Marie Dautelle
Version
6.0, July 21, 2013

Definition at line 28 of file XMLContextImpl.java.

Member Function Documentation

◆ current() [1/2]

static AbstractContext javolution.context.AbstractContext.current ( )
staticinherited

Returns the current context for the current thread or

null

if this thread has no context (default).

Definition at line 61 of file AbstractContext.java.

61  {
62  return AbstractContext.CURRENT.get();
63  }

References javolution.context.AbstractContext.CURRENT.

Referenced by javolution.context.LogContext.currentLogContext(), javolution.context.SecurityContext.currentSecurityContext(), javolution.text.TextContext.currentTextContext(), javolution.xml.XMLContext.currentXMLContext(), javolution.context.LocalContext.enter(), javolution.context.ConcurrentContext.enter(), and javolution.context.LocalContext.Parameter< T >.get().

Here is the caller graph for this function:

◆ current() [2/2]

static <T extends AbstractContext> T javolution.context.AbstractContext.current ( Class< T >  type)
staticprotectedinherited

Returns the current context of specified type or

null

if none.

Definition at line 69 of file AbstractContext.java.

69  {
70  AbstractContext ctx = AbstractContext.CURRENT.get();
71  while (ctx != null) {
72  if (type.isInstance(ctx))
73  return (T) ctx;
74  ctx = ctx.outer;
75  }
76  return null;
77  }

References javolution.context.AbstractContext.CURRENT, and javolution.context.AbstractContext.outer.

◆ currentXMLContext()

static XMLContext javolution.xml.XMLContext.currentXMLContext ( )
staticprivateinherited

Returns the current xml context.

Definition at line 68 of file XMLContext.java.

68  {
69  XMLContext ctx = AbstractContext.current(XMLContext.class);
70  if (ctx != null)
71  return ctx;
72  return OSGiServices.getXMLContext();
73  }

References javolution.context.AbstractContext.current(), and javolution.osgi.internal.OSGiServices.getXMLContext().

Referenced by javolution.xml.XMLContext.enter(), and javolution.xml.XMLContext.getFormat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter() [1/2]

static XMLContext javolution.xml.XMLContext.enter ( )
staticinherited

Enters and returns a new xml context instance.

Definition at line 41 of file XMLContext.java.

41  {
42  return (XMLContext) XMLContext.currentXMLContext().enterInner();
43  }

References javolution.xml.XMLContext.currentXMLContext(), and javolution.context.AbstractContext.enterInner().

Here is the call graph for this function:

◆ enter() [2/2]

static <T extends AbstractContext> T javolution.context.AbstractContext.enter ( Class< T >  custom)
staticinherited

Enters the scope of a custom context. This method raises a SecurityException if the permission to enter contexts of the specified class is not granted. For example, the following disallow entering any custom context. [code] SecurityContext ctx = SecurityContext.enter(); try { ctx.revoke(new SecurityContext.Permission(AbstractContext.class, "enter")); ... // Cannot enter any custom context. } finally { ctx.exit(); // Back to previous security settings. }[/code]


Parameters
customthe custom context to enter.
Exceptions
IllegalArgumentExceptionif the specified class default constructor cannot be instantiated.
SecurityExceptionif
SecurityContext.Permission(custom, "enter")

is not granted.
See also
SecurityContext.Permission

Definition at line 101 of file AbstractContext.java.

101  {
102  SecurityContext.check(new Permission<T>(custom, "enter"));
103  try {
104  return (T) custom.newInstance().enterInner();
105  } catch (InstantiationException e) {
106  throw new IllegalArgumentException(
107  "Cannot instantiate instance of " + custom, e);
108  } catch (IllegalAccessException e) {
109  throw new IllegalArgumentException("Cannot access " + custom, e);
110  }
111  }

References javolution.context.SecurityContext.check().

Here is the call graph for this function:

◆ enterInner()

AbstractContext javolution.context.AbstractContext.enterInner ( )
protectedinherited

Enters the scope of an inner context which becomes the current context; the previous current context becomes the outer of this context.

Returns
the inner context entered.

Definition at line 141 of file AbstractContext.java.

141  {
143  inner.outer = AbstractContext.CURRENT.get();
144  AbstractContext.CURRENT.set(inner);
145  return inner;
146  }

References javolution.context.AbstractContext.CURRENT, and javolution.context.AbstractContext.outer.

Referenced by javolution.xml.XMLContext.enter(), javolution.text.TextContext.enter(), javolution.context.LogContext.enter(), javolution.context.LocalContext.enter(), javolution.context.SecurityContext.enter(), and javolution.context.ConcurrentContext.enter().

Here is the caller graph for this function:

◆ exit()

void javolution.context.AbstractContext.exit ( )
inherited

Exits the scope of this context; the outer of this context becomes
the current context.

Exceptions
IllegalStateExceptionif this context is not the current context.

Reimplemented in javolution.context.ConcurrentContext, and javolution.context.internal.ConcurrentContextImpl.

Definition at line 155 of file AbstractContext.java.

155  {
156  if (this != AbstractContext.CURRENT.get())
157  throw new IllegalStateException(
158  "This context is not the current context");
159  AbstractContext.CURRENT.set(outer);
160  outer = null;
161  }

References javolution.context.AbstractContext.CURRENT.

◆ getFormat()

static <T> XMLFormat<T> javolution.xml.XMLContext.getFormat ( Class<? extends T >  type)
staticinherited

Returns the xml format for the specified type; if none defined the default object xml format (based on TextFormat) is returned.

Definition at line 49 of file XMLContext.java.

49  {
50  return XMLContext.currentXMLContext().searchFormat(type);
51  }

References javolution.xml.XMLContext.currentXMLContext(), and javolution.xml.XMLContext.searchFormat().

Referenced by javolution.xml.XMLBinding.getFormat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOuter()

AbstractContext javolution.context.AbstractContext.getOuter ( )
protectedinherited

Returns the outer context of this context or

null

if this context has no outer context.

Definition at line 167 of file AbstractContext.java.

167  {
168  return outer;
169  }

◆ inherit()

static void javolution.context.AbstractContext.inherit ( AbstractContext  ctx)
staticinherited

Inherits the specified context which becomes the context of the current thread. This method is particularly useful when creating new threads to make them inherits from the context stack of the parent thread. [code] //Spawns a new thread inheriting the context of the current thread. MyThread myThread = new MyThread(); myThread.inherited = AbstractContext.current(); myThread.start(); ... class MyThread extends Thread { AbstractContext inherited; public void run() { AbstractContext.inherit(inherited); // Sets current context. ... } }[/code]

Definition at line 131 of file AbstractContext.java.

131  {
132  CURRENT.set(ctx);
133  }

Referenced by javolution.context.internal.ConcurrentThreadImpl.run().

Here is the caller graph for this function:

◆ inner()

XMLContext javolution.xml.internal.XMLContextImpl.inner ( )
protected

Returns a new inner instance of this context inheriting the properties of this context. The new instance can be configured independently from its parent.

Reimplemented from javolution.context.AbstractContext.

Definition at line 33 of file XMLContextImpl.java.

33  {
34  XMLContextImpl ctx = new XMLContextImpl();
35  ctx.formats.putAll(formats);
36  return ctx;
37  }

References javolution.xml.internal.XMLContextImpl.formats.

◆ searchFormat()

protected<T> XMLFormat<T> javolution.xml.internal.XMLContextImpl.searchFormat ( Class<? extends T >  type)
package

Searches the xml format for the specified type.

Reimplemented from javolution.xml.XMLContext.

Definition at line 41 of file XMLContextImpl.java.

41  {
42  XMLFormat xml = formats.get(type);
43  if (xml != null)
44  return xml;
45  DefaultXMLFormat format = type.getAnnotation(DefaultXMLFormat.class);
46  if (format != null) {
47  Class<? extends XMLFormat> formatClass = format.value();
48  try {
49  xml = formatClass.newInstance();
50  synchronized (formats) { // Required since possible concurrent use
51  // (getFormatInContext is not a configuration method).
52  formats.put(type, xml);
53  }
54  return xml;
55  } catch (Throwable ex) {
56  throw new RuntimeException(ex);
57  }
58  }
59  // Check predefined format as last resource.
60  if (Map.class.isAssignableFrom(type))
61  return MAP_XML;
62  if (Collection.class.isAssignableFrom(type))
63  return COLLECTION_XML;
64  return OBJECT_XML;
65  }

References javolution.util.FastMap< K, V >.get(), javolution.xml.XMLFormat< T >.newInstance(), javolution.util.FastMap< K, V >.put(), and javolution.xml.DefaultXMLFormat.value().

Here is the call graph for this function:

◆ setFormat()

public<T> void javolution.xml.internal.XMLContextImpl.setFormat ( Class<? extends T >  type,
XMLFormat< T >  format 
)
package

Sets the xml format for the specified type (and its sub-types).

Reimplemented from javolution.xml.XMLContext.

Definition at line 68 of file XMLContextImpl.java.

68  {
69  formats.put(type, format);
70  }

References javolution.util.FastMap< K, V >.put().

Here is the call graph for this function:

Member Data Documentation

◆ COLLECTION_XML

final XMLFormat javolution.xml.internal.XMLContextImpl.COLLECTION_XML
staticprivate
Initial value:
= new XMLFormat() {
@SuppressWarnings("unchecked")
public void read(XMLFormat.InputElement xml, Object obj)
throws XMLStreamException {
Collection collection = (Collection) obj;
while (xml.hasNext()) {
collection.add(xml.getNext());
}
}
public void write(Object obj, XMLFormat.OutputElement xml)
throws XMLStreamException {
Collection collection = (Collection) obj;
for (Iterator i = collection.iterator(); i.hasNext();) {
xml.add(i.next());
}
}
}

Holds the default XML representation for java.util.Collection instances. This representation consists of nested XML elements one for each element of the collection. The elements' order is defined by the collection iterator order. Collections are deserialized using their default constructor.

Definition at line 89 of file XMLContextImpl.java.

◆ CURRENT

final ThreadLocal<AbstractContext> javolution.context.AbstractContext.CURRENT = new ThreadLocal<AbstractContext>()
staticprivateinherited

◆ formats

final FastMap<Class<?>, XMLFormat<?> > javolution.xml.internal.XMLContextImpl.formats = new FastMap<Class<?>, XMLFormat<?>>()
private

Definition at line 30 of file XMLContextImpl.java.

Referenced by javolution.xml.internal.XMLContextImpl.inner().

◆ MAP_XML

final XMLFormat javolution.xml.internal.XMLContextImpl.MAP_XML
staticprivate
Initial value:
= new XMLFormat() {
@SuppressWarnings("unchecked")
public void read(XMLFormat.InputElement xml, Object obj)
throws XMLStreamException {
final Map map = (Map) obj;
while (xml.hasNext()) {
Object key = xml.get("Key");
Object value = xml.get("Value");
map.put(key, value);
}
}
public void write(Object obj, XMLFormat.OutputElement xml)
throws XMLStreamException {
final Map map = (Map) obj;
for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
xml.add(entry.getKey(), "Key");
xml.add(entry.getValue(), "Value");
}
}
}

Holds the default XML representation for java.util.Map instances. This representation consists of key/value pair as nested XML elements. For example:[code] <javolution.util.FastMap> <Key class="java.lang.String" value="ONE">

<Key class="java.lang.String" value="TWO">

<Key class="java.lang.String" value="THREE">

</javolution.util.FastMap>[/code]

The elements' order is defined by the map's entries iterator order. Maps are deserialized using their default constructor.

Definition at line 126 of file XMLContextImpl.java.

◆ OBJECT_XML

final XMLFormat javolution.xml.internal.XMLContextImpl.OBJECT_XML = new XMLFormat.Default()
staticprivate

Holds the static XML format for java.lang.Object.class instances. The XML representation consists of the text representation of the object as a "value" attribute.

Definition at line 80 of file XMLContextImpl.java.

◆ outer

AbstractContext javolution.context.AbstractContext.outer
privateinherited

Holds the outer context or

null

if none (top context).

Definition at line 50 of file AbstractContext.java.

Referenced by javolution.context.AbstractContext.current(), and javolution.context.AbstractContext.enterInner().


The documentation for this class was generated from the following file:
javolution.context.AbstractContext.CURRENT
static final ThreadLocal< AbstractContext > CURRENT
Definition: AbstractContext.java:45
javolution.xml.XMLContext.XMLContext
XMLContext()
Definition: XMLContext.java:36
javolution.context.AbstractContext.inner
abstract AbstractContext inner()
javolution.xml.internal.XMLContextImpl.MAP_XML
static final XMLFormat MAP_XML
Definition: XMLContextImpl.java:126
javolution.context.AbstractContext.outer
AbstractContext outer
Definition: AbstractContext.java:50
javolution.xml.internal.XMLContextImpl.OBJECT_XML
static final XMLFormat OBJECT_XML
Definition: XMLContextImpl.java:80
javolution.xml.internal.XMLContextImpl.COLLECTION_XML
static final XMLFormat COLLECTION_XML
Definition: XMLContextImpl.java:89
javolution.xml.internal.XMLContextImpl.formats
final FastMap< Class<?>, XMLFormat<?> > formats
Definition: XMLContextImpl.java:30
javolution.context.AbstractContext.AbstractContext
AbstractContext()
Definition: AbstractContext.java:55