Kaydet (Commit) 7e7014ba authored tarafından Noel Grandin's avatar Noel Grandin

use early returns to make method easier to read

Change-Id: Iabaedbd51d3832eff8e7470fd586132c38e1d039
üst ec0c4ce0
...@@ -121,94 +121,93 @@ public class ComponentContext implements XComponentContext, XComponent ...@@ -121,94 +121,93 @@ public class ComponentContext implements XComponentContext, XComponent
public Object getValueByName( String rName ) public Object getValueByName( String rName )
{ {
Object o = m_table.get( rName ); Object o = m_table.get( rName );
if (o != null) if (o == null)
{ {
if (o instanceof ComponentContextEntry) if (m_xDelegate != null)
{ {
ComponentContextEntry entry = (ComponentContextEntry)o; return m_xDelegate.getValueByName( rName );
if (entry.m_lateInit != null) }
{ else
Object xInstance = null; {
return Any.VOID;
}
}
try if (!(o instanceof ComponentContextEntry))
{ {
String serviceName = (String)entry.m_lateInit; // direct value in map
if (serviceName != null) return o;
{ }
if (m_xSMgr != null)
{
xInstance = m_xSMgr.createInstanceWithContext( serviceName, this );
}
else
{
if (DEBUG)
System.err.println( "### no service manager instance for late init of singleton instance \"" + rName + "\"!" );
}
}
else
{
XSingleComponentFactory xCompFac =
UnoRuntime.queryInterface(
XSingleComponentFactory.class, entry.m_lateInit );
if (xCompFac != null)
{
xInstance = xCompFac.createInstanceWithContext( this );
}
else
{
if (DEBUG)
System.err.println( "### neither service name nor service factory given for late init of singleton instance \"" + rName + "\"!" );
}
}
}
catch (com.sun.star.uno.Exception exc)
{
if (DEBUG)
System.err.println( "### exception occurred on late init of singleton instance \"" + rName + "\": " + exc.getMessage() );
}
if (xInstance != null) ComponentContextEntry entry = (ComponentContextEntry)o;
{ if (entry.m_lateInit == null)
synchronized (entry) {
{ return entry.m_value;
if (entry.m_lateInit != null) }
{
entry.m_value = xInstance; Object xInstance = null;
entry.m_lateInit = null; try
} {
else // inited in the meantime String serviceName = (String)entry.m_lateInit;
{ if (serviceName != null)
// dispose fresh service instance {
XComponent xComp = UnoRuntime.queryInterface( if (m_xSMgr != null)
XComponent.class, xInstance ); {
if (xComp != null) xInstance = m_xSMgr.createInstanceWithContext( serviceName, this );
{ }
xComp.dispose(); else
} {
} if (DEBUG)
} System.err.println( "### no service manager instance for late init of singleton instance \"" + rName + "\"!" );
}
else
{
if (DEBUG)
System.err.println( "### failed late init of singleton instance \"" + rName + "\"!" );
}
} }
return entry.m_value;
} }
else // direct value in map else
{ {
return o; XSingleComponentFactory xCompFac = UnoRuntime.queryInterface( XSingleComponentFactory.class, entry.m_lateInit );
if (xCompFac != null)
{
xInstance = xCompFac.createInstanceWithContext( this );
}
else
{
if (DEBUG)
System.err.println( "### neither service name nor service factory given for late init of singleton instance \"" + rName + "\"!" );
}
} }
} }
else if (m_xDelegate != null) catch (com.sun.star.uno.Exception exc)
{
if (DEBUG)
System.err.println( "### exception occurred on late init of singleton instance \"" + rName + "\": " + exc.getMessage() );
}
if (xInstance != null)
{ {
return m_xDelegate.getValueByName( rName ); synchronized (entry)
{
if (entry.m_lateInit != null)
{
entry.m_value = xInstance;
entry.m_lateInit = null;
}
else // inited in the meantime
{
// dispose fresh service instance
XComponent xComp = UnoRuntime.queryInterface(
XComponent.class, xInstance );
if (xComp != null)
{
xComp.dispose();
}
}
}
} }
else else
{ {
return Any.VOID; if (DEBUG)
System.err.println( "### failed late init of singleton instance \"" + rName + "\"!" );
} }
return entry.m_value;
} }
public XMultiComponentFactory getServiceManager() public XMultiComponentFactory getServiceManager()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment