diff options
Diffstat (limited to 'src/org/libreoffice/tools/types/Interface.java')
-rw-r--r-- | src/org/libreoffice/tools/types/Interface.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/org/libreoffice/tools/types/Interface.java b/src/org/libreoffice/tools/types/Interface.java new file mode 100644 index 0000000..871a1ea --- /dev/null +++ b/src/org/libreoffice/tools/types/Interface.java @@ -0,0 +1,71 @@ +package org.libreoffice.tools.types; + +import java.util.ArrayList; + +import com.sun.star.reflection.XInterfaceAttributeTypeDescription2; +import com.sun.star.reflection.XInterfaceMemberTypeDescription; +import com.sun.star.reflection.XInterfaceTypeDescription2; +import com.sun.star.reflection.XTypeDescription; +import com.sun.star.uno.TypeClass; +import com.sun.star.uno.UnoRuntime; + +public class Interface { + + XInterfaceTypeDescription2 mDescr; + + public Interface( XTypeDescription pDescr ) { + if ( !pDescr.getTypeClass().equals( TypeClass.INTERFACE ) ) { + throw new IllegalArgumentException( "Not an interface description" ); + } + + mDescr = (XInterfaceTypeDescription2)UnoRuntime.queryInterface( + XInterfaceTypeDescription2.class, pDescr ); + } + + public String getName( ) { + return mDescr.getName(); + } + + public void checkAttributes( ArrayList<XInterfaceAttributeTypeDescription2> pAttributes, ArrayList<String> pPropinterfaces) { + String typeName = getName( ); + if ( typeName.equals( "com.sun.star.beans.XPropertySet" ) || + typeName.equals( "com.sun.star.beans.XFastPropertySet" ) || + typeName.equals( "com.sun.star.beans.XPropertyAccess" ) ) { + pPropinterfaces.add( typeName ); + } + + // Check the attributes in the base types + XTypeDescription[] baseTypes = mDescr.getBaseTypes(); + for (XTypeDescription baseType : baseTypes) { + Interface iface = new Interface( baseType ); + iface.checkAttributes( pAttributes, pPropinterfaces ); + } + + // Check the attributes of the interface + XInterfaceMemberTypeDescription[] members = mDescr.getMembers(); + for (XInterfaceMemberTypeDescription member : members) { + XInterfaceAttributeTypeDescription2 attr = (XInterfaceAttributeTypeDescription2) + UnoRuntime.queryInterface( XInterfaceAttributeTypeDescription2.class, member ); + if ( attr != null ) { + pAttributes.add( attr ); + } + } + } + + public boolean checkXComponentSupport() { + boolean supported = false; + + if ( getName().equals( "com.sun.star.lang.XComponent" ) ) { + supported = true; + } else { + XTypeDescription[] baseTypes = mDescr.getBaseTypes(); + int i = 0; + while ( i < baseTypes.length && !supported ) { + Interface iface = new Interface( baseTypes[i] ); + supported = iface.checkXComponentSupport(); + } + } + + return supported; + } +} |