package org.jboss.iiop.rmi;
import org.omg.CORBA.ORB;
import org.omg.CORBA.TCKind;
import org.omg.CORBA.TypeCode;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.Serializable;
import java.io.Externalizable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Iterator;
import java.util.WeakHashMap;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class InterfaceAnalysis
extends ContainerAnalysis
{
Map operationAnalysisMap;
private static final org.jboss.logging.Logger logger =
org.jboss.logging.Logger.getLogger(InterfaceAnalysis.class);
private static WorkCacheManager cache
= new WorkCacheManager(InterfaceAnalysis.class);
public static InterfaceAnalysis getInterfaceAnalysis(Class cls)
throws RMIIIOPViolationException
{
return (InterfaceAnalysis)cache.getAnalysis(cls);
}
protected InterfaceAnalysis(Class cls)
{
super(cls);
logger.debug("new InterfaceAnalysis: " + cls.getName());
}
protected void doAnalyze()
throws RMIIIOPViolationException
{
super.doAnalyze();
calculateOperationAnalysisMap();
fixupCaseNames();
}
public boolean isAbstractInterface()
{
return abstractInterface;
}
public boolean isRmiIdlRemoteInterface()
{
return (!abstractInterface);
}
public String[] getAllTypeIds()
{
if (allTypeIds == null)
logger.debug(cls + " null allTypeIds");
return (String[])allTypeIds.clone();
}
protected ArrayList getContainedEntries()
{
ArrayList ret = new ArrayList(constants.length +
attributes.length +
operations.length);
for (int i = 0; i < constants.length; ++i)
ret.add(constants[i]);
for (int i = 0; i < attributes.length; ++i)
ret.add(attributes[i]);
for (int i = 0; i < operations.length; ++i)
ret.add(operations[i]);
return ret;
}
protected void analyzeOperations()
throws RMIIIOPViolationException
{
logger.debug(cls + " analyzeOperations");
if (!cls.isInterface())
throw new IllegalArgumentException("Class \"" + cls.getName() +
"\" is not an interface.");
abstractInterface = RmiIdlUtil.isAbstractInterface(cls);
calculateAllTypeIds();
int operationCount = 0;
for (int i = 0; i < methods.length; ++i)
if ((m_flags[i] & (M_READ|M_WRITE|M_READONLY)) == 0)
++operationCount;
operations = new OperationAnalysis[operationCount];
operationCount = 0;
for (int i = 0; i < methods.length; ++i) {
if ((m_flags[i] & (M_READ|M_WRITE|M_READONLY)) == 0) {
operations[operationCount] = new OperationAnalysis(methods[i]);
++operationCount;
}
}
logger.debug(cls + " analyzeOperations operations=" + operations.length);
}
protected void calculateOperationAnalysisMap()
{
operationAnalysisMap = new HashMap();
OperationAnalysis oa;
for (int i = 0; i < operations.length; ++i) {
oa = operations[i];
operationAnalysisMap.put(oa.getIDLName(), oa);
}
for (int i = 0; i < attributes.length; ++i) {
AttributeAnalysis attr = attributes[i];
oa = attr.getAccessorAnalysis();
if (oa != null) {
operationAnalysisMap.put(oa.getIDLName(), oa);
oa = attr.getMutatorAnalysis();
if (oa != null)
operationAnalysisMap.put(oa.getIDLName(), oa);
}
}
}
protected void calculateAllTypeIds()
{
if (!isRmiIdlRemoteInterface()) {
allTypeIds = new String[0];
}
else {
ArrayList a = new ArrayList();
InterfaceAnalysis[] intfs = getInterfaces();
for (int i = 0; i < intfs.length; ++i) {
String[] ss = intfs[i].getAllTypeIds();
for (int j = 0; j < ss.length; ++j)
if (!a.contains(ss[j]))
a.add(ss[j]);
}
allTypeIds = new String[a.size() + 1];
allTypeIds[0] = getRepositoryId();
for (int i = 1; i <= a.size(); ++i)
allTypeIds[i] = (String)a.get(a.size()-i);
}
}
private boolean abstractInterface;
private String[] allTypeIds;
}