tdf#172532 Java provider: Use new concrete interfaces for optional methods

Instead of using XInvocation and XPropertySet to expose the optional
create and edit methods, the script providers based on Java now use the
new concrete interfaces XCreatableBrowseNode and XEditableBrowseNode.

Change-Id: Ibc72c434544eb129e30b406d527bef4bb6eea264
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207346
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
Tested-by: Jenkins
This commit is contained in:
Neil Roberts
2026-07-15 09:07:21 +02:00
parent e0fb7f2466
commit f67727b46c
6 changed files with 312 additions and 479 deletions
@@ -21,11 +21,13 @@ package com.sun.star.script.framework.browse;
import com.sun.star.beans.XIntrospectionAccess;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lib.uno.helper.PropertySet;
import com.sun.star.lib.uno.helper.ComponentBase;
import com.sun.star.script.XInvocation;
import com.sun.star.script.browse.BrowseNodeTypes;
import com.sun.star.script.browse.XBrowseNode;
import com.sun.star.script.browse.XCreatableBrowseNode;
import com.sun.star.script.browse.XDeletableBrowseNode;
import com.sun.star.script.browse.XRenamableBrowseNode;
import com.sun.star.script.framework.container.Parcel;
import com.sun.star.script.framework.container.ParcelContainer;
import com.sun.star.script.framework.container.ScriptEntry;
@@ -46,18 +48,16 @@ import java.util.Collection;
import javax.swing.JOptionPane;
public class ParcelBrowseNode extends PropertySet implements
XBrowseNode, XInvocation {
public class ParcelBrowseNode extends ComponentBase implements
XBrowseNode, XCreatableBrowseNode, XDeletableBrowseNode, XRenamableBrowseNode {
private final ScriptProvider provider;
private Collection<XBrowseNode> browsenodes;
private final ParcelContainer container;
private Parcel parcel;
// these four are properties, they are accessed via reflection
public boolean deletable = true;
public boolean editable = false;
public boolean creatable = false;
public boolean renamable = true;
private boolean deletable = true;
private boolean creatable = false;
private boolean renamable = true;
public ParcelBrowseNode(ScriptProvider provider, ParcelContainer container,
String parcelName) throws
@@ -69,10 +69,6 @@ public class ParcelBrowseNode extends PropertySet implements
this.parcel = (Parcel)this.container.getByName(parcelName);
registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable");
registerProperty("Editable", new Type(boolean.class), (short)0, "editable");
registerProperty("Creatable", new Type(boolean.class), (short)0, "creatable");
registerProperty("Renamable", new Type(boolean.class), (short)0, "renamable");
if (provider.hasScriptEditor())
{
this.creatable = true;
@@ -91,7 +87,6 @@ public class ParcelBrowseNode extends PropertySet implements
container.isUnoPkg() ) )
{
deletable = false;
editable = false;
creatable = false;
renamable = false;
}
@@ -147,165 +142,89 @@ public class ParcelBrowseNode extends PropertySet implements
return getName();
}
// implementation of XInvocation interface
public XIntrospectionAccess getIntrospection() {
@Override
public boolean isCreatableNode() {
return creatable;
}
@Override
public boolean isDeletableNode() {
return deletable;
}
@Override
public boolean isRenamableNode() {
return renamable;
}
@Override
public ScriptBrowseNode createNode(String newName) {
if (newName == null || newName.length() == 0)
return null;
try {
String source = provider.getScriptEditor().getTemplate();
String languageName =
newName + "." + provider.getScriptEditor().getExtension();
String language = container.getLanguage();
ScriptEntry entry = new ScriptEntry(language, languageName);
Parcel parcel = (Parcel)container.getByName(getName());
ScriptMetaData data = new ScriptMetaData(parcel, entry, source);
parcel.insertByName(languageName, data);
ScriptBrowseNode sbn =
new ScriptBrowseNode(provider, parcel, languageName);
if (browsenodes == null) {
LogUtils.DEBUG("browsenodes null!!");
browsenodes = new ArrayList<XBrowseNode>(4);
}
browsenodes.add(sbn);
return sbn;
} catch (Exception e) {
LogUtils.DEBUG("ParcelBrowseNode[create] failed with: " + e);
LogUtils.DEBUG(LogUtils.getTrace(e));
}
return null;
}
public Object invoke(String aFunctionName, Object[] aParams,
short[][] aOutParamIndex, Object[][] aOutParam) throws
com.sun.star.lang.IllegalArgumentException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
LogUtils.DEBUG("ParcelBrowseNode invoke for " + aFunctionName);
// Initialise the out parameters - not used but prevents error in
// UNO bridge
aOutParamIndex[0] = new short[0];
aOutParam[0] = new Object[0];
Any result = new Any(new Type(Boolean.class), Boolean.TRUE);
if (aFunctionName.equals("Creatable")) {
try {
String newName;
if (aParams == null || aParams.length < 1
|| !AnyConverter.isString(aParams[0])) {
String prompt = "Enter name for new Script";
String title = "Create Script";
// try to get a DialogFactory instance, if it fails
// just use a Swing JOptionPane to prompt for the name
try {
DialogFactory dialogFactory = DialogFactory.getDialogFactory();
newName = dialogFactory.showInputDialog(title, prompt);
} catch (Exception e) {
newName = JOptionPane.showInputDialog(null, prompt, title,
JOptionPane.QUESTION_MESSAGE);
}
} else {
newName = AnyConverter.toString(aParams[0]);
}
if (newName == null || newName.length() == 0) {
result = new Any(new Type(Boolean.class), Boolean.FALSE);
} else {
String source = provider.getScriptEditor().getTemplate();
String languageName =
newName + "." + provider.getScriptEditor().getExtension();
String language = container.getLanguage();
ScriptEntry entry = new ScriptEntry(language, languageName);
Parcel parcel = (Parcel)container.getByName(getName());
ScriptMetaData data = new ScriptMetaData(parcel, entry, source);
parcel.insertByName(languageName, data);
ScriptBrowseNode sbn =
new ScriptBrowseNode(provider, parcel, languageName);
if (browsenodes == null) {
LogUtils.DEBUG("browsenodes null!!");
browsenodes = new ArrayList<XBrowseNode>(4);
}
browsenodes.add(sbn);
result = new Any(new Type(XBrowseNode.class), sbn);
}
} catch (Exception e) {
LogUtils.DEBUG("ParcelBrowseNode[create] failed with: " + e);
LogUtils.DEBUG(LogUtils.getTrace(e));
result = new Any(new Type(Boolean.class), Boolean.FALSE);
}
} else if (aFunctionName.equals("Deletable")) {
try {
if (container.deleteParcel(getName())) {
result = new Any(new Type(Boolean.class), Boolean.TRUE);
} else {
result = new Any(new Type(Boolean.class), Boolean.FALSE);
}
} catch (Exception e) {
result = new Any(new Type(Boolean.class), Boolean.FALSE);
}
} else if (aFunctionName.equals("Renamable")) {
String newName = null;
try {
if (aParams == null || aParams.length < 1 ||
!AnyConverter.isString(aParams[0])) {
String prompt = "Enter new name for Library";
String title = "Rename Library";
// try to get a DialogFactory instance, if it fails
// just use a Swing JOptionPane to prompt for the name
try {
DialogFactory dialogFactory = DialogFactory.getDialogFactory();
newName = dialogFactory.showInputDialog(title, prompt);
} catch (Exception e) {
newName = JOptionPane.showInputDialog(null, prompt, title,
JOptionPane.QUESTION_MESSAGE);
}
} else {
newName = AnyConverter.toString(aParams[0]);
}
container.renameParcel(getName(), newName);
Parcel p = (Parcel)container.getByName(newName);
if (browsenodes == null) {
getChildNodes();
}
if (browsenodes != null) {
ScriptBrowseNode[] childNodes =
browsenodes.toArray(new ScriptBrowseNode[browsenodes.size()]);
for (int index = 0; index < childNodes.length; index++) {
childNodes[ index ].updateURI(p);
}
}
result = new Any(new Type(XBrowseNode.class), this);
} catch (Exception e) {
result = new Any(new Type(Boolean.class), Boolean.FALSE);
}
@Override
public boolean deleteNode() {
try {
if (container.deleteParcel(getName()))
return true;
} catch (Exception e) {
}
else {
throw new com.sun.star.lang.IllegalArgumentException(
"Function " + aFunctionName + " not supported.");
}
return result;
}
public void setValue(String aPropertyName, Object aValue) throws
com.sun.star.beans.UnknownPropertyException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
}
public Object getValue(String aPropertyName) throws
com.sun.star.beans.UnknownPropertyException {
return null;
}
public boolean hasMethod(String aName) {
return false;
}
public boolean hasProperty(String aName) {
return false;
@Override
public ParcelBrowseNode renameNode(String newName) {
try {
container.renameParcel(getName(), newName);
Parcel p = (Parcel)container.getByName(newName);
if (browsenodes == null) {
getChildNodes();
}
if (browsenodes != null) {
ScriptBrowseNode[] childNodes =
browsenodes.toArray(new ScriptBrowseNode[browsenodes.size()]);
for (int index = 0; index < childNodes.length; index++) {
childNodes[ index ].updateURI(p);
}
}
return this;
} catch (Exception e) {
return null;
}
}
}
@@ -37,8 +37,6 @@ public class PkgProviderBrowseNode extends ProviderBrowseNode {
container.getParcelContainerDir());
LogUtils.DEBUG("*** PkgProviderBrowseNode ctor, container has num parcels = " +
container.getElementNames().length);
deletable = false;
editable = false;
creatable = false;
}
@@ -22,11 +22,11 @@ import com.sun.star.beans.XIntrospectionAccess;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lib.uno.helper.PropertySet;
import com.sun.star.lib.uno.helper.ComponentBase;
import com.sun.star.script.XInvocation;
import com.sun.star.script.browse.BrowseNodeTypes;
import com.sun.star.script.browse.XBrowseNode;
import com.sun.star.script.browse.XCreatableBrowseNode;
import com.sun.star.script.framework.container.ParcelContainer;
import com.sun.star.script.framework.log.LogUtils;
import com.sun.star.script.framework.provider.ScriptProvider;
@@ -44,18 +44,15 @@ import java.util.Collection;
import javax.swing.JOptionPane;
public class ProviderBrowseNode extends PropertySet implements
XBrowseNode, XInvocation {
public class ProviderBrowseNode extends ComponentBase implements
XBrowseNode, XCreatableBrowseNode {
private final ScriptProvider provider;
private Collection<XBrowseNode> browsenodes;
private final String name;
protected ParcelContainer container;
private final XComponentContext m_xCtx;
// these are properties, they are accessed by reflection
public boolean deletable = true;
public boolean creatable = true;
public boolean editable = false;
protected boolean creatable = true;
public ProviderBrowseNode(ScriptProvider provider, ParcelContainer container,
XComponentContext xCtx) {
@@ -66,9 +63,6 @@ public class ProviderBrowseNode extends PropertySet implements
this.provider = provider;
this.m_xCtx = xCtx;
registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable");
registerProperty("Creatable", new Type(boolean.class), (short)0, "creatable");
registerProperty("Editable", new Type(boolean.class), (short)0, "editable");
XMultiComponentFactory xFac = m_xCtx.getServiceManager();
try {
@@ -78,7 +72,6 @@ public class ProviderBrowseNode extends PropertySet implements
xCtx));
if ( container.isUnoPkg() || xSFA.isReadOnly( container.getParcelContainerDir() ) )
{
deletable = false;
creatable = false;
}
}
@@ -165,100 +158,36 @@ public class ProviderBrowseNode extends PropertySet implements
return getName();
}
// implementation of XInvocation interface
public XIntrospectionAccess getIntrospection() {
return null;
@Override
public boolean isCreatableNode() {
return creatable;
}
public Object invoke(String aFunctionName, Object[] aParams,
short[][] aOutParamIndex, Object[][] aOutParam) throws
com.sun.star.lang.IllegalArgumentException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
@Override
public ParcelBrowseNode createNode(String name) {
try {
if (name == null || name.length() == 0)
return null;
// Initialise the out parameters - not used but prevents error in
// UNO bridge
aOutParamIndex[0] = new short[0];
aOutParam[0] = new Object[0];
Object newParcel = container.createParcel(name);
LogUtils.DEBUG("Parcel created " + name + " " + newParcel);
Any result = new Any(new Type(Boolean.class), Boolean.TRUE);
if (newParcel == null)
return null;
if (aFunctionName.equals("Creatable")) {
try {
String name;
ParcelBrowseNode parcel = new ParcelBrowseNode(provider, container, name);
LogUtils.DEBUG("created parcel node ");
if (aParams == null || aParams.length < 1 ||
!AnyConverter.isString(aParams[0])) {
String prompt = "Enter name for new Parcel";
String title = "Create Parcel";
// try to get a DialogFactory instance, if it fails
// just use a Swing JOptionPane to prompt for the name
try {
DialogFactory dialogFactory = DialogFactory.getDialogFactory();
name = dialogFactory.showInputDialog(title, prompt);
} catch (Exception e) {
name = JOptionPane.showInputDialog(null, prompt, title,
JOptionPane.QUESTION_MESSAGE);
}
} else {
name = AnyConverter.toString(aParams[0]);
}
if (name == null || name.length() == 0) {
result = new Any(new Type(Boolean.class), Boolean.FALSE);
} else {
Object newParcel = container.createParcel(name);
LogUtils.DEBUG("Parcel created " + name + " " + newParcel);
if (newParcel == null) {
result = new Any(new Type(Boolean.class), Boolean.FALSE);
} else {
ParcelBrowseNode parcel = new ParcelBrowseNode(provider, container, name);
LogUtils.DEBUG("created parcel node ");
if (browsenodes == null) {
browsenodes = new ArrayList<XBrowseNode>(5);
}
browsenodes.add(parcel);
result = new Any(new Type(XBrowseNode.class), parcel);
}
}
} catch (Exception e) {
LogUtils.DEBUG("ProviderBrowseNode[create] failed with: " + e);
LogUtils.DEBUG(LogUtils.getTrace(e));
result = new Any(new Type(Boolean.class), Boolean.FALSE);
if (browsenodes == null) {
browsenodes = new ArrayList<XBrowseNode>(5);
}
} else {
throw new com.sun.star.lang.IllegalArgumentException(
"Function " + aFunctionName + " not supported.");
browsenodes.add(parcel);
return parcel;
} catch (Exception e) {
LogUtils.DEBUG("ProviderBrowseNode[create] failed with: " + e);
LogUtils.DEBUG(LogUtils.getTrace(e));
return null;
}
return result;
}
public void setValue(String aPropertyName, Object aValue) throws
com.sun.star.beans.UnknownPropertyException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
}
public Object getValue(String aPropertyName) throws
com.sun.star.beans.UnknownPropertyException {
return null;
}
public boolean hasMethod(String aName) {
return false;
}
public boolean hasProperty(String aName) {
return false;
}
}
@@ -19,20 +19,15 @@ package com.sun.star.script.framework.browse;
import com.sun.star.beans.XIntrospectionAccess;
import com.sun.star.container.ElementExistException;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.lang.NoSupportException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lib.uno.helper.PropertySet;
import com.sun.star.reflection.InvocationTargetException;
import com.sun.star.script.XInvocation;
import com.sun.star.script.browse.BrowseNodeTypes;
import com.sun.star.script.browse.XBrowseNode;
import com.sun.star.script.browse.XDeletableBrowseNode;
import com.sun.star.script.browse.XEditableBrowseNode;
import com.sun.star.script.browse.XRenamableBrowseNode;
import com.sun.star.script.framework.container.Parcel;
import com.sun.star.script.framework.container.ScriptEntry;
import com.sun.star.script.framework.container.ScriptMetaData;
@@ -44,12 +39,13 @@ import com.sun.star.ucb.XSimpleFileAccess;
import com.sun.star.uno.Any;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.DeploymentException;
import com.sun.star.uno.Type;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public class ScriptBrowseNode extends PropertySet implements
XBrowseNode, XInvocation {
XBrowseNode, XDeletableBrowseNode, XEditableBrowseNode, XRenamableBrowseNode {
private final ScriptProvider provider;
@@ -59,9 +55,10 @@ public class ScriptBrowseNode extends PropertySet implements
// these are properties, accessed by reflection
public String uri;
public String description;
public boolean editable;
public boolean deletable = false;
public boolean renamable = false;
private boolean editable = false;
private boolean deletable = false;
private boolean renamable = false;
public ScriptBrowseNode(ScriptProvider provider, Parcel parent, String name) {
@@ -111,9 +108,6 @@ public class ScriptBrowseNode extends PropertySet implements
}
registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable");
registerProperty("Editable", new Type(boolean.class), (short)0, "editable");
registerProperty("Renamable", new Type(boolean.class), (short)0, "renamable");
registerProperty("URI", new Type(String.class), (short)0, "uri");
registerProperty("Description", new Type(String.class), (short)0,
"description");
@@ -154,147 +148,88 @@ public class ScriptBrowseNode extends PropertySet implements
}
}
// implementation of XInvocation interface
public XIntrospectionAccess getIntrospection() {
return null;
@Override
public boolean isDeletableNode() {
return deletable;
}
public Object invoke(String aFunctionName, Object[] aParams,
short[][] aOutParamIndex, Object[][] aOutParam) throws
com.sun.star.lang.IllegalArgumentException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
@Override
public boolean isEditableNode() {
return editable;
}
// Initialise the out parameters - not used but prevents error in
// UNO bridge
aOutParamIndex[0] = new short[0];
aOutParam[0] = new Object[0];
@Override
public boolean isRenamableNode() {
return renamable;
}
Any result = new Any(new Type(Boolean.class), Boolean.TRUE);
if (aFunctionName.equals("Editable")) {
if (!editable) {
NoSupportException nse =
new NoSupportException(aFunctionName + " is not editable ");
throw new InvocationTargetException(
"Scripting framework error editing script", null, nse);
}
XScriptContext ctxt = provider.getScriptingContext();
ScriptMetaData data = null;
try {
data = parent.getByName(name);
} catch (NoSuchElementException nse) {
throw new com.sun.star.lang.IllegalArgumentException(nse,
name + " does not exist or can't be found ");
} catch (com.sun.star.lang.WrappedTargetException wte) {
// rethrow
throw new InvocationTargetException(
"Scripting framework editing script ", null, wte.TargetException);
}
provider.getScriptEditor().edit(ctxt, data);
} else if (aFunctionName.equals("Deletable")) {
if (!deletable) {
NoSupportException nse = new NoSupportException(
aFunctionName + " is not supported for this node");
throw new InvocationTargetException(
"Scripting framework error deleting script", null, nse);
}
try {
parent.removeByName(name);
result = new Any(new Type(Boolean.class), Boolean.TRUE);
} catch (NoSuchElementException nse) {
throw new com.sun.star.lang.IllegalArgumentException(nse,
name + " does not exist or can't be found ");
} catch (WrappedTargetException wte) {
// rethrow
throw new InvocationTargetException(
"Scripting framework deleting script ", null, wte.TargetException);
}
} else if (aFunctionName.equals("Renamable")) {
result = new Any(new Type(XBrowseNode.class), new XBrowseNode[0]);
if (!renamable) {
NoSupportException nse = new NoSupportException(
aFunctionName + " is not supported for this node");
throw new InvocationTargetException(
"Scripting framework error renaming script", null, nse);
}
try {
String newName = AnyConverter.toString(aParams[0]);
ScriptMetaData oldData = parent.getByName(name);
oldData.loadSource();
String oldSource = oldData.getSource();
LogUtils.DEBUG("Create renamed script");
String languageName =
newName + "." + provider.getScriptEditor().getExtension();
String language = provider.getName();
ScriptEntry entry = new ScriptEntry(language, languageName);
ScriptMetaData data =
new ScriptMetaData(parent, entry, oldSource);
parent.insertByName(languageName, data);
LogUtils.DEBUG("Now remove old script");
parent.removeByName(name);
uri = data.getShortFormScriptURL();
name = languageName;
result = new Any(new Type(XBrowseNode.class), this);
} catch (NoSuchElementException nse) {
throw new com.sun.star.lang.IllegalArgumentException(nse,
name + " does not exist or can't be found ");
} catch (ElementExistException eee) {
// rethrow
throw new InvocationTargetException(
"Scripting framework error renaming script ", null, eee);
} catch (WrappedTargetException wte) {
// rethrow
throw new InvocationTargetException(
"Scripting framework rename script ", null, wte.TargetException);
}
} else {
throw new com.sun.star.lang.IllegalArgumentException(
"Function " + aFunctionName + " not supported.");
@Override
public boolean editNode() {
if (!editable) {
throw new DeploymentException("Called editable on non-editable node");
}
return result;
XScriptContext ctxt = provider.getScriptingContext();
ScriptMetaData data = null;
try {
data = parent.getByName(name);
} catch (Exception e) {
return false;
}
provider.getScriptEditor().edit(ctxt, data);
return true;
}
public void setValue(String aPropertyName, Object aValue) throws
com.sun.star.beans.UnknownPropertyException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
@Override
public boolean deleteNode() {
if (!deletable) {
throw new DeploymentException("Called delete on non-deletable node");
}
try {
parent.removeByName(name);
return true;
} catch (Exception e) {
return false;
}
}
public Object getValue(String aPropertyName) throws
com.sun.star.beans.UnknownPropertyException {
@Override
public ScriptBrowseNode renameNode(String newName) {
if (!renamable) {
throw new DeploymentException("Called rename on non-renamable node");
}
return null;
}
try {
ScriptMetaData oldData = parent.getByName(name);
oldData.loadSource();
String oldSource = oldData.getSource();
public boolean hasMethod(String aName) {
return false;
}
LogUtils.DEBUG("Create renamed script");
public boolean hasProperty(String aName) {
return false;
String languageName =
newName + "." + provider.getScriptEditor().getExtension();
String language = provider.getName();
ScriptEntry entry = new ScriptEntry(language, languageName);
ScriptMetaData data =
new ScriptMetaData(parent, entry, oldSource);
parent.insertByName(languageName, data);
LogUtils.DEBUG("Now remove old script");
parent.removeByName(name);
uri = data.getShortFormScriptURL();
name = languageName;
return this;
} catch (Exception e) {
return null;
}
}
}
@@ -38,9 +38,12 @@ import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.XTypeProvider;
import com.sun.star.script.XInvocation;
import com.sun.star.script.browse.BrowseNodeTypes;
import com.sun.star.script.browse.XBrowseNode;
import com.sun.star.script.browse.XCreatableBrowseNode;
import com.sun.star.script.browse.XDeletableBrowseNode;
import com.sun.star.script.browse.XEditableBrowseNode;
import com.sun.star.script.browse.XRenamableBrowseNode;
import com.sun.star.script.framework.browse.DialogFactory;
import com.sun.star.script.framework.browse.ProviderBrowseNode;
import com.sun.star.script.framework.container.ParcelContainer;
@@ -74,8 +77,9 @@ import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XMacroExpander;
public abstract class ScriptProvider implements
XScriptProvider, XBrowseNode, XPropertySet, XInvocation, XInitialization,
XTypeProvider, XServiceInfo, XNameContainer {
XScriptProvider, XBrowseNode, XCreatableBrowseNode, XDeletableBrowseNode,
XEditableBrowseNode, XRenamableBrowseNode, XPropertySet, XInitialization, XTypeProvider,
XServiceInfo, XNameContainer {
private final String[] __serviceNames = {
"com.sun.star.script.provider.ScriptProviderFor",
@@ -94,10 +98,13 @@ public abstract class ScriptProvider implements
// proxies to helper objects which implement interfaces
private XPropertySet m_xPropertySetProxy;
private XInvocation m_xInvocationProxy;
// TODO should this be implemented in this class
private XBrowseNode m_xBrowseNodeProxy;
private XCreatableBrowseNode m_xCreatableBrowseNodeProxy;
private XDeletableBrowseNode m_xDeletableBrowseNodeProxy;
private XEditableBrowseNode m_xEditableBrowseNodeProxy;
private XRenamableBrowseNode m_xRenamableBrowseNodeProxy;
private XScriptContext m_xScriptContext;
public ScriptProvider(XComponentContext ctx, String language) {
@@ -243,9 +250,15 @@ public abstract class ScriptProvider implements
// delegation????
m_xBrowseNodeProxy =
new ProviderBrowseNode(this, m_container, m_xContext);
m_xCreatableBrowseNodeProxy =
UnoRuntime.queryInterface(XCreatableBrowseNode.class, m_xBrowseNodeProxy);
m_xDeletableBrowseNodeProxy =
UnoRuntime.queryInterface(XDeletableBrowseNode.class, m_xBrowseNodeProxy);
m_xEditableBrowseNodeProxy =
UnoRuntime.queryInterface(XEditableBrowseNode.class, m_xBrowseNodeProxy);
m_xRenamableBrowseNodeProxy =
UnoRuntime.queryInterface(XRenamableBrowseNode.class, m_xBrowseNodeProxy);
m_xInvocationProxy =
UnoRuntime.queryInterface(XInvocation.class, m_xBrowseNodeProxy);
m_xPropertySetProxy =
UnoRuntime.queryInterface(XPropertySet.class, m_xBrowseNodeProxy);
} else {
@@ -264,15 +277,18 @@ public abstract class ScriptProvider implements
* @return The types value
*/
public com.sun.star.uno.Type[] getTypes() {
Type[] retValue = new Type[ 8 ];
Type[] retValue = new Type[ 11 ];
retValue[ 0 ] = new Type(XScriptProvider.class);
retValue[ 1 ] = new Type(XBrowseNode.class);
retValue[ 2 ] = new Type(XInitialization.class);
retValue[ 3 ] = new Type(XTypeProvider.class);
retValue[ 4 ] = new Type(XServiceInfo.class);
retValue[ 5 ] = new Type(XPropertySet.class);
retValue[ 6 ] = new Type(XInvocation.class);
retValue[ 7 ] = new Type(com.sun.star.container.XNameContainer.class);
retValue[ 6 ] = new Type(XCreatableBrowseNode.class);
retValue[ 7 ] = new Type(XDeletableBrowseNode.class);
retValue[ 8 ] = new Type(XEditableBrowseNode.class);
retValue[ 9 ] = new Type(XRenamableBrowseNode.class);
retValue[ 10 ] = new Type(com.sun.star.container.XNameContainer.class);
return retValue;
}
@@ -415,44 +431,80 @@ public abstract class ScriptProvider implements
return getName();
}
// implementation of XInvocation interface
public XIntrospectionAccess getIntrospection() {
return m_xInvocationProxy.getIntrospection();
@Override
public boolean isCreatableNode()
{
if (m_xCreatableBrowseNodeProxy != null)
return m_xCreatableBrowseNodeProxy.isCreatableNode();
else
return false;
}
public Object invoke(String aFunctionName, Object[] aParams,
short[][] aOutParamIndex, Object[][] aOutParam) throws
com.sun.star.lang.IllegalArgumentException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
return m_xInvocationProxy.invoke(
aFunctionName, aParams, aOutParamIndex, aOutParam);
@Override
public XBrowseNode createNode(String newName)
{
if (m_xCreatableBrowseNodeProxy != null)
return m_xCreatableBrowseNodeProxy.createNode(newName);
else
return null;
}
public void setValue(String aPropertyName, Object aValue) throws
com.sun.star.beans.UnknownPropertyException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
m_xInvocationProxy.setValue(aPropertyName, aValue);
@Override
public boolean isDeletableNode()
{
if (m_xDeletableBrowseNodeProxy != null)
return m_xDeletableBrowseNodeProxy.isDeletableNode();
else
return false;
}
public Object getValue(String aPropertyName) throws
com.sun.star.beans.UnknownPropertyException {
return m_xInvocationProxy.getValue(aPropertyName);
@Override
public boolean deleteNode()
{
if (m_xDeletableBrowseNodeProxy != null)
return m_xDeletableBrowseNodeProxy.deleteNode();
else
return false;
}
public boolean hasMethod(String aName) {
return m_xInvocationProxy.hasMethod(aName);
@Override
public boolean isEditableNode()
{
if (m_xEditableBrowseNodeProxy != null)
return m_xEditableBrowseNodeProxy.isEditableNode();
else
return false;
}
public boolean hasProperty(String aName) {
return m_xInvocationProxy.hasProperty(aName);
@Override
public boolean editNode()
{
if (m_xEditableBrowseNodeProxy != null)
return m_xEditableBrowseNodeProxy.editNode();
else
return false;
}
@Override
public boolean isRenamableNode()
{
if (m_xRenamableBrowseNodeProxy != null)
return m_xRenamableBrowseNodeProxy.isRenamableNode();
else
return false;
}
@Override
public XBrowseNode renameNode(String newName)
{
if (m_xRenamableBrowseNodeProxy != null)
return m_xRenamableBrowseNodeProxy.renameNode(newName);
else
return null;
}
public XPropertySetInfo getPropertySetInfo() {
return m_xPropertySetProxy.getPropertySetInfo();
return m_xPropertySetProxy == null ? null : m_xPropertySetProxy.getPropertySetInfo();
}
public void setPropertyValue(String aPropertyName, Object aValue) throws
@@ -461,14 +513,18 @@ public abstract class ScriptProvider implements
com.sun.star.lang.IllegalArgumentException,
com.sun.star.lang.WrappedTargetException {
m_xPropertySetProxy.setPropertyValue(aPropertyName, aValue);
if (m_xPropertySetProxy != null)
m_xPropertySetProxy.setPropertyValue(aPropertyName, aValue);
}
public Object getPropertyValue(String PropertyName) throws
com.sun.star.beans.UnknownPropertyException,
com.sun.star.lang.WrappedTargetException {
return m_xPropertySetProxy.getPropertyValue(PropertyName);
if (m_xPropertySetProxy == null)
return null;
else
return m_xPropertySetProxy.getPropertyValue(PropertyName);
}
public void addPropertyChangeListener(String aPropertyName,
@@ -476,7 +532,8 @@ public abstract class ScriptProvider implements
com.sun.star.beans.UnknownPropertyException,
com.sun.star.lang.WrappedTargetException {
m_xPropertySetProxy.addPropertyChangeListener(aPropertyName, xListener);
if (m_xPropertySetProxy != null)
m_xPropertySetProxy.addPropertyChangeListener(aPropertyName, xListener);
}
public void removePropertyChangeListener(
@@ -484,8 +541,8 @@ public abstract class ScriptProvider implements
com.sun.star.beans.UnknownPropertyException,
com.sun.star.lang.WrappedTargetException {
m_xPropertySetProxy.removePropertyChangeListener(
aPropertyName, aListener);
if (m_xPropertySetProxy != null)
m_xPropertySetProxy.removePropertyChangeListener(aPropertyName, aListener);
}
public void addVetoableChangeListener(
@@ -493,7 +550,8 @@ public abstract class ScriptProvider implements
com.sun.star.beans.UnknownPropertyException,
com.sun.star.lang.WrappedTargetException {
m_xPropertySetProxy.addVetoableChangeListener(PropertyName, aListener);
if (m_xPropertySetProxy != null)
m_xPropertySetProxy.addVetoableChangeListener(PropertyName, aListener);
}
public void removeVetoableChangeListener(String PropertyName,
@@ -501,9 +559,8 @@ public abstract class ScriptProvider implements
com.sun.star.beans.UnknownPropertyException,
com.sun.star.lang.WrappedTargetException {
m_xPropertySetProxy.removeVetoableChangeListener(
PropertyName, aListener);
if (m_xPropertySetProxy != null)
m_xPropertySetProxy.removeVetoableChangeListener(PropertyName, aListener);
}
public java.lang.Object getByName(String aName) throws
com.sun.star.container.NoSuchElementException,
@@ -13,7 +13,8 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/script/browse/XBrowseNode.hpp>
#include <com/sun/star/script/XInvocation.hpp>
#include <com/sun/star/script/browse/XCreatableBrowseNode.hpp>
#include <com/sun/star/script/browse/XRenamableBrowseNode.hpp>
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
namespace
@@ -51,25 +52,23 @@ void BeanShellTest::setUp()
xUcb->registerContentProvider(xExpandProvider, u"vnd.sun.star.expand"_ustr, true);
}
void createChild(css::uno::Reference<css::script::XInvocation>& xInvocation, const OUString& sName)
void createChild(css::uno::Reference<css::script::browse::XBrowseNode>& xNode,
const OUString& sName)
{
css::uno::Sequence<css::uno::Any> aArgs = { css::uno::Any(sName) };
css::uno::Sequence<sal_Int16> aOutParamIndex;
css::uno::Sequence<css::uno::Any> aOutParam;
xInvocation->invoke("Creatable", aArgs, aOutParamIndex, aOutParam);
css::uno::Reference<css::script::browse::XCreatableBrowseNode> xCreatable(
xNode, css::uno::UNO_QUERY_THROW);
css::uno::Reference<css::script::browse::XBrowseNode> xResult = xCreatable->createNode(sName);
CPPUNIT_ASSERT(xResult.is());
}
void renameLibrary(css::uno::Reference<css::script::XInvocation>& xInvocation,
void renameLibrary(css::uno::Reference<css::script::browse::XBrowseNode>& xNode,
const OUString& sName)
{
css::uno::Sequence<css::uno::Any> aArgs = { css::uno::Any(sName) };
css::uno::Sequence<sal_Int16> aOutParamIndex;
css::uno::Sequence<css::uno::Any> aOutParam;
css::uno::Any xResult = xInvocation->invoke("Renamable", aArgs, aOutParamIndex, aOutParam);
css::uno::Reference<css::script::browse::XRenamableBrowseNode> xRenamable(
xNode, css::uno::UNO_QUERY_THROW);
css::uno::Reference<css::script::browse::XBrowseNode> xResult = xRenamable->renameNode(sName);
css::uno::Reference<css::script::XInvocation> xRenamedInvocation;
CPPUNIT_ASSERT(xResult >>= xRenamedInvocation);
CPPUNIT_ASSERT_EQUAL(xInvocation, xRenamedInvocation);
CPPUNIT_ASSERT_EQUAL(xResult, xNode);
}
css::uno::Reference<css::script::browse::XBrowseNode>
@@ -96,14 +95,12 @@ void BeanShellTest::testRenameEmptyLibrary()
u"com.sun.star.script.provider.ScriptProviderForBeanShell"_ustr, aArgs, m_xContext),
css::uno::UNO_QUERY_THROW);
css::uno::Reference<css::script::XInvocation> xInvocation(xRoot, css::uno::UNO_QUERY_THROW);
// Create an empty library
createChild(xInvocation, "EmptyLibrary");
createChild(xRoot, "EmptyLibrary");
// Make sure the library we just created exists in the hierarchy
css::uno::Reference<css::script::XInvocation> xEmptyLibrary(findChild(xRoot, u"EmptyLibrary"),
css::uno::UNO_QUERY_THROW);
css::uno::Reference<css::script::browse::XBrowseNode> xEmptyLibrary
= findChild(xRoot, u"EmptyLibrary");
// Try renaming it
renameLibrary(xEmptyLibrary, "RenamedEmptyLibrary");
@@ -121,14 +118,12 @@ void BeanShellTest::testRenameNonEmptyLibrary()
u"com.sun.star.script.provider.ScriptProviderForBeanShell"_ustr, aArgs, m_xContext),
css::uno::UNO_QUERY_THROW);
css::uno::Reference<css::script::XInvocation> xInvocation(xRoot, css::uno::UNO_QUERY_THROW);
// Create an empty library
createChild(xInvocation, "NonEmptyLibrary");
createChild(xRoot, "NonEmptyLibrary");
// Make sure the library we just created exists in the hierarchy
css::uno::Reference<css::script::XInvocation> xNewLibrary(findChild(xRoot, u"NonEmptyLibrary"),
css::uno::UNO_QUERY_THROW);
css::uno::Reference<css::script::browse::XBrowseNode> xNewLibrary
= findChild(xRoot, u"NonEmptyLibrary");
// Create a script within the new library
createChild(xNewLibrary, "SomeScript");