/** * Create a new extractor. */ public MultifieldExtractor(int tupleindex, OAVAttributeType attr, int subindex) { assert attr!=null && !OAVAttributeType.NONE.equals(attr.getMultiplicity()); this.tupleindex = tupleindex; this.attr = attr; this.subindex = subindex; }
/** * Get the string representation. * @return The string representation. */ public String toString() { return "["+tupleindex+"]"+"."+(attr==null? "object": attr.getName())+(key==null? "": "["+key+"]"); }
/** * Get the default value. */ protected Object getDefaultValue(Object property) { Object ret = null; if(property instanceof OAVAttributeType) ret = ((OAVAttributeType)property).getDefaultValue(); else ret = super.getDefaultValue(property); return ret; }
/** * Ensure that a type has an attribute. * @param object The object. * @param attribute The attribute. * @throws RuntimeException if value is not allowed. */ protected boolean checkTypeHasAttribute(Object object, OAVAttributeType attribute) { if(attribute==null) throw new IllegalArgumentException("Attribute must not null."); OAVObjectType type = attribute.getObjectType() instanceof OAVJavaType ? tmodel.getJavaType(object.getClass()) : (OAVObjectType)types.get(object); if(type==null) throw new RuntimeException("Unknown object type of: "+object); OAVAttributeType attr = type.getAttributeType(attribute.getName()); if(!attribute.equals(attr)) throw new RuntimeException("Attribute must belong to object type: "+attribute+", "+type); return true; }
/** * Test if a value is decodable to the same type. * Works for basic (final) types only and checks if the * two types are of same class. */ protected boolean isDecodableToSameType(Object property, Object value, IContext context) { boolean ret = true; if(value!=null) { OAVAttributeType attr = (OAVAttributeType)property; ret = value.getClass().equals(((OAVJavaType)attr.getType()).getClazz()); } return ret; } }
String mult = attribute.getMultiplicity(); if(OAVAttributeType.LIST.equals(mult)) tmp = new ArrayList(); OAVAttributeType keyattr = attribute.getIndexAttribute(); if(keyattr==null) throw new RuntimeException("Index attribute not specified: "+attribute);
if(OAVAttributeType.NONE.equals(attribute.getMultiplicity())) if(!(attribute.getType() instanceof OAVJavaType)) child = new ObjectNode(this, child); else if(isInspectable(child)) if(!(attribute.getType() instanceof OAVJavaType)) child = new ObjectNode(this, child); else if(isInspectable(child))
/** * Test if two objects are equal. */ public boolean equals(Object obj) { if(this == obj) return true; boolean ret = false; if(obj instanceof OAVObjectUsage) { final OAVObjectUsage other = (OAVObjectUsage)obj; ret = object.equals(other.getObject()) && attr.equals(other.getAttribute()); } return ret; }
/** * Test for equality. * @return True, if equal. */ public boolean equals(Object obj) { boolean ret = this==obj; if(!ret && obj!=null && obj.getClass().equals(this.getClass())) { OAVAttributeType attr = (OAVAttributeType)obj; if(SUtil.equals(name, attr.getName()) && SUtil.equals(otype, attr.getObjectType())) { ret = true; } } return ret; } }
/** * Compute the hascode. * @return The hashcode. */ public int hashCode() { int ret; if(!attribute.getMultiplicity().equals(OAVAttributeType.NONE)) { ret = super.hashCode(); } else { final int prime = 31; ret = prime * id.hashCode(); ret = prime * ret + type.hashCode(); ret = prime * ret + attribute.hashCode(); } return ret; }
/** * The hash code. */ public int hashCode() { int result = 31 + (attr!=null ? attr.hashCode() : 0); result = result*31 + tupleindex; result = result*31 + subindex; return result; }
/** * Create a new attribute type. * @param name The name. * @param type The type. * @param mult The multiplicity. * @param def The default value. */ public OAVAttributeType createAttributeType(String name, OAVObjectType type, String mult, Object def, OAVAttributeType idxattr) { if(!tmodel.contains(type)) throw new RuntimeException("Unknown object type: "+type); OAVAttributeType attr = new OAVAttributeType(this, name, type, mult, def, idxattr); addAttributeType(attr); return attr; }
/** * Test if an attribute is contained in the attribute set. * @param attr The attribute. * @return True, if contained. */ public boolean contains(OAVAttributeType attr) { boolean ret = attributes==null? false: attributes.contains(attr); if(!ret && alltypes!=null && attr.getObjectType() instanceof OAVJavaType) { ret = alltypes.contains(attr.getObjectType()); if(!ret) { OAVJavaType attrtype = (OAVJavaType)attr.getObjectType(); for(Iterator it=alltypes.iterator(); it.hasNext() && !ret; ) { OAVJavaType type = (OAVJavaType)it.next(); ret = attrtype.isSubtype(type); } } } // todo: build up negative list for already tested java types to improve performance. return ret; }
for(int i=0; i<aprecands.length; i++) Object key = state.getAttributeValue(aprecands[i], OAVBDIRuntimeModel.capability_has_precandidates.getIndexAttribute()); state.removeAttributeValue(rcapa, OAVBDIRuntimeModel.capability_has_precandidates, key);
/** * Create a new OAV attribute type. * @param otype The object type holding the attribute. * @param name The name of the OAV attribute type. * @param mult The multiplicity. * @param type The type. * @param def The default value. */ protected OAVAttributeType(OAVObjectType otype, String name, OAVObjectType type, String mult, Object def, OAVAttributeType idxattr) { if(otype==null || type==null) throw new IllegalArgumentException("Type must not be null."); if(!MULTIPLICITIES_ALL.contains(mult)) throw new IllegalArgumentException("Type must be one of: "+MULTIPLICITIES_ALL+" "+mult); this.otype = otype; this.name = name; this.mult = mult; this.type = type; this.def = def; this.idxattr = idxattr; this.hashcode = calcHashCode(); }
/** * Ensure that a type has an attribute. * @param object The object. * @param attribute The attribute. * @throws RuntimeException if value is not allowed. */ protected boolean checkTypeHasAttribute(Object object, OAVAttributeType attribute) { if(attribute==null) throw new IllegalArgumentException("Attribute must not null."); OAVObjectType type = attribute.getObjectType() instanceof OAVJavaType ? tmodel.getJavaType(object.getClass()) : (OAVObjectType)types.get(object); if(type==null) throw new RuntimeException("Unknown object type of: "+object); OAVAttributeType attr = type.getAttributeType(attribute.getName()); if(!attribute.equals(attr)) throw new RuntimeException("Attribute must belong to object type: "+attribute+", "+type); return true; }
/** * Test if a value is decodable to the same type. * Works for basic (final) types only and checks if the * two types are of same class. */ protected boolean isDecodableToSameType(Object property, Object value, IContext context) { boolean ret = true; if(value!=null) { OAVAttributeType attr = (OAVAttributeType)property; ret = value.getClass().equals(((OAVJavaType)attr.getType()).getClazz()); } return ret; } }
String mult = attribute.getMultiplicity(); if(OAVAttributeType.LIST.equals(mult)) tmp = new ArrayList(); OAVAttributeType keyattr = attribute.getIndexAttribute(); if(keyattr==null) throw new RuntimeException("Index attribute not specified: "+attribute);
/** * Test if two objects are equal. */ public boolean equals(Object obj) { if(this == obj) return true; boolean ret = false; if(obj instanceof OAVObjectUsage) { final OAVObjectUsage other = (OAVObjectUsage)obj; ret = object.equals(other.getObject()) && attr.equals(other.getAttribute()); } return ret; }
/** * Test for equality. * @return True, if equal. */ public boolean equals(Object obj) { boolean ret = this==obj; if(!ret && obj!=null && obj.getClass().equals(this.getClass())) { OAVAttributeType attr = (OAVAttributeType)obj; if(SUtil.equals(name, attr.getName()) && SUtil.equals(otype, attr.getObjectType())) { ret = true; } } return ret; } }