private void processOCDAttributes ( String currDefId , AttributeDefinition [ ] attrDefs , Map < String , AttributeDefinition > requiredAttributes , Map < String , AttributeDefinition > optionalAttributes , Map < String , ExtendedAttributeDefinition > attributeMap , boolean required ) { // We need to set the current Attributes Map to be the optional list if we're processing option attrs, or required otherwise. We set the // alternativeAttributes to be the other Map of attrs. Map < String , AttributeDefinition > currentAttributes ; Map < String , AttributeDefinition > alternateAttributes ; if ( required ) { currentAttributes = requiredAttributes ; alternateAttributes = optionalAttributes ; } else { currentAttributes = optionalAttributes ; alternateAttributes = requiredAttributes ; } // Iterate over the list of attributes for ( AttributeDefinition attrDef : attrDefs ) { String attrId = attrDef . getID ( ) ; ExtendedAttributeDefinition extendedAttr = attributeMap . get ( attrId ) ; String rename ; if ( extendedAttr != null ) { // If we have a final attr, we don't add it to the list of attrs to write out, and we should also // remove it from the existing list if it was defined in a super type. if ( extendedAttr . isFinal ( ) ) { currentAttributes . remove ( attrId ) ; alternateAttributes . remove ( attrId ) ; } else if ( ( rename = extendedAttr . getRename ( ) ) != null ) { // If we have a rename, then we should take the existing attr, and replace any values that are defined in // in the new attr. boolean alternativeAttr = false ; AttributeDefinition attrToRename = currentAttributes . get ( rename ) ; // if the attribute to rename is null, then it might be because it has been defined as an optional and is now a required attr, // or visa versa. Before we complain that the attr doesn't exist, check the other list of attrs to see if that is the case. // If so, remove the attr from whichever Map it has been defined in, and add it to the current Attribute Map. // e.g. if we have an renamed attr that is not optional, it may have been defined as required in the super definition. // if so remove from required attr Map and add to the optional attr Map. if ( attrToRename == null ) { attrToRename = alternateAttributes . get ( rename ) ; alternativeAttr = true ; } // If we still haven't found the attr that we're renaming, issue a warning msg, and stop processing this Definition. // Otherwise build up a new attribute based which is a "merge" of new values, and any old values that haven't been defined // in the rename attribute. We add this new one, and remove the original from whichever Map of attributes it was previous // defined in. if ( attrToRename == null ) { // If we can't find the attribute that we're trying to rename then issue a warning. error ( "schemagen.rename.attribute.missing" , new Object [ ] { currDefId , rename , extendedAttr . getID ( ) } ) ; } else { // Add the new attr to the current list, and remove the old version from the optional or required depending on where it was // defined. currentAttributes . put ( attrId , renameAttribute ( currDefId , attributeMap . get ( rename ) , extendedAttr , required ) ) ; if ( alternativeAttr ) alternateAttributes . remove ( rename ) ; else currentAttributes . remove ( rename ) ; } // Otherwise we've got no extensions so just add the attribute to the list. } else { currentAttributes . put ( attrId , attrDef ) ; } } } }
This method takes a set of Attribute Definitions and processes them against an existing Map of attributes .