type clean up

This commit is contained in:
Kay Ramme 2001-05-08 08:34:18 +00:00
parent 4cc8b7efdd
commit 2938ec9144
9 changed files with 835 additions and 374 deletions

View File

@ -0,0 +1,94 @@
/*************************************************************************
*
* $RCSfile: FieldDescription.java,v $
*
* $Revision: 1.1 $
*
* last change: $Author: kr $ $Date: 2001-05-08 09:34:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
package com.sun.star.lib.uno.typedesc;
import java.lang.reflect.Field;
import com.sun.star.uno.IMethodDescription;
import com.sun.star.uno.ITypeDescription;
import com.sun.star.uno.IFieldDescription;
import com.sun.star.lib.uno.typeinfo.MemberTypeInfo;
public class FieldDescription extends MemberTypeInfo implements IFieldDescription {
ITypeDescription _iTypeDescription;
Field _field;
FieldDescription(MemberTypeInfo memberTypeInfo, Field field) {
super(memberTypeInfo.getName(), memberTypeInfo.getFlags());
_field = field;
}
public ITypeDescription getTypeDescription() {
if(_iTypeDescription == null)
_iTypeDescription = TypeDescription.getTypeDescription(this, getField().getType());
return _iTypeDescription;
}
public Field getField() {
return _field;
}
}

View File

@ -2,9 +2,9 @@
*
* $RCSfile: MethodDescription.java,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: kr $ $Date: 2001-04-17 15:01:37 $
* last change: $Author: kr $ $Date: 2001-05-08 09:34:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -65,12 +65,16 @@ package com.sun.star.lib.uno.typedesc;
import java.lang.reflect.Method;
import com.sun.star.uno.IMethodDescription;
import com.sun.star.uno.ITypeDescription;
import com.sun.star.lib.uno.typeinfo.MethodTypeInfo;
import com.sun.star.lib.uno.typeinfo.ParameterTypeInfo;
import com.sun.star.lib.uno.typeinfo.TypeInfo;
public class MethodDescription extends MethodTypeInfo {
public class MethodDescription extends MethodTypeInfo implements IMethodDescription {
static private final TypeDescription __xInterface = TypeDescription.getTypeDescription(com.sun.star.uno.XInterface.class);
static private TypeDescription __xInterfaceArray;
static private TypeDescription __xInterfaceArrayArray;
@ -132,15 +136,15 @@ public class MethodDescription extends MethodTypeInfo {
_return_sig = TypeDescription.getTypeDescription(this, resultClass);
}
public TypeDescription[] getInSignature() {
public ITypeDescription[] getInSignature() {
return _in_sig;
}
public TypeDescription[] getOutSignature() {
public ITypeDescription[] getOutSignature() {
return _out_sig;
}
public TypeDescription getReturnSig() {
public ITypeDescription getReturnSignature() {
return _return_sig;
}

View File

@ -2,9 +2,9 @@
*
* $RCSfile: TypeDescription.java,v $
*
* $Revision: 1.7 $
* $Revision: 1.8 $
*
* last change: $Author: kr $ $Date: 2001-05-04 11:13:38 $
* last change: $Author: kr $ $Date: 2001-05-08 09:34:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -72,6 +72,9 @@ import java.lang.reflect.Modifier;
import com.sun.star.uno.Any;
import com.sun.star.uno.Enum;
import com.sun.star.uno.IFieldDescription;
import com.sun.star.uno.IMethodDescription;
import com.sun.star.uno.ITypeDescription;
import com.sun.star.uno.Type;
import com.sun.star.uno.TypeClass;
import com.sun.star.uno.Union;
@ -94,15 +97,15 @@ import com.sun.star.lib.uno.typeinfo.TypeInfo;
* methods, which may be changed or moved in the furture, so please
* do not use these methods.
* <p>
* @version $Revision: 1.7 $ $ $Date: 2001-05-04 11:13:38 $
* @version $Revision: 1.8 $ $ $Date: 2001-05-08 09:34:17 $
* @author Kay Ramme
* @since UDK2.0
*/
public class TypeDescription {
public class TypeDescription implements ITypeDescription {
/**
* When set to true, enables various debugging output.
*/
public static final boolean DEBUG = false;
private static final boolean DEBUG = false;
public static final TypeDescription __void_TypeDescription = new TypeDescription(TypeClass.VOID, "void", "[Ljava.lang.Void;", void.class); // VOID
public static final TypeDescription __char_TypeDescription = new TypeDescription(TypeClass.CHAR, "char", "[C", char.class); // CHAR
@ -121,7 +124,7 @@ public class TypeDescription {
public static final TypeDescription __any_TypeDescription = new TypeDescription(TypeClass.ANY, "any", "[Ljava.lang.Object;", Object.class); // ANY
static private final Hashtable __classToTypeDescription = new Hashtable();
static private final Hashtable __classToTypeDescription = new Hashtable();
static private final Hashtable __typeNameToTypeDescription = new Hashtable();
static private final Hashtable __typeClassToTypeName = new Hashtable();
@ -528,6 +531,25 @@ public class TypeDescription {
return typeDescription;
}
static public ITypeDescription getTypeDescription(Type type) throws ClassNotFoundException {
ITypeDescription iTypeDescription = type.getTypeDescription();
if(iTypeDescription == null) {
if(type.getZClass() != null)
iTypeDescription = getTypeDescription(type.getZClass());
else if(type.getTypeClass() != null && type.getTypeClass() != TypeClass.UNKNOWN)
iTypeDescription = getTypeDescription(type.getTypeClass());
else if(type.getTypeName() != null)
iTypeDescription = getTypeDescription(type.getTypeName());
type.setTypeDescription(iTypeDescription);
}
return iTypeDescription;
}
static public TypeDescription getTypeDescription(TypeClass typeClass) {
TypeDescription typeDescription = null;
@ -548,11 +570,11 @@ public class TypeDescription {
protected int _offset;
protected MethodDescription _methodDescriptionsByIndex[];
protected Hashtable _methodDescriptionsByName;
protected Hashtable _memberTypeInfosByName;
protected Hashtable _iFieldDescriptionsByName;
protected Field _fields[];
protected IFieldDescription _iFieldDescriptions[];
protected TypeDescription _componentType;
protected ITypeDescription _componentType;
private void _initByClass(Class zClass) {
@ -588,7 +610,7 @@ public class TypeDescription {
_typeClass = TypeClass.SEQUENCE;
_componentType = getTypeDescription(zClass.getComponentType());
_typeName = "[]" + _componentType._typeName;
_typeName = "[]" + _componentType.getTypeName();
_arrayTypeName = "[" + _class.getName();
}
@ -602,7 +624,6 @@ public class TypeDescription {
if(superClass != null && superClass != Object.class)
_superType = getTypeDescription(superClass);
_initFields();
_initMemberTypeInfos();
}
else {
@ -615,7 +636,6 @@ public class TypeDescription {
if(superClass != null && superClass != Object.class)
_superType = getTypeDescription(superClass);
_initFields();
_initMemberTypeInfos();
}
@ -642,8 +662,8 @@ public class TypeDescription {
_typeClass = TypeClass.SEQUENCE;
_componentType = getTypeDescription(typeName.substring(2));
_class = Class.forName(_componentType._arrayTypeName);
_arrayTypeName = "[" + _componentType._arrayTypeName;
_class = Class.forName(_componentType.getArrayTypeName());
_arrayTypeName = "[" + _componentType.getArrayTypeName();
__cyclicTypes.remove(typeName);
}
@ -653,21 +673,6 @@ public class TypeDescription {
}
private void _initFields() {
Field fields[] = _class.getFields();
int size = 0;
for(int i = 0; i < fields.length; ++ i)
if((fields[i].getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) == 0) // neither static nor transient ?
++ size;
_fields = new Field[size];
size = 0;
for(int i = 0; i < fields.length; ++ i)
if((fields[i].getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) == 0) // neither static nor transient ?
_fields[size ++] = fields[i];
}
private void _initMethodTypeInfos() {
if(_methodDescriptionsByName != null)
return;
@ -752,96 +757,94 @@ public class TypeDescription {
private void _initMemberTypeInfos() {
TypeInfo typeInfos[] = __getTypeInfos(_class);
Field fields[] = getFields();
MemberTypeInfo memberTypeInfos[] = new MemberTypeInfo[fields.length];
Field fields[] = _class.getFields();
int index = 0;
IFieldDescription iFieldDescriptions[] = new IFieldDescription[fields.length];
_iFieldDescriptionsByName = new Hashtable();
_memberTypeInfosByName = new Hashtable();
for(int i = 0; i < fields.length; ++ i) {
MemberTypeInfo memberTypeInfo = null;
if((fields[i].getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) == 0) { // neither static nor transient ?
if(_superType != null)
memberTypeInfo = _superType.getMemberTypeInfo(fields[i].getName());
IFieldDescription iFieldDescription = null;
if(memberTypeInfo == null)
memberTypeInfo = __findMemberTypeInfo(typeInfos, fields[i].getName());
if(_superType != null)
iFieldDescription = _superType.getFieldDescription(fields[i].getName());
if(memberTypeInfo == null)
memberTypeInfo = new MemberTypeInfo(fields[i].getName(), 0);
if(iFieldDescription == null) {
MemberTypeInfo memberTypeInfo = __findMemberTypeInfo(typeInfos, fields[i].getName());
_memberTypeInfosByName.put(memberTypeInfo.getName(), memberTypeInfo);
if(memberTypeInfo == null)
memberTypeInfo = new MemberTypeInfo(fields[i].getName(), 0);
iFieldDescription = new FieldDescription(memberTypeInfo, fields[i]);
}
_iFieldDescriptionsByName.put(iFieldDescription.getName(), iFieldDescription);
iFieldDescriptions[index ++] = iFieldDescription;
}
}
_iFieldDescriptions = new IFieldDescription[index];
System.arraycopy(iFieldDescriptions, 0, _iFieldDescriptions, 0, index);
}
public TypeDescription getSuperType() {
public ITypeDescription getSuperType() {
return _superType;
}
public MethodDescription []getMethodDescriptions() {
public IMethodDescription []getMethodDescriptions() {
_initMethodTypeInfos();
MethodDescription methodDescriptions[] = null;
IMethodDescription iMethodDescriptions[] = null;
if(_methodDescriptionsByIndex != null) {
methodDescriptions = new MethodDescription[_methodDescriptionsByIndex.length];
iMethodDescriptions = new IMethodDescription[_methodDescriptionsByIndex.length];
System.arraycopy(_methodDescriptionsByIndex, 0, methodDescriptions, 0, _methodDescriptionsByIndex.length);
System.arraycopy(_methodDescriptionsByIndex, 0, iMethodDescriptions, 0, _methodDescriptionsByIndex.length);
}
return methodDescriptions;
return iMethodDescriptions;
}
public MethodDescription getMethodDescription(int methodId) {
public IMethodDescription getMethodDescription(int methodId) {
_initMethodTypeInfos();
MethodDescription methodDescription = null;
IMethodDescription iMethodDescription = null;
int relMethodId = methodId - (_offset - _methodDescriptionsByIndex.length);
if(relMethodId >= 0 && relMethodId < _methodDescriptionsByIndex.length)
methodDescription = _methodDescriptionsByIndex[relMethodId];
else if(_superType != null)
methodDescription = _superType.getMethodDescription(methodId);
iMethodDescription = _methodDescriptionsByIndex[relMethodId];
return methodDescription;
else if(_superType != null)
iMethodDescription = _superType.getMethodDescription(methodId);
return iMethodDescription;
}
public MethodDescription getMethodDescription(String name) {
public IMethodDescription getMethodDescription(String name) {
_initMethodTypeInfos();
MethodDescription methodDescription = (MethodDescription)_methodDescriptionsByName.get(name);
if(methodDescription == null && _superType != null)
methodDescription = _superType.getMethodDescription(name);
IMethodDescription iMethodDescription = (MethodDescription)_methodDescriptionsByName.get(name);
if(iMethodDescription == null && _superType != null)
iMethodDescription = _superType.getMethodDescription(name);
return methodDescription;
return iMethodDescription;
}
public MemberTypeInfo []getMemberTypeInfos() {
MemberTypeInfo memberTypeInfos[] = null;
if(_memberTypeInfosByName != null) {
memberTypeInfos = new MemberTypeInfo[_memberTypeInfosByName.size()];
Enumeration elements = _memberTypeInfosByName.elements();
int i = 0;
while(elements.hasMoreElements()) {
memberTypeInfos[i ++] = (MemberTypeInfo)elements.nextElement();
}
}
return memberTypeInfos;
public IFieldDescription []getFieldDescriptions() {
return _iFieldDescriptions;
}
public MemberTypeInfo getMemberTypeInfo(String name) {
MemberTypeInfo memberTypeInfo = (MemberTypeInfo)_memberTypeInfosByName.get(name);
if(memberTypeInfo == null && _superType != null)
memberTypeInfo = _superType.getMemberTypeInfo(name);
public IFieldDescription getFieldDescription(String name) {
IFieldDescription iFieldDescription = (IFieldDescription)_iFieldDescriptionsByName.get(name);
if(iFieldDescription == null && _superType != null)
iFieldDescription = _superType.getFieldDescription(name);
return memberTypeInfo;
}
public Field []getFields() {
return _fields;
return iFieldDescription;
}
/**
@ -859,14 +862,14 @@ public class TypeDescription {
* <p>
* @return the <code>TypeDescription</code>
*/
public TypeDescription getComponentType() {
TypeDescription componentTypeDescription = null;
public ITypeDescription getComponentType() {
ITypeDescription iTypeDescription = null;
Class componentClass = getZClass().getComponentType();
if(componentClass != null)
componentTypeDescription = getTypeDescription(componentClass);
iTypeDescription = getTypeDescription(componentClass);
return componentTypeDescription;
return iTypeDescription;
}
/**

View File

@ -2,9 +2,9 @@
*
* $RCSfile: Any.java,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: kr $ $Date: 2001-01-16 17:49:37 $
* last change: $Author: kr $ $Date: 2001-05-08 09:34:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -67,7 +67,7 @@ package com.sun.star.uno;
* The UNO IDL type any is mapped to java type <code>java.lang.Object</code>.
* In special cases it is necessary to have an explicit any.
* <p>
* @version $Revision: 1.2 $ $ $Date: 2001-01-16 17:49:37 $
* @version $Revision: 1.3 $ $ $Date: 2001-05-08 09:34:18 $
* @author Kay Ramme
* @since UDK1.0
*/
@ -95,13 +95,7 @@ public class Any {
* @deprecated as of UDK 2.0
*/
public Any(Class zInterface, Object object) {
try {
_type = new Type(zInterface);
}
catch(Throwable throwable) { // can not happen!
System.err.println(getClass().getName() + ".<init> - unexpected exception:" + throwable);
}
_type = new Type(zInterface);
_object = object;
}
@ -110,26 +104,6 @@ public class Any {
_object = object;
}
/**
* Gets the type of the any.
* <p>
* @deprecated as of UDK 2.0
* <p>
* @return the type of the any.
*/
public Class getInterface() {
Class zClass = null;
try {
zClass = _type.getDescription();
}
catch(ClassNotFoundException classNotFoundException) { // can not happen
System.err.println(getClass().getName() + ".getInterface - unexpected exception:" + classNotFoundException);
}
return zClass;
}
/**
* Gets the type of the any.
* <p>

View File

@ -0,0 +1,89 @@
/*************************************************************************
*
* $RCSfile: IFieldDescription.java,v $
*
* $Revision: 1.1 $
*
* last change: $Author: kr $ $Date: 2001-05-08 09:34:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
package com.sun.star.uno;
import java.lang.reflect.Field;
/**
* The <code>IFieldDescription</code> describes non
* method members.
* <p>
* @version $Revision: 1.1 $ $ $Date: 2001-05-08 09:34:18 $
* @author Kay Ramme
* @since UDK3.0
*/
public interface IFieldDescription extends IMemberDescription {
/**
* Gives the name of this member.
* <p>
* @return the name
*/
ITypeDescription getTypeDescription();
/**
* Gives native java field of this member.
* <p>
* @return the java field
*/
Field getField();
}

View File

@ -0,0 +1,100 @@
/*************************************************************************
*
* $RCSfile: IMemberDescription.java,v $
*
* $Revision: 1.1 $
*
* last change: $Author: kr $ $Date: 2001-05-08 09:34:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
package com.sun.star.uno;
/**
* The <code>IMemberDescription</code> is the base interface
* for members of UNO types <code>ITypeDescriptions</code>.
* <p>
* @version $Revision: 1.1 $ $ $Date: 2001-05-08 09:34:18 $
* @author Kay Ramme
* @since UDK3.0
*/
public interface IMemberDescription {
/**
* Gives the name of this member.
* <p>
* @return the name
*/
String getName();
/**
* Indicates if this member is unsigned.
* <p>
* @return the unsigned state
*/
boolean isUnsigned();
/**
* Indicates if this member is an any.
* <p>
* @return the any state
*/
boolean isAny();
/**
* Indicates if this member is an interface.
* <p>
* @return the interface state
*/
boolean isInterface();
}

View File

@ -0,0 +1,130 @@
/*************************************************************************
*
* $RCSfile: IMethodDescription.java,v $
*
* $Revision: 1.1 $
*
* last change: $Author: kr $ $Date: 2001-05-08 09:34:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
package com.sun.star.uno;
import java.lang.reflect.Method;
/**
* The <code>IMethodDescription</code> allows to examine a method
* in detail. It gives a view to java methods from a UNO point.
* <p>
* @version $Revision: 1.1 $ $ $Date: 2001-05-08 09:34:18 $
* @author Kay Ramme
* @since UDK3.0
*/
public interface IMethodDescription extends IMemberDescription {
/**
* Indicates if this method is <code>oneWay</code>,
* respectivly if this method may become executed asynchronously.
* <p>
* @return true means may execute asynchronously .
*/
boolean isOneway();
/**
* Gives the relative index of this method in the declaring
* interface.
* <p>
* @return the realtive index of this method
*/
int getIndex();
/**
* Indicates if this method is const.
* <p>
* @return true means it is const.
*/
boolean isConst();
/**
* Gives any array of <code>ITypeDescription> of
* the [in] parameters.
* <p>
* @return the in parameters
*/
ITypeDescription[] getInSignature();
/**
* Gives any array of <code>ITypeDescription> of
* the [out] parameters.
* <p>
* @return the out parameters
*/
ITypeDescription[] getOutSignature();
/**
* Gives the <code>ITypeDescription</code> of
* the return type.
* <p>
* @return the return type <code>ITypeDescription</code>
*/
ITypeDescription getReturnSignature();
/**
* Gives native java method of this method.
* <p>
* @return the java methodd
*/
Method getMethod();
}

View File

@ -0,0 +1,161 @@
/*************************************************************************
*
* $RCSfile: ITypeDescription.java,v $
*
* $Revision: 1.1 $
*
* last change: $Author: kr $ $Date: 2001-05-08 09:34:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
package com.sun.star.uno;
/**
* The <code>ITypeDescription</code> allows to examine a type
* in detail (e.g. it is used for marshaling/unmarshaling).
* <p>
* @version $Revision: 1.1 $ $ $Date: 2001-05-08 09:34:18 $
* @author Kay Ramme
* @since UDK3.0
*/
public interface ITypeDescription {
/**
* Gets the <code>ITypeDescription</code> of the
* super, if it exists.
* <p>
* @return the <code>ITypeDescription</code>.
*/
ITypeDescription getSuperType();
/**
* Gets the <code>IMethodDescription</code> for every
* method, if this type is an interface. Otherwise
* returns <code>null</code>.
* <p>
* @return the <code>IMethodDescription[]</code>.
*/
IMethodDescription []getMethodDescriptions();
/**
* Gets the <code>IMethodDescription</code> for the
* method with index methodId, if it exists, otherwise
* returns <code>null</code>.
* <p>
* @return the <code>IMethodDescription</code>.
*/
IMethodDescription getMethodDescription(int methodId);
/**
* Gets the <code>IMethodDescription</code> for the
* method with the name <code>name</code>, if it exists,
* otherwise returns <code>null</code>.
* <p>
* @return the <code>IMethodDescription</code>.
*/
IMethodDescription getMethodDescription(String name);
/**
* Gets the <code>IFieldDescription</code> for every
* field, if this type is an interface. Otherwise
* returns <code>null</code>.
* <p>
* @return the <code>IFieldDescription[]</code>.
*/
IFieldDescription []getFieldDescriptions();
/**
* Gets the <code>IFieldDescription</code> for the
* field with the name <code>name</code>, if it exists,
* otherwise returns <code>null</code>.
* <p>
* @return the <code>IFieldDescription</code>.
*/
IFieldDescription getFieldDescription(String name);
/**
* Gets the IDL <code>TypeClass</code> of the type.
* <p>
* @return the <code>TypeClass</code>.
*/
TypeClass getTypeClass();
/**
* Gets the component <code>ITypeDescription</code> if
* this is an array type, otherwise returns <code>null</code>.
* <p>
* @return the <code>ITypeDescription</code>
*/
ITypeDescription getComponentType();
/**
* Gets the type name.
* <p>
* @return the type name.
*/
String getTypeName();
/**
* Gets the array type name.
* <p>
* @return the array type name.
*/
String getArrayTypeName();
/**
* Gets the corresponding java class for the type.
* <p>
* @return the corresponding java class.
*/
Class getZClass();
}

View File

@ -2,9 +2,9 @@
*
* $RCSfile: Type.java,v $
*
* $Revision: 1.4 $
* $Revision: 1.5 $
*
* last change: $Author: kr $ $Date: 2001-02-19 10:07:03 $
* last change: $Author: kr $ $Date: 2001-05-08 09:34:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -62,9 +62,8 @@
package com.sun.star.uno;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
//import java.lang.reflect.InstantiationException;
import java.util.Hashtable;
/**
* The Type class represents the IDL builtin type <code>type</code>.
@ -72,13 +71,9 @@ import java.lang.reflect.InvocationTargetException;
* The IDL type is not directly mapped to <code>java.lang.Class</code>,
* because it can be necessary to describe a type which is unknown
* to the java runtime system, e.g. for delaying the need of a class,
* so that it is possible to generate it one the fly.
* so that it is possible to generate it on the fly.
* <p>
* The current implementations holds various <code>static</code> helper
* methods, which may be changed or moved in the furture, so please
* do not use these methods.
* <p>
* @version $Revision: 1.4 $ $ $Date: 2001-02-19 10:07:03 $
* @version $Revision: 1.5 $ $ $Date: 2001-05-08 09:34:18 $
* @author Markus Meyer
* @author Kay Ramme
* @since UDK1.0
@ -87,326 +82,237 @@ public class Type {
/**
* When set to true, enables various debugging output.
*/
public static final boolean DEBUG = false;
private static final boolean DEBUG = false;
static private Method __getFromClass;
static private Method __getFromName;
static private Method __getFromTypeClass;
static private final String[] __typeClassToTypeName = new String[]{
"void",
"char",
"boolean",
"byte",
"short",
"unsigned short",
"long",
"unsigned long",
"hyper",
"unsigned hyper",
"float",
"double",
"string",
"type",
"any"
};
/* these variables will be removed with UDK 3.0 */
static private Method __isTypeClassSimple;
static private Method __getTypeClass;
static private Method __getTypeName;
static private Method __getArrayTypeName;
static private Method __getZClass;
static private final Hashtable __javaClassToTypeName = new Hashtable();
static private final Hashtable __typeNameToTypeClass = new Hashtable();
static {
if(DEBUG) System.err.println("##### com.sun.star.uno.Type.<sinit>");
for(int i = 0; i < __typeClassToTypeName.length; ++ i)
__typeNameToTypeClass.put(__typeClassToTypeName[i], TypeClass.fromInt(i));
Throwable throwable = null;
try {
Class typeDesc_Class = Class.forName("com.sun.star.lib.uno.typedesc.TypeDescription");
__getFromName = typeDesc_Class.getMethod("getTypeDescription", new Class[]{String.class});
__getFromClass = typeDesc_Class.getMethod("getTypeDescription", new Class[]{Class.class});
__getFromTypeClass = typeDesc_Class.getMethod("getTypeDescription", new Class[]{TypeClass.class});
__isTypeClassSimple = typeDesc_Class.getMethod("isTypeClassSimple", new Class[]{TypeClass.class});
__getTypeClass = typeDesc_Class.getMethod("getTypeClass", new Class[]{});
__getTypeName = typeDesc_Class.getMethod("getTypeName", new Class[]{});
__getArrayTypeName = typeDesc_Class.getMethod("getArrayTypeName", new Class[]{});
__getZClass = typeDesc_Class.getMethod("getZClass", new Class[]{});
}
catch(NoSuchMethodException noSuchMethodException) {
throwable = noSuchMethodException;
}
catch(ClassNotFoundException classNotFoundException) {
throwable = classNotFoundException;
}
if(throwable != null) {
String message = "com.sun.star.uno.Type.<sinit> - exception:" + throwable;
throwable.printStackTrace();
System.err.println(message);
throw new java.lang.RuntimeException(message);
}
__javaClassToTypeName.put(Void.class, "void");
__javaClassToTypeName.put(void.class, "void");
__javaClassToTypeName.put(Character.class, "char");
__javaClassToTypeName.put(char.class, "char");
__javaClassToTypeName.put(Boolean.class, "boolean");
__javaClassToTypeName.put(boolean.class, "boolean");
__javaClassToTypeName.put(Byte.class, "byte");
__javaClassToTypeName.put(byte.class, "byte");
__javaClassToTypeName.put(Short.class, "short");
__javaClassToTypeName.put(short.class, "short");
__javaClassToTypeName.put(Integer.class, "long");
__javaClassToTypeName.put(int.class, "long");
__javaClassToTypeName.put(Long.class, "hyper");
__javaClassToTypeName.put(long.class, "hyper");
__javaClassToTypeName.put(Float.class, "float");
__javaClassToTypeName.put(float.class, "float");
__javaClassToTypeName.put(Double.class, "double");
__javaClassToTypeName.put(double.class, "double");
__javaClassToTypeName.put(String.class, "string");
__javaClassToTypeName.put(Type.class, "type");
__javaClassToTypeName.put(Any.class, "any");
__javaClassToTypeName.put(Object.class, "any");
}
static private boolean __isTypeClassPrimitive(TypeClass typeClass) {
return typeClass.getValue() < 15;
}
protected String _typeName;
protected Class _class;
protected TypeClass _typeClass;
protected ITypeDescription _iTypeDescription;
/**
* Determines if the given <code>TypeClass</code> is simple.
* Constructs a new <code>Type</code> which defaults
* to <code>void</code>
* <p>
* @deprecated as of UDK 2.0 (moved to com.sun.star.lib.uno.typedesc.TypeDescription)
* <p>
* @return <code>true</code> means simple
* @param typeClass the IDL typeClass
* @since UDK3.0
*/
static public boolean isTypeClassSimple(TypeClass typeClass) {
boolean isSimple = false;
try {
isSimple = ((Boolean)__isTypeClassSimple.invoke(null, new Object[]{typeClass})).booleanValue();
}
catch(IllegalAccessException illegalAccessException) {
}
catch(InvocationTargetException invocationTargetException) {
}
return isSimple;
public Type() {
this(void.class);
}
/**
* Constructs a new <code>Type</code> with
* the given <code>class</code>.
* <p>
* @since UDK3.0
* @param zClass the class of this type
*/
public Type(Class zClass) {
_class = zClass;
protected Object _typeDescription;
_typeName = (String)__javaClassToTypeName.get(zClass);
if(_typeName != null)
_typeClass = (TypeClass)__typeNameToTypeClass.get(_typeName);
protected void init(Class zClass) {
Throwable throwable = null;
try {
_typeDescription = __getFromClass.invoke(null, new Object[]{zClass});
else {
if(Enum.class.isAssignableFrom(zClass)) {
_typeClass = TypeClass.ENUM;
_typeName = zClass.getName();
}
else if(Union.class.isAssignableFrom(zClass)) {
_typeClass = TypeClass.UNION;
_typeName = zClass.getName();
}
else if(zClass.isInterface()) {
_typeClass = TypeClass.INTERFACE;
_typeName = zClass.getName();
}
else if(zClass.isArray()) {
_typeClass = TypeClass.SEQUENCE;
_typeName = "[]" + (new Type(_class.getComponentType()).getTypeName());
}
else if(Throwable.class.isAssignableFrom(zClass)) {
_typeClass = TypeClass.EXCEPTION;
_typeName = zClass.getName();
}
else {
_typeClass = TypeClass.UNKNOWN;
_typeName = zClass.getName();
}
}
catch(InvocationTargetException invocationTargetException) {
throwable = invocationTargetException.getTargetException();
}
catch(IllegalAccessException illegalAccessException) {
throwable = illegalAccessException;
}
if(throwable != null)
throw new java.lang.RuntimeException(getClass().getName() + ".<init>(Class) - fatal - couldn't create typedescription - " + throwable + " " + zClass);
}
protected void init(TypeClass typeClass) {
Throwable throwable = null;
try {
_typeDescription = __getFromTypeClass.invoke(null, new Object[]{typeClass});
}
catch(InvocationTargetException invocationTargetException) {
throwable = invocationTargetException.getTargetException();
}
catch(IllegalAccessException illegalAccessException) {
throwable = illegalAccessException;
}
if(throwable != null)
throw new java.lang.RuntimeException(getClass().getName() + ".<init>(TypeClass) - fatal - couldn't create typedescription - " + throwable + " " + typeClass);
}
protected void init(String typeName) throws ClassNotFoundException {
Throwable throwable = null;
try {
_typeDescription = __getFromName.invoke(null, new Object[]{typeName});
}
catch(InvocationTargetException invocationTargetException) {
throwable = invocationTargetException.getTargetException();
}
catch(IllegalAccessException illegalAccessException) {
throwable = illegalAccessException;
}
if(throwable != null)
throw new java.lang.ClassNotFoundException(getClass().getName() + ".<init>(String) - fatal - couldn't create typedescription - " + throwable);
}
/**
* Constructs a new <code>Type</code> with
* the given type description.
* <p>
* @since UDK3.0
* @param typeDescription a type description
*/
public Type(Object typeDescription) {
_typeDescription = typeDescription;
}
/**
* Constructs a new <code>Type</code> which defaults
* to <code>void</code>
* <p>
*/
public Type() {
init(void.class);
}
/**
* Constructs a new <code>Type</code> with
* the given <code>class</code>.
* <p>
* @param zClass the class of this type
*/
public Type(Class zClass) throws Exception { // the exception is only for compatibility reasons
init(zClass);
public Type(ITypeDescription iTypeDescription) {
_typeName = iTypeDescription.getTypeName();
_typeClass = iTypeDescription.getTypeClass();
_iTypeDescription = iTypeDescription;
}
/**
* Constructs a new <code>Type</code> with
* the given type name.
* <p>
* @since UDK3.0
* @param typeName the name of this type
*/
public Type(String typeName) throws com.sun.star.uno.Exception, ClassNotFoundException { // the com.sun.star.uno.Exception is only for compatibility reasons
init(typeName);
public Type(String typeName) {
_typeClass = (TypeClass)__typeNameToTypeClass.get(typeName);
if(_typeClass == null)
_typeClass = TypeClass.UNKNOWN;
_typeName = typeName;
}
/**
* Constructs a new <code>Type</code> with
* the given <code>TypeClass</code>.
* <p>
* @since UDK3.0
* @param typeClass the <code>TypeClass</code> of this type
*/
public Type(TypeClass typeClass) throws com.sun.star.uno.Exception {
init(typeClass);
}
/**
* @deprecated as of UDK 2.0
*/
public Type(TypeClass typeClass, String typeName) throws com.sun.star.uno.Exception {
if(typeName != null) {
try {
init(typeName);
}
catch(ClassNotFoundException classNotFoundException) {
throw new Exception(classNotFoundException.toString());
}
public Type(TypeClass typeClass) throws IllegalArgumentException {
if(__isTypeClassPrimitive(typeClass)) {
_typeClass = typeClass;
_typeName = __typeClassToTypeName[typeClass.getValue()];
}
else
init(typeClass);
throw new IllegalArgumentException(typeClass + " is not primitive");
}
/**
* @deprecated as of UDK 2.0
*/
public Type(TypeClass typeClass, String typeName, Class zClass) throws com.sun.star.uno.Exception {
this(typeClass, typeName);
}
/**
* @deprecated as of UDK 2.0
*/
public Type(TypeClass typeClass, String typeName, String arrayTypeName, Class zClass) throws com.sun.star.uno.Exception {
this(typeClass, typeName);
}
/**
* Gives the the type description of this type.
* Gives the type description of this type.
* <p>
* @since UDK3.0
* @return the type description
*/
public Object getTypeDescription() {
return _typeDescription;
public ITypeDescription getTypeDescription() {
return _iTypeDescription;
}
/**
* Gets the IDL <code>TypeClass</code> of the type.
* Sets the type description for this type.
* <p>
* @deprecated as of UDK 2.0
* <p>
* @return the <code>TypeClass</code>.
* @since UDK3.0
* @return the type description
*/
public TypeClass getTypeClass() {
TypeClass typeClass = null;
try {
typeClass = (TypeClass)__getTypeClass.invoke(_typeDescription, null);
}
catch(IllegalAccessException illegalAccessException) {
}
catch(InvocationTargetException invocationTargetException) {
}
return typeClass;
public void setTypeDescription(ITypeDescription iTypeDescription) {
_iTypeDescription = iTypeDescription;
}
/**
* Gets the type name.
* Returns <code>null</code> if this
* type has not been constructed by name.
* <p>
* @deprecated as of UDK 2.0
* <p>
* @since UDK1.0
* @return the type name.
*/
public String getTypeName() {
String typeName = null;
try {
typeName = (String)__getTypeName.invoke(_typeDescription, null);
}
catch(IllegalAccessException illegalAccessException) {
}
catch(InvocationTargetException invocationTargetException) {
}
return typeName;
}
/**
* Gets the array type name.
* <p>
* @deprecated as of UDK 2.0
* <p>
* @return the array type name.
*/
public String getArrayTypeName() {
String arrayTypeName = null;
try {
arrayTypeName = (String)__getArrayTypeName.invoke(_typeDescription, null);
}
catch(IllegalAccessException illegalAccessException) {
}
catch(InvocationTargetException invocationTargetException) {
}
return arrayTypeName;
return _typeName;
}
/**
* Gets the corresponding java class for the type.
* Gets the class.
* Returns <code>null</code> if this
* type has not been constructed by <code>Class</code>.
* <p>
* @deprecated as of UDK 2.0
* <p>
* @return the corresponding java class.
* @since UDK1.0
* @return the type name.
*/
public Class getDescription() throws ClassNotFoundException {
Class zClass = null;
try {
zClass = (Class)__getZClass.invoke(_typeDescription, null);
}
catch(IllegalAccessException illegalAccessException) {
}
catch(InvocationTargetException invocationTargetException) {
}
return zClass;
public Class getZClass() {
return _class;
}
/**
* Gets the typeClass.
* Returns <code>null</code> if this
* type has not been constructed by <code>TypeClass</code>.
* <p>
* @since UDK1.0
* @return the type name.
*/
public TypeClass getTypeClass() {
return _typeClass;
}
/**
* Compares two types.
* <p>
* @return true, if the given type and this type are equal
*/
public boolean equals(Object type) {
public boolean equals(Object object) {
boolean result = false;
if(type != null) {
result = _typeDescription == ((Type)type)._typeDescription;
Type type = (Type)object;
if(!result && _typeDescription != null)
result = _typeDescription.equals(((Type)type)._typeDescription);
}
if(type != null)
result = _typeName.equals(type._typeName);
return result;
}
@ -417,7 +323,7 @@ public class Type {
* @return the hash code
*/
public int hashCode() {
return _typeDescription.hashCode();
return _typeName.hashCode();
}
/**
@ -426,7 +332,7 @@ public class Type {
* @return a descriptive <code>String</code>
*/
public String toString() {
return "Type<" + _typeDescription + ">";
return "Type<" + _typeName + ">";
}
}