1 23 24 package org.objectweb.fractal.julia.type; 25 26 import org.objectweb.fractal.api.Type; 27 import org.objectweb.fractal.api.type.InterfaceType; 28 29 import java.io.Serializable ; 30 31 34 35 public class BasicInterfaceType implements InterfaceType, Serializable { 36 37 40 41 private final static int CLIENT_FLAG = 1; 42 43 46 47 private final static int OPTIONAL_FLAG = 2; 48 49 52 53 private final static int COLLECTION_FLAG = 4; 54 55 58 59 private String name; 60 61 64 65 private String signature; 66 67 71 72 private int flags; 73 74 78 91 92 public BasicInterfaceType ( 93 final String name, 94 final String signature, 95 final boolean isClient, 96 final boolean isOptional, 97 final boolean isCollection) 98 { 99 int flags = 0; 100 flags = (isClient ? flags | CLIENT_FLAG : flags); 101 flags = (isOptional ? flags | OPTIONAL_FLAG : flags); 102 flags = (isCollection ? flags | COLLECTION_FLAG : flags); 103 this.name = name; 104 this.signature = signature; 105 this.flags = flags; 106 } 107 108 112 public String getFcItfName () { 113 return name; 114 } 115 116 public String getFcItfSignature () { 117 return signature; 118 } 119 120 public boolean isFcClientItf () { 121 return (flags & CLIENT_FLAG) != 0; 122 } 123 124 public boolean isFcOptionalItf () { 125 return (flags & OPTIONAL_FLAG) != 0; 126 } 127 128 public boolean isFcCollectionItf () { 129 return (flags & COLLECTION_FLAG) != 0; 130 } 131 132 public boolean isFcSubTypeOf (final Type type) { 133 if (type instanceof InterfaceType) { 134 InterfaceType t = (InterfaceType)type; 135 if (t.isFcClientItf() != isFcClientItf()) { 137 return false; 138 } 139 if (!t.getFcItfName().equals(getFcItfName())) { 141 return false; 142 } 143 if (t.isFcCollectionItf() && !isFcCollectionItf()) { 145 return false; 146 } 147 if (isFcClientItf()) { 149 if (t.isFcOptionalItf() && !isFcOptionalItf()) { 150 return false; 151 } 152 } else { 153 if (!t.isFcOptionalItf() && isFcOptionalItf()) { 154 return false; 155 } 156 } 157 if (t.getFcItfSignature().equals(getFcItfSignature())) { 159 return true; 160 } 161 if (t instanceof BasicInterfaceType) { 162 try { 163 Class c1 = Class.forName(signature); 164 Class c2 = Class.forName(((BasicInterfaceType)t).signature); 165 if (c1 != null && c2 != null && isFcClientItf()) { 166 return c1.isAssignableFrom(c2); 167 } else { 168 return c2.isAssignableFrom(c1); 169 } 170 } catch (ClassNotFoundException e) { 171 return true; 172 } 173 } 174 } 175 return false; 176 } 177 178 182 188 189 public boolean equals (final Object o) { 190 if (o instanceof InterfaceType) { 191 InterfaceType type = (InterfaceType)o; 192 if (getFcItfName().equals(type.getFcItfName()) && 193 isFcClientItf() == type.isFcClientItf() && 194 isFcOptionalItf() == type.isFcOptionalItf() && 195 isFcCollectionItf() == type.isFcCollectionItf()) 196 { 197 if (getFcItfName().equals("attribute-controller") || 198 getFcItfSignature().equals(type.getFcItfSignature())) 199 { 200 return true; 201 } 202 } 203 } 204 return false; 205 } 206 } 207 | Popular Tags |