summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bosdonnat <cedricbosdo@openoffice.org>2009-10-21 23:11:26 +0200
committerCédric Bosdonnat <cedricbosdo@openoffice.org>2009-10-21 23:11:26 +0200
commit5b2850199e7dcbda5d57a1afbf90fb57cf8bc46f (patch)
treee96f59966862062577058747315de6468beeaf5e
parente7fe8ec8d3fda1589364fc2bffb773161e3232b7 (diff)
Types check: implemented
-rw-r--r--src/org/openoffice/tools/DumpException.java17
-rw-r--r--src/org/openoffice/tools/SkeletonMaker.java36
-rw-r--r--src/org/openoffice/tools/types/Bootstrap.java2
-rw-r--r--src/org/openoffice/tools/types/Service.java96
-rw-r--r--src/org/openoffice/tools/types/TypeManager.java60
5 files changed, 205 insertions, 6 deletions
diff --git a/src/org/openoffice/tools/DumpException.java b/src/org/openoffice/tools/DumpException.java
new file mode 100644
index 0000000..faf19b8
--- /dev/null
+++ b/src/org/openoffice/tools/DumpException.java
@@ -0,0 +1,17 @@
+package org.openoffice.tools;
+
+/**
+ * Exception used for all the Uno-skeletonmaker specific problems.
+ *
+ * @author cbosdonnat
+ *
+ */
+public class DumpException extends Exception {
+
+ public DumpException( String pMessage ) {
+ super( pMessage );
+ }
+
+ private static final long serialVersionUID = -3757702196179358713L;
+
+}
diff --git a/src/org/openoffice/tools/SkeletonMaker.java b/src/org/openoffice/tools/SkeletonMaker.java
index 5c77b8a..cb30648 100644
--- a/src/org/openoffice/tools/SkeletonMaker.java
+++ b/src/org/openoffice/tools/SkeletonMaker.java
@@ -1,5 +1,7 @@
package org.openoffice.tools;
+import java.util.ArrayList;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
@@ -8,9 +10,13 @@ import org.openoffice.tools.options.HelpFormatter;
import org.openoffice.tools.options.SubcommandLine;
import org.openoffice.tools.types.TypeManager;
+import com.sun.star.reflection.XPropertyTypeDescription;
+
public class SkeletonMaker {
- public void generateComponent( CommandLine pArgs ) {
+ private static final int MAX_INTERFACES = 12;
+
+ public static void generateComponent( CommandLine pArgs ) {
TypeManager manager = null;
@@ -25,10 +31,31 @@ public class SkeletonMaker {
// Check the types
String[] types = pArgs.getOptionValues( "t" );
+ ArrayList<String> interfaces = new ArrayList<String>();
+ ArrayList<String> services = new ArrayList<String>();
+ ArrayList<XPropertyTypeDescription> members = new ArrayList<XPropertyTypeDescription>();
+
+ // Get the service, interfaces and members from the types
for (String type : types) {
- // TODO Get the service, interfaces... from it
+ manager.checkType( type, services, interfaces, members );
+ }
+
+ // TODO For ProtocolHandler case, check the frame.ProtocolHandler and frame.XDispatch types
+
+ boolean serviceObject = !services.isEmpty();
+
+ // TODO Check for the property helper
+
+ // TODO Check for the default interfaces
+
+ 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
+
+ // TODO Print everything
+
} catch ( Exception e ) {
e.printStackTrace();
} finally {
@@ -48,8 +75,7 @@ public class SkeletonMaker {
// TODO Add the other commands
String subCommand = commandline.getSubcommand();
if ( subCommand.equals( OptionsHelper.COMMAND_COMPONENT ) ) {
- SkeletonMaker maker = new SkeletonMaker();
- maker.generateComponent( commandline.getCommandLine() );
+ generateComponent( commandline.getCommandLine() );
} else if ( subCommand.equals( OptionsHelper.COMMAND_REGISTRATION ) ) {
// TODO implement
@@ -61,7 +87,7 @@ public class SkeletonMaker {
}
}
- private String getLanguage( CommandLine pArgs ) {
+ private static String getLanguage( CommandLine pArgs ) {
String[] langs = LanguageHelper.getLanguages();
String lang = null;
int i = 0;
diff --git a/src/org/openoffice/tools/types/Bootstrap.java b/src/org/openoffice/tools/types/Bootstrap.java
index d3bd3f4..8c933b5 100644
--- a/src/org/openoffice/tools/types/Bootstrap.java
+++ b/src/org/openoffice/tools/types/Bootstrap.java
@@ -111,6 +111,7 @@ public class Bootstrap {
context entries (type class ComponentContextEntry).
@return a new context.
*/
+ @SuppressWarnings("unchecked")
static public XComponentContext createInitialComponentContext( Hashtable context_entries )
throws Exception
{
@@ -188,6 +189,7 @@ public class Bootstrap {
@see cppuhelper/defaultBootstrap_InitialComponentContext()
*/
+ @SuppressWarnings("unchecked")
static public final XComponentContext defaultBootstrap_InitialComponentContext(
String ini_file, Hashtable bootstrap_parameters )
throws Exception
diff --git a/src/org/openoffice/tools/types/Service.java b/src/org/openoffice/tools/types/Service.java
new file mode 100644
index 0000000..0564500
--- /dev/null
+++ b/src/org/openoffice/tools/types/Service.java
@@ -0,0 +1,96 @@
+package org.openoffice.tools.types;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import com.sun.star.reflection.XPropertyTypeDescription;
+import com.sun.star.reflection.XServiceTypeDescription2;
+import com.sun.star.reflection.XTypeDescription;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.UnoRuntime;
+
+/**
+ * Wrapper class to get the informations on a service.
+ *
+ * @author cbosdonnat
+ *
+ */
+public class Service {
+
+ XServiceTypeDescription2 mDescr;
+ ArrayList<XTypeDescription> mRefs;
+
+
+ public Service( XTypeDescription pDescr ) {
+ if ( !pDescr.getTypeClass().equals( TypeClass.SERVICE ) ) {
+ throw new IllegalArgumentException( "Not a service description" );
+ }
+
+ mDescr = (XServiceTypeDescription2)UnoRuntime.queryInterface(
+ XServiceTypeDescription2.class, pDescr );
+
+ mRefs = new ArrayList<XTypeDescription>();
+ if ( !isNewStyleService() ) {
+ mRefs.addAll( Arrays.asList( mDescr.getMandatoryServices() ) );
+ mRefs.addAll( Arrays.asList( mDescr.getOptionalServices() ) );
+ mRefs.addAll( Arrays.asList( mDescr.getMandatoryInterfaces() ) );
+ mRefs.addAll( Arrays.asList( mDescr.getOptionalInterfaces() ) );
+ }
+ }
+
+ public XServiceTypeDescription2 getDescription( ) {
+ return mDescr;
+ }
+
+ public boolean isNewStyleService( ) {
+ return mDescr.isSingleInterfaceBased();
+ }
+
+ public XTypeDescription getSupertype( ) {
+ XTypeDescription superType = null;
+ if ( isNewStyleService() ) {
+ superType = mDescr.getInterface();
+ }
+ return superType;
+ }
+
+ public int getReferenceCount( ) {
+ return mRefs.size();
+ }
+
+ public String getReferenceTypeName( int pRefNumber ) {
+ String name = new String( );
+
+
+
+ return name;
+ }
+
+ public int getMethodCount( ) {
+ return mDescr.getConstructors().length;
+ }
+
+ public String getMethodName( int pMethodNumber ) {
+ String name = new String();
+ if ( pMethodNumber >= 0 && pMethodNumber < getMethodCount() ) {
+ name = mDescr.getConstructors()[ pMethodNumber ].getName();
+ }
+ return name;
+ }
+
+ public int getPropertiesCount( ) {
+ int count = 0;
+ if ( !isNewStyleService() ) {
+ count = mDescr.getProperties().length;
+ }
+ return count;
+ }
+
+ public XPropertyTypeDescription getProperty( int pPropNumber ) {
+ XPropertyTypeDescription result = null;
+ if ( pPropNumber >= 0 && pPropNumber < getPropertiesCount() ) {
+ result = mDescr.getProperties()[ pPropNumber ];
+ }
+ return result;
+ }
+}
diff --git a/src/org/openoffice/tools/types/TypeManager.java b/src/org/openoffice/tools/types/TypeManager.java
index e0a8b34..5950976 100644
--- a/src/org/openoffice/tools/types/TypeManager.java
+++ b/src/org/openoffice/tools/types/TypeManager.java
@@ -4,16 +4,17 @@ import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
-import java.util.Vector;
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.XPropertyTypeDescription;
import com.sun.star.reflection.XTypeDescription;
import com.sun.star.registry.XSimpleRegistry;
import com.sun.star.uno.RuntimeException;
+import com.sun.star.uno.TypeClass;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
@@ -72,6 +73,63 @@ public class TypeManager {
mngrSet.insert( tdProvider );
}
+ public void checkType( String pTypeName, ArrayList<String> pServices, ArrayList<String> pInterfaces,
+ ArrayList< XPropertyTypeDescription > pMembers ) {
+ try {
+ XTypeDescription descr = searchType( pTypeName );
+
+ switch ( descr.getTypeClass().getValue() ) {
+ case TypeClass.INTERFACE_value:
+ // Don't add the css.lang.XTypeProvider and cxx.uno.XWeak
+ if ( !pTypeName.equals( "com.sun.star.lang.XTypeProvider" ) &&
+ !pTypeName.equals( "com.sun.star.uno.XWeak" ) &&
+ !pInterfaces.contains( pTypeName ) ) {
+ pInterfaces.add( pTypeName );
+ }
+ break;
+ case TypeClass.SERVICE_value:
+ if ( !pServices.contains( pTypeName ) ) {
+ pServices.add( pTypeName );
+
+ Service service = new Service( descr );
+ if ( service.getSupertype() != null ) {
+ // New style services
+
+ String supertype = service.getSupertype().getName();
+ if ( !pInterfaces.contains( supertype ) ) {
+ pInterfaces.add( supertype );
+ }
+
+ // check if constructors are specified, if yes automatically
+ // support of XInitialization. We will take care of the default
+ // constructor because in this case XInitialization is not called.
+ if ( service.getMethodCount() > 1 ||
+ service.getMethodCount() == 1 && service.getMethodName( 0 ).length() > 0 ) {
+ String initIterface = "com.sun.star.lang.XInitialization";
+ if ( !pInterfaces.contains( initIterface ) ) {
+ pInterfaces.add( initIterface );
+ }
+ }
+ } else {
+ // Old style services
+
+ for ( int i = 0, len = service.getReferenceCount(); i < len; i++ ) {
+ String refName = service.getReferenceTypeName( i );
+ checkType( refName, pServices, pInterfaces, pMembers );
+ }
+
+ // Get the properties
+ for ( int i = 0, len = service.getPropertiesCount(); i < len; i++ ) {
+ pMembers.add( service.getProperty( i ) );
+ }
+ }
+ }
+ break;
+ }
+ } catch ( Exception e ) {
+ }
+ }
+
/**
* Search the description of a given UNO type in the registries.
*