summaryrefslogtreecommitdiff
path: root/src/org/openoffice/tools
diff options
context:
space:
mode:
authorCédric Bosdonnat <cedricbosdo@openoffice.org>2009-10-30 11:41:45 +0100
committerCédric Bosdonnat <cedricbosdo@openoffice.org>2009-10-30 11:41:45 +0100
commit15f9a487edc99c9213535c74ff6ea8560cc57df0 (patch)
treed8d267a2c707a31eee7f22d4d8e0038d722c4977 /src/org/openoffice/tools
parent5b2850199e7dcbda5d57a1afbf90fb57cf8bc46f (diff)
Implemented the types check
Now, let's print everything to the output file: the real configurable part will start soon.
Diffstat (limited to 'src/org/openoffice/tools')
-rw-r--r--src/org/openoffice/tools/SkeletonMaker.java31
-rw-r--r--src/org/openoffice/tools/types/Interface.java71
-rw-r--r--src/org/openoffice/tools/types/Service.java22
-rw-r--r--src/org/openoffice/tools/types/TypeManager.java81
4 files changed, 199 insertions, 6 deletions
diff --git a/src/org/openoffice/tools/SkeletonMaker.java b/src/org/openoffice/tools/SkeletonMaker.java
index cb30648..ad319b6 100644
--- a/src/org/openoffice/tools/SkeletonMaker.java
+++ b/src/org/openoffice/tools/SkeletonMaker.java
@@ -10,6 +10,7 @@ import org.openoffice.tools.options.HelpFormatter;
import org.openoffice.tools.options.SubcommandLine;
import org.openoffice.tools.types.TypeManager;
+import com.sun.star.reflection.XInterfaceAttributeTypeDescription2;
import com.sun.star.reflection.XPropertyTypeDescription;
public class SkeletonMaker {
@@ -42,17 +43,19 @@ public class SkeletonMaker {
// TODO For ProtocolHandler case, check the frame.ProtocolHandler and frame.XDispatch types
- boolean serviceObject = !services.isEmpty();
+ // Check for the property helper
+ ArrayList<XInterfaceAttributeTypeDescription2> attributes = new ArrayList<XInterfaceAttributeTypeDescription2>();
+ ArrayList<String> propinterfaces = new ArrayList<String>();
+ String propertyHelper = manager.checkPropertyHelper( pArgs, services, interfaces, attributes, propinterfaces );
- // TODO Check for the property helper
-
- // TODO Check for the default interfaces
+ // Check the default interfaces
+ checkDefaultInterfaces( interfaces, services, propertyHelper );
if ( interfaces.size() > MAX_INTERFACES ) {
throw new DumpException( "The skeletonmaker supports components with 12 interfaces only (limitation of the UNO implementation helpers)!" );
}
- // TODO Check the XComponent support
+ boolean supportXComp = manager.checkXComponentSupport( interfaces );
// TODO Print everything
@@ -66,6 +69,24 @@ public class SkeletonMaker {
}
}
+ private static void checkDefaultInterfaces(ArrayList<String> pInterfaces,
+ ArrayList<String> pServices, String pPropertyHelper) {
+
+ if ( pServices.isEmpty() ) {
+ pInterfaces.remove( "com.sun.star.lang.XServiceInfo" );
+ } else {
+ if ( !pInterfaces.contains( "com.sun.star.lang.XServiceInfo" ) ) {
+ pInterfaces.add( "com.sun.star.lang.XServiceInfo" );
+ }
+ }
+
+ if ( pPropertyHelper.equals( TypeManager.NOPROPERTYHELPER ) ) {
+ pInterfaces.remove( "com.sun.star.beans.XPropertySet" );
+ pInterfaces.remove( "com.sun.star.beans.XFastPropertySet" );
+ pInterfaces.remove( "com.sun.star.beans.XPropertyAccess" );
+ }
+ }
+
public static void main(String[] args) {
Command cmd = OptionsHelper.setupCommandLine();
diff --git a/src/org/openoffice/tools/types/Interface.java b/src/org/openoffice/tools/types/Interface.java
new file mode 100644
index 0000000..bd99aa7
--- /dev/null
+++ b/src/org/openoffice/tools/types/Interface.java
@@ -0,0 +1,71 @@
+package org.openoffice.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;
+ }
+}
diff --git a/src/org/openoffice/tools/types/Service.java b/src/org/openoffice/tools/types/Service.java
index 0564500..de8ad7c 100644
--- a/src/org/openoffice/tools/types/Service.java
+++ b/src/org/openoffice/tools/types/Service.java
@@ -61,7 +61,10 @@ public class Service {
public String getReferenceTypeName( int pRefNumber ) {
String name = new String( );
-
+ XTypeDescription ref = mRefs.get( pRefNumber );
+ if ( ref != null ) {
+ name = ref.getName();
+ }
return name;
}
@@ -93,4 +96,21 @@ public class Service {
}
return result;
}
+
+ public boolean hasProperties() {
+
+ boolean hasProps = getPropertiesCount() > 0;
+
+ // Check the references for properties
+ int i = 0;
+ while ( !hasProps && i < getReferenceCount() ) {
+ XTypeDescription desc = mRefs.get( i );
+ if ( desc.getTypeClass().equals( TypeClass.SERVICE ) ) {
+ Service service = new Service( desc );
+ hasProps = service.hasProperties();
+ }
+ }
+
+ return hasProps;
+ }
}
diff --git a/src/org/openoffice/tools/types/TypeManager.java b/src/org/openoffice/tools/types/TypeManager.java
index 5950976..b105a4f 100644
--- a/src/org/openoffice/tools/types/TypeManager.java
+++ b/src/org/openoffice/tools/types/TypeManager.java
@@ -4,12 +4,16 @@ import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.commons.cli.CommandLine;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XHierarchicalNameAccess;
import com.sun.star.container.XSet;
import com.sun.star.frame.XDesktop;
import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.reflection.XInterfaceAttributeTypeDescription2;
import com.sun.star.reflection.XPropertyTypeDescription;
import com.sun.star.reflection.XTypeDescription;
import com.sun.star.registry.XSimpleRegistry;
@@ -25,6 +29,8 @@ import com.sun.star.uno.XComponentContext;
*/
public class TypeManager {
+ public static final String NOPROPERTYHELPER = "_";
+
private String mInstallDir;
private XComponentContext mCtxt;
private XHierarchicalNameAccess mTypeDescMngr;
@@ -130,6 +136,81 @@ public class TypeManager {
}
}
+ public String checkPropertyHelper(CommandLine pArgs, ArrayList<String> pServices, ArrayList<String> pInterfaces,
+ ArrayList<XInterfaceAttributeTypeDescription2> pAttributes, ArrayList<String> pPropinterfaces) {
+
+ String result = new String();
+
+ Iterator<String> it = pInterfaces.iterator();
+ if ( !pServices.isEmpty() ) {
+ it = pServices.iterator();
+ }
+
+ boolean oldStyleWithProps = false;
+ while ( it.hasNext() && result.isEmpty() ) {
+ String typename = it.next( );
+ try {
+ XTypeDescription typeDesc = searchType( typename );
+ if ( !pServices.isEmpty() ) {
+ Service service = new Service( typeDesc );
+
+ boolean propMixin = Boolean.parseBoolean( pArgs.getOptionValue( "propertysetmixin" ) );
+ if ( propMixin && service.getSupertype() != null ) {
+ Interface iface = new Interface( service.getSupertype() );
+ iface.checkAttributes( pAttributes, pPropinterfaces );
+
+ if ( !pAttributes.isEmpty() && !pPropinterfaces.isEmpty() ) {
+ result = service.getSupertype().getName();
+ }
+ } else {
+ oldStyleWithProps = service.hasProperties();
+ }
+ } else {
+ Interface iface = new Interface( typeDesc );
+ iface.checkAttributes( pAttributes, pPropinterfaces );
+ if ( !pAttributes.isEmpty() && !pPropinterfaces.isEmpty() ) {
+ result = typename;
+ }
+ }
+ } catch( Exception e ) {
+ }
+ }
+
+ if ( result.isEmpty() && oldStyleWithProps ) {
+ result = NOPROPERTYHELPER;
+ }
+
+ return result;
+ }
+
+ public boolean checkXComponentSupport( ArrayList<String> pInterfaces ) {
+
+ boolean supported = false;
+
+ if ( pInterfaces.isEmpty() ) {
+ supported = false;
+ } else {
+
+ Iterator<String> it = pInterfaces.iterator();
+ while ( it.hasNext() && !supported ) {
+ String typeName = it.next( );
+ if ( typeName.equals( "com.sun.star.lang.XComponent" ) ) {
+ pInterfaces.remove( "com.sun.star.lang.XComponent" );
+ supported = true;
+ } else {
+ try {
+ XTypeDescription descr = searchType( typeName );
+ Interface iface = new Interface( descr );
+ supported = iface.checkXComponentSupport( );
+ } catch ( NoSuchElementException e ) {
+ }
+ }
+ }
+ }
+
+ return supported;
+ }
+
/**
* Search the description of a given UNO type in the registries.
*