if (values != null && values.length > 0)
{
extensions = new HashSet<ExtensionMetaData>(values.length);
for (int j=0;j<values.length;j++)
{
ExtensionMetaData extmd = new ExtensionMetaData(values[j].vendorName(),
values[j].key().toString(), values[j].value().toString());
extensions.add(extmd);
}
}
}
else if (annName.equals(JDOAnnotationUtils.EXTENSION))
{
ExtensionMetaData extmd = new ExtensionMetaData((String)annotationValues.get("vendorName"),
(String)annotationValues.get("key"), (String)annotationValues.get("value"));
extensions = new HashSet<ExtensionMetaData>(1);
extensions.add(extmd);
}
else
{
NucleusLogger.METADATA.error(LOCALISER.msg("044203",
member.getName(), annotations[i].getName()));
}
}
}
if (mmd == null &&
(transactionalField || nonPersistentField || primaryKey || colmds != null || serialised ||
embeddedOwnerField != null || embeddedNullIndicatorColumn != null || embeddedNullIndicatorValue != null ||
embeddedMembers != null ||
elemmd != null || keymd != null || valuemd != null || ordermd != null ||
idxmd != null || unimd != null || fkmd != null || joinmd != null))
{
// @Persistent not supplied but other relevant annotations defined, so add default metadata element
if (member.isProperty())
{
mmd = new PropertyMetaData(cmd, member.getName());
}
else
{
mmd = new FieldMetaData(cmd, member.getName());
}
mmd.setPrimaryKey("" + primaryKey);
}
if (mmd != null)
{
cmd.addMember(mmd);
if (primaryKey)
{
mmd.setPrimaryKey(true);
}
if (serialised)
{
mmd.setSerialised(true);
}
if (nonPersistentField)
{
mmd.setNotPersistent();
}
if (transactionalField)
{
mmd.setTransactional();
}
// Add any embedded info
if (embeddedOwnerField != null || embeddedNullIndicatorColumn != null ||
embeddedNullIndicatorValue != null || embeddedMembers != null)
{
EmbeddedMetaData embmd = new EmbeddedMetaData();
embmd.setOwnerMember(embeddedOwnerField);
embmd.setNullIndicatorColumn(embeddedNullIndicatorColumn);
embmd.setNullIndicatorValue(embeddedNullIndicatorValue);
mmd.setEmbeddedMetaData(embmd);
if (embeddedMembers != null && embeddedMembers.length > 0)
{
for (int j=0;j<embeddedMembers.length;j++)
{
// Add the metadata for the embedded field/property to the embedded metadata
String memberName = embeddedMembers[j].name();
if (memberName.indexOf('.') > 0)
{
memberName = memberName.substring(memberName.lastIndexOf('.')+1);
}
AbstractMemberMetaData embfmd = getFieldMetaDataForPersistent(embmd, embeddedMembers[j],
isMemberOfClassAField(member.getType(), memberName));
embmd.addMember(embfmd);
}
}
}
// If the field is a container then add its container element
ContainerMetaData contmd = null;
if (Collection.class.isAssignableFrom(member.getType()))
{
Class collectionElementType = null;
StringBuffer elementTypeStr = new StringBuffer();
if (elementTypes != null && elementTypes.length > 0 && elementTypes[0] != void.class)
{
// User-specified element type(s)
for (int j=0;j<elementTypes.length;j++)
{
if (elementTypeStr.length() > 0)
{
elementTypeStr.append(',');
}
elementTypeStr.append(elementTypes[j].getName());
}
collectionElementType = elementTypes[0]; // Use the first only
}
else
{
// Try to derive element type from generics info
if (member.getGenericType() instanceof ParameterizedType)
{
ParameterizedType paramtype = (ParameterizedType)member.getGenericType();
if (paramtype.getActualTypeArguments().length == 1)
{
Type type = paramtype.getActualTypeArguments()[0];
if (type instanceof Class)
{
collectionElementType = (Class) type;
}
else if (type instanceof ParameterizedType)
{
collectionElementType = (Class) ((ParameterizedType)type).getRawType();
}
else
{
throw new IllegalStateException("Unknown type: " + type);
}
elementTypeStr.append(collectionElementType.getName());
}
}
}
contmd = new CollectionMetaData();
CollectionMetaData collmd = (CollectionMetaData)contmd;
collmd.setElementType(elementTypeStr.toString());
collmd.setEmbeddedElement(embeddedElement);
collmd.setSerializedElement(serializedElement);
collmd.setDependentElement(dependentElement);
// Add any embedded element mappings
if (embeddedElementMembers != null)
{
EmbeddedMetaData embmd = elemmd.getEmbeddedMetaData();
for (int j=0;j<embeddedElementMembers.length;j++)
{
// Add the metadata for the embedded element to the embedded metadata
String memberName = embeddedElementMembers[j].name();
if (memberName.indexOf('.') > 0)
{
memberName = memberName.substring(memberName.lastIndexOf('.')+1);
}
AbstractMemberMetaData embfmd = getFieldMetaDataForPersistent(embmd,
embeddedElementMembers[j],
isMemberOfClassAField(collectionElementType, memberName));
embmd.addMember(embfmd);
}
}
}
else if (member.getType().isArray())
{
StringBuffer elementTypeStr = new StringBuffer();
if (elementTypes != null && elementTypes.length > 0 && elementTypes[0] != void.class)
{
// User-specified element type(s)
for (int j=0;j<elementTypes.length;j++)
{
if (elementTypeStr.length() > 0)
{
elementTypeStr.append(',');
}
elementTypeStr.append(elementTypes[j].getName());
}
}
else
{
// Derive from component type
elementTypeStr.append(member.getType().getComponentType().getName());
}
contmd = new ArrayMetaData();
ArrayMetaData arrmd = (ArrayMetaData)contmd;
arrmd.setElementType(elementTypeStr.toString());
arrmd.setEmbeddedElement(embeddedElement);
arrmd.setSerializedElement(serializedElement);
arrmd.setDependentElement(dependentElement);
}
else if (Map.class.isAssignableFrom(member.getType()))
{
Class mapKeyType = null;
if (keyType != null && keyType != void.class)
{
// User-specified key type
mapKeyType = keyType;
}
else
{
// Try to derive key type from generics info
if (member.getGenericType() instanceof ParameterizedType)
{
ParameterizedType paramtype = (ParameterizedType)member.getGenericType();
if (paramtype.getActualTypeArguments().length == 2)
{
Type type = paramtype.getActualTypeArguments()[0];
if (type instanceof Class)
{
mapKeyType = (Class) type;
}
else if (type instanceof ParameterizedType)
{
mapKeyType = (Class) ((ParameterizedType)type).getRawType();
}
else
{
throw new IllegalStateException("Unknown type: " + type);
}
}
}
}
Class mapValueType = null;
if (valueType != null && valueType != void.class)
{
// User-specified value type
mapValueType = valueType;
}
else
{
// Try to derive value type from generics info
if (member.getGenericType() instanceof ParameterizedType)
{
ParameterizedType paramtype = (ParameterizedType)member.getGenericType();
if (paramtype.getActualTypeArguments().length == 2)
{
Type type = paramtype.getActualTypeArguments()[1];
if (type instanceof Class)
{
mapValueType = (Class) type;
}
else if (type instanceof ParameterizedType)
{
mapValueType = (Class) ((ParameterizedType)type).getRawType();
}
else
{
throw new IllegalStateException("Unknown type: " + type);
}
}
}
}
contmd = new MapMetaData();
MapMetaData mapmd = (MapMetaData)contmd;
mapmd.setKeyType((mapKeyType != null ? mapKeyType.getName() : null));
mapmd.setEmbeddedKey(embeddedKey);
mapmd.setSerializedKey(serializedKey);
mapmd.setDependentKey(dependentKey);
mapmd.setValueType((mapValueType != null ? mapValueType.getName() : null));
mapmd.setEmbeddedValue(embeddedValue);
mapmd.setSerializedValue(serializedValue);
mapmd.setDependentValue(dependentValue);
if (embeddedKeyMembers != null)
{
// Add any embedded key mappings
EmbeddedMetaData embmd = keymd.getEmbeddedMetaData();
for (int j=0;j<embeddedKeyMembers.length;j++)
{
// Add the metadata for the embedded key to the embedded metadata
String memberName = embeddedKeyMembers[j].name();
if (memberName.indexOf('.') > 0)
{
memberName = memberName.substring(memberName.lastIndexOf('.')+1);
}
AbstractMemberMetaData embfmd = getFieldMetaDataForPersistent(embmd, embeddedKeyMembers[j],
isMemberOfClassAField(mapKeyType, memberName));
embmd.addMember(embfmd);
}
}
if (embeddedValueMembers != null)
{
// Add any embedded value mappings
EmbeddedMetaData embmd = valuemd.getEmbeddedMetaData();
for (int j=0;j<embeddedValueMembers.length;j++)
{
// Add the metadata for the embedded value to the embedded metadata
String memberName = embeddedValueMembers[j].name();
if (memberName.indexOf('.') > 0)
{
memberName = memberName.substring(memberName.lastIndexOf('.')+1);
}
AbstractMemberMetaData embfmd = getFieldMetaDataForPersistent(embmd, embeddedValueMembers[j],
isMemberOfClassAField(mapValueType, memberName));
embmd.addMember(embfmd);
}
}
}
if (contmd != null)
{
mmd.setContainer(contmd);
if (elemmd != null)
{
elemmd.setParent(mmd);
mmd.setElementMetaData(elemmd);
}
if (keymd != null)
{
keymd.setParent(mmd);
mmd.setKeyMetaData(keymd);
}
if (valuemd != null)
{
valuemd.setParent(mmd);
mmd.setValueMetaData(valuemd);
}
if (ordermd != null)
{
ordermd.setParent(mmd);
mmd.setOrderMetaData(ordermd);
}
}
if (joinmd != null)
{
mmd.setJoinMetaData(joinmd);
}
if (colmds != null)
{
for (int i=0;i<colmds.length;i++)
{
mmd.addColumn(colmds[i]);
}
}
if (idxmd != null)
{
mmd.setIndexMetaData(idxmd);
}
if (unimd != null)
{
mmd.setUniqueMetaData(unimd);
}
if (fkmd != null)
{
mmd.setForeignKeyMetaData(fkmd);
}
if (cacheable != null && cacheable.equalsIgnoreCase("false"))
{
mmd.setCacheable(false);
}
if (extensions != null)
{
Iterator<ExtensionMetaData> iter = extensions.iterator();
while (iter.hasNext())
{
ExtensionMetaData extmd = iter.next();
mmd.addExtension(extmd.getVendorName(), extmd.getKey(), extmd.getValue());
}
}
}
}