summaryrefslogtreecommitdiff
path: root/odk/examples/DevelopersGuide/Config/ConfigExamples.java
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/DevelopersGuide/Config/ConfigExamples.java')
-rw-r--r--odk/examples/DevelopersGuide/Config/ConfigExamples.java99
1 files changed, 45 insertions, 54 deletions
diff --git a/odk/examples/DevelopersGuide/Config/ConfigExamples.java b/odk/examples/DevelopersGuide/Config/ConfigExamples.java
index 979075e82d52..0281dca8324a 100644
--- a/odk/examples/DevelopersGuide/Config/ConfigExamples.java
+++ b/odk/examples/DevelopersGuide/Config/ConfigExamples.java
@@ -179,7 +179,7 @@ public class ConfigExamples
{
// check the provider implementation
XServiceInfo xProviderServices =
- (XServiceInfo) UnoRuntime.queryInterface( XServiceInfo.class, xProvider );
+ UnoRuntime.queryInterface( XServiceInfo.class, xProvider );
if (xProviderServices == null ||
!xProviderServices.supportsService("com.sun.star.configuration.ConfigurationProvider"))
@@ -217,10 +217,9 @@ public class ConfigExamples
final String sProviderService = "com.sun.star.configuration.ConfigurationProvider";
// create the provider and return it as a XMultiServiceFactory
- XMultiServiceFactory xProvider = (XMultiServiceFactory)
- UnoRuntime.queryInterface(XMultiServiceFactory.class,
- mxServiceManager.createInstanceWithContext(sProviderService,
- mxContext));
+ XMultiServiceFactory xProvider = UnoRuntime.queryInterface(XMultiServiceFactory.class,
+ mxServiceManager.createInstanceWithContext(sProviderService,
+ mxContext));
return xProvider;
}
@@ -389,7 +388,7 @@ public class ConfigExamples
// accessing a single nested value
XHierarchicalPropertySet xProperties =
- (XHierarchicalPropertySet)UnoRuntime.queryInterface(XHierarchicalPropertySet.class, xViewRoot);
+ UnoRuntime.queryInterface(XHierarchicalPropertySet.class, xViewRoot);
Object aVisible = xProperties.getHierarchicalPropertyValue("Option/VisibleGrid");
options.visible = ((Boolean) aVisible).booleanValue();
@@ -398,7 +397,7 @@ public class ConfigExamples
Object xSubdivision = xProperties.getHierarchicalPropertyValue("Subdivision");
XMultiPropertySet xSubdivProperties =
- (XMultiPropertySet)UnoRuntime.queryInterface(XMultiPropertySet.class, xSubdivision);
+ UnoRuntime.queryInterface(XMultiPropertySet.class, xSubdivision);
// variables for multi-element access
String[] aElementNames = new String[2];
@@ -415,8 +414,7 @@ public class ConfigExamples
Object xResolution = xProperties.getHierarchicalPropertyValue("Resolution");
XMultiHierarchicalPropertySet xResolutionProperties =
- (XMultiHierarchicalPropertySet)
- UnoRuntime.queryInterface(XMultiHierarchicalPropertySet.class, xResolution);
+ UnoRuntime.queryInterface(XMultiHierarchicalPropertySet.class, xResolution);
aElementNames[0] = "XAxis/Metric";
aElementNames[1] = "YAxis/Metric";
@@ -429,7 +427,7 @@ public class ConfigExamples
// all options have been retrieved - clean up and return
// we are done with the view - dispose it
- ((XComponent)UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose();
+ UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose();
return options;
}
@@ -450,7 +448,7 @@ public class ConfigExamples
{
// First process this as an element (preorder traversal)
XHierarchicalName xElementPath =
- (XHierarchicalName) UnoRuntime.queryInterface(XHierarchicalName.class, xElement);
+ UnoRuntime.queryInterface(XHierarchicalName.class, xElement);
String sPath = xElementPath.getHierarchicalName();
@@ -458,7 +456,7 @@ public class ConfigExamples
// now process this as a container
XNameAccess xChildAccess =
- (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xElement);
+ UnoRuntime.queryInterface(XNameAccess.class, xElement);
// get a list of child elements
String[] aElementNames = xChildAccess.getElementNames();
@@ -472,7 +470,7 @@ public class ConfigExamples
if ( aAnyConv.isObject(aChild) && !aAnyConv.isArray(aChild) )
{
// then get an interface
- XInterface xChildElement = (XInterface)UnoRuntime.queryInterface(XInterface.class, aChild);
+ XInterface xChildElement = UnoRuntime.queryInterface(XInterface.class, aChild);
// and continue processing child elements recursively
browseElementRecursively( xChildElement, aProcessor );
@@ -510,7 +508,7 @@ public class ConfigExamples
// This assumes that the processor
// does not keep a reference to the elements in processStructuralElement
- ((XComponent) UnoRuntime.queryInterface(XComponent.class,xViewRoot)).dispose();
+ UnoRuntime.queryInterface(XComponent.class,xViewRoot).dispose();
xViewRoot = null;
}
@@ -549,11 +547,11 @@ public class ConfigExamples
public void processStructuralElement( String sPath_, XInterface xElement_) {
// get template information, to detect instances of the 'Filter' template
XTemplateInstance xInstance =
- ( XTemplateInstance )UnoRuntime.queryInterface( XTemplateInstance .class,xElement_);
+ UnoRuntime.queryInterface( XTemplateInstance .class,xElement_);
// only select the Filter entries
if (xInstance != null && xInstance.getTemplateName().endsWith("Filter")) {
- XNamed xNamed = (XNamed)UnoRuntime.queryInterface(XNamed.class,xElement_);
+ XNamed xNamed = UnoRuntime.queryInterface(XNamed.class,xElement_);
System.out.println("Filter " + xNamed.getName() + " (" + sPath_ + ")");
}
}
@@ -579,8 +577,7 @@ public class ConfigExamples
// set up the initial values and register listeners
// get a data access interface, to supply the view with a model
XMultiHierarchicalPropertySet xProperties =
- (XMultiHierarchicalPropertySet)
- UnoRuntime.queryInterface(XMultiHierarchicalPropertySet.class, xViewRoot);
+ UnoRuntime.queryInterface(XMultiHierarchicalPropertySet.class, xViewRoot);
dialog.setModel( xProperties );
@@ -589,7 +586,7 @@ public class ConfigExamples
XChangesListener xListener = dialog.createChangesListener( );
XChangesNotifier xNotifier =
- (XChangesNotifier)UnoRuntime.queryInterface(XChangesNotifier.class, xViewRoot);
+ UnoRuntime.queryInterface(XChangesNotifier.class, xViewRoot);
xNotifier.addChangesListener( xListener );
@@ -600,7 +597,7 @@ public class ConfigExamples
{
// changes have been applied to the view here
XChangesBatch xUpdateControl =
- (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot);
+ UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot);
try
{
@@ -617,7 +614,7 @@ public class ConfigExamples
xNotifier.removeChangesListener( xListener );
// we are done with the view - dispose it
- ((XComponent)UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose();
+ UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose();
}
/** A class that changes some grid options settings
@@ -721,7 +718,7 @@ public class ConfigExamples
try
{
XHierarchicalPropertySet xHPS =
- (XHierarchicalPropertySet)UnoRuntime.queryInterface(XHierarchicalPropertySet.class, mxModel);
+ UnoRuntime.queryInterface(XHierarchicalPropertySet.class, mxModel);
final String sSetting = "Option/VisibleGrid";
@@ -749,7 +746,7 @@ public class ConfigExamples
{
Object xOtherViewRoot = createUpdatableView(xKey);
- XNameReplace aReplace = (XNameReplace)UnoRuntime.queryInterface(XNameReplace.class, xOtherViewRoot);
+ XNameReplace aReplace = UnoRuntime.queryInterface(XNameReplace.class, xOtherViewRoot);
String aItemNames [] = aReplace.getElementNames();
for (int i=0; i < aItemNames.length; ++i) {
@@ -778,12 +775,12 @@ public class ConfigExamples
// commit the changes
XChangesBatch xUpdateControl =
- (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class,xOtherViewRoot);
+ UnoRuntime.queryInterface(XChangesBatch.class,xOtherViewRoot);
xUpdateControl.commitChanges();
// we are done with the view - dispose it
- ((XComponent)UnoRuntime.queryInterface(XComponent.class, xOtherViewRoot)).dispose();
+ UnoRuntime.queryInterface(XComponent.class, xOtherViewRoot).dispose();
}
catch (Exception e)
{
@@ -805,13 +802,13 @@ public class ConfigExamples
// resetting a single nested value
XHierarchicalNameAccess xHierarchicalAccess =
- (XHierarchicalNameAccess)UnoRuntime.queryInterface(XHierarchicalNameAccess.class, xViewRoot);
+ UnoRuntime.queryInterface(XHierarchicalNameAccess.class, xViewRoot);
// get using absolute name
Object xOptions = xHierarchicalAccess.getByHierarchicalName(cGridOptionsPath + "/Option");
XPropertyState xOptionState =
- (XPropertyState)UnoRuntime.queryInterface(XPropertyState.class, xOptions);
+ UnoRuntime.queryInterface(XPropertyState.class, xOptions);
xOptionState.setPropertyToDefault("VisibleGrid");
@@ -820,9 +817,9 @@ public class ConfigExamples
Object xResolutionY = xHierarchicalAccess.getByHierarchicalName("Resolution/YAxis");
XPropertyState xResolutionStateX =
- (XPropertyState)UnoRuntime.queryInterface(XPropertyState.class, xResolutionX);
+ UnoRuntime.queryInterface(XPropertyState.class, xResolutionX);
XPropertyState xResolutionStateY =
- (XPropertyState)UnoRuntime.queryInterface(XPropertyState.class, xResolutionY);
+ UnoRuntime.queryInterface(XPropertyState.class, xResolutionY);
xResolutionStateX.setPropertyToDefault("Metric");
xResolutionStateY.setPropertyToDefault("Metric");
@@ -831,18 +828,18 @@ public class ConfigExamples
Object xSubdivision = xHierarchicalAccess.getByHierarchicalName("Subdivision");
XMultiPropertyStates xSubdivisionStates =
- (XMultiPropertyStates)UnoRuntime.queryInterface(XMultiPropertyStates.class, xSubdivision);
+ UnoRuntime.queryInterface(XMultiPropertyStates.class, xSubdivision);
xSubdivisionStates.setAllPropertiesToDefault();
// commit the changes
XChangesBatch xUpdateControl =
- (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot);
+ UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot);
xUpdateControl.commitChanges();
// we are done with the view - dispose it
- ((XComponent)UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose();
+ UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose();
}
@@ -900,7 +897,7 @@ public class ConfigExamples
// set the values
XPropertySet xDataSourceProperties =
- (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xDataSource);
+ UnoRuntime.queryInterface(XPropertySet.class, xDataSource);
xDataSourceProperties.setPropertyValue("URL", sDataSourceURL );
xDataSourceProperties.setPropertyValue("User", sUser );
@@ -923,12 +920,12 @@ public class ConfigExamples
// commit the changes
XChangesBatch xUpdateControl =
- (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot);
+ UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot);
xUpdateControl.commitChanges();
// now clean up
- ((XComponent) UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose();
+ UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose();
}
/** This method gets the DataSourceDescription for a data source.
@@ -956,7 +953,7 @@ public class ConfigExamples
xProvider.createInstanceWithArguments(cUpdatableView, aArguments);
XNameAccess xSetOfDataSources =
- (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,xViewRoot);
+ UnoRuntime.queryInterface(XNameAccess.class,xViewRoot);
Object xDataSourceDescriptor = null; // the result
if ( xSetOfDataSources .hasByName( sDataSourceName ))
@@ -965,8 +962,7 @@ public class ConfigExamples
try
{
// the view should point to the element directly, so we need to extend the path
- XHierarchicalName xComposePath = (XHierarchicalName)
- UnoRuntime.queryInterface(XHierarchicalName.class, xSetOfDataSources );
+ XHierarchicalName xComposePath = UnoRuntime.queryInterface(XHierarchicalName.class, xSetOfDataSources );
String sElementPath = xComposePath.composeHierarchicalName( sDataSourceName );
@@ -984,7 +980,7 @@ public class ConfigExamples
if ( xDataSourceDescriptor != null) // all went fine
{
// dispose the other view
- ((XComponent)UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose();
+ UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose();
xViewRoot = null;
}
}
@@ -1001,11 +997,11 @@ public class ConfigExamples
{
// get the container
XNameContainer xSetUpdate =
- (XNameContainer)UnoRuntime.queryInterface(XNameContainer.class, xViewRoot);
+ UnoRuntime.queryInterface(XNameContainer.class, xViewRoot);
// create a new detached set element (instance of DataSourceDescription)
XSingleServiceFactory xElementFactory =
- (XSingleServiceFactory)UnoRuntime.queryInterface(XSingleServiceFactory.class, xSetUpdate);
+ UnoRuntime.queryInterface(XSingleServiceFactory.class, xSetUpdate);
// the new element is the result !
xDataSourceDescriptor = xElementFactory.createInstance();
@@ -1026,17 +1022,16 @@ public class ConfigExamples
// get the settings set as a container
XNameContainer xSettingsContainer =
- (XNameContainer) UnoRuntime.queryInterface( XNameContainer.class, xSettingsSet);
+ UnoRuntime.queryInterface( XNameContainer.class, xSettingsSet);
// and get a factory interface for creating the entries
XSingleServiceFactory xSettingsFactory =
- (XSingleServiceFactory) UnoRuntime.queryInterface(XSingleServiceFactory.class, xSettingsSet);
+ UnoRuntime.queryInterface(XSingleServiceFactory.class, xSettingsSet);
// now insert the individual settings
for (int i = 0; i < aSettings.length; ++i) {
// create a DataSourceSetting object
- XPropertySet xSetting = (XPropertySet)
- UnoRuntime.queryInterface( XPropertySet.class, xSettingsFactory.createInstance() );
+ XPropertySet xSetting = UnoRuntime.queryInterface( XPropertySet.class, xSettingsFactory.createInstance() );
// can set the value before inserting
xSetting.setPropertyValue( "Value", aSettings[i].Value );
@@ -1061,7 +1056,7 @@ public class ConfigExamples
do
{
XChild xParentAccess =
- (XChild) UnoRuntime.queryInterface(XChild.class,xResult);
+ UnoRuntime.queryInterface(XChild.class,xResult);
if (xParentAccess != null)
xParent = xParentAccess.getParent();
@@ -1082,11 +1077,9 @@ public class ConfigExamples
void renameSetItem(XNamed xNamedItem, String sNewName)
throws com.sun.star.uno.Exception
{
- XChild xChildItem = (XChild)
- UnoRuntime.queryInterface(XChild.class, xNamedItem);
+ XChild xChildItem = UnoRuntime.queryInterface(XChild.class, xNamedItem);
- XNameContainer xParentSet = (XNameContainer)
- UnoRuntime.queryInterface( XNameContainer.class, xChildItem.getParent() );
+ XNameContainer xParentSet = UnoRuntime.queryInterface( XNameContainer.class, xChildItem.getParent() );
String sOldName = xNamedItem.getName();
@@ -1099,11 +1092,9 @@ public class ConfigExamples
void moveSetItem(XChild xChildItem, XNameContainer xNewParent)
throws com.sun.star.uno.Exception
{
- XNamed xNamedItem = (XNamed)
- UnoRuntime.queryInterface(XNamed.class, xChildItem);
+ XNamed xNamedItem = UnoRuntime.queryInterface(XNamed.class, xChildItem);
- XNameContainer xOldParent = (XNameContainer)
- UnoRuntime.queryInterface( XNameContainer.class, xChildItem.getParent() );
+ XNameContainer xOldParent = UnoRuntime.queryInterface( XNameContainer.class, xChildItem.getParent() );
String sItemName = xNamedItem.getName();