Search in sources :

Example 1 with MacroString

use of org.datanucleus.util.MacroString in project datanucleus-core by datanucleus.

the class AbstractClassMetaData method getReferencedClassMetaData.

/**
 * Method to return the ClassMetaData for classes referenced by this object. This method does the actual work of addition.
 * @param orderedCmds List of ordered ClassMetaData objects (added to).
 * @param referencedCmds Set of all ClassMetaData objects (added to).
 * @param viewReferences Map, mapping class name to set of referenced class for all views.
 * @param clr the ClassLoaderResolver
 */
private void getReferencedClassMetaData(final List<AbstractClassMetaData> orderedCmds, final Set<AbstractClassMetaData> referencedCmds, final Map<String, Set<String>> viewReferences, final ClassLoaderResolver clr) {
    // This will ensure that any classes with dependencies on them are put in the orderedCmds List in the correct order.
    if (!referencedCmds.contains(this)) {
        // Go ahead and add this class to the referenced Set, it will get added to the orderedCmds List after all classes that this depends on have been added.
        referencedCmds.add(this);
        for (int i = 0; i < managedMembers.length; i++) {
            managedMembers[i].getReferencedClassMetaData(orderedCmds, referencedCmds, clr);
        }
        // Add on any superclass
        if (persistableSuperclass != null) {
            getSuperAbstractClassMetaData().getReferencedClassMetaData(orderedCmds, referencedCmds, clr);
        }
        // Add on any objectid class
        if (objectidClass != null && !usesSingleFieldIdentityClass()) {
            AbstractClassMetaData idCmd = mmgr.getMetaDataForClass(objectidClass, clr);
            if (idCmd != null) {
                idCmd.getReferencedClassMetaData(orderedCmds, referencedCmds, clr);
            }
        }
        // Add on any view-definition for this class
        String viewDefStr = getValueForExtension(MetaData.EXTENSION_CLASS_VIEW_DEFINITION);
        if (viewDefStr != null) {
            MacroString viewDef = new MacroString(fullName, getValueForExtension(MetaData.EXTENSION_CLASS_VIEW_IMPORTS), viewDefStr);
            viewDef.substituteMacros(new MacroString.MacroHandler() {

                public void onIdentifierMacro(MacroString.IdentifierMacro im) {
                    if (// ignore itself
                    !getFullClassName().equals(im.className)) {
                        addViewReference(viewReferences, im.className);
                        AbstractClassMetaData viewCmd = mmgr.getMetaDataForClass(im.className, clr);
                        viewCmd.getReferencedClassMetaData(orderedCmds, referencedCmds, viewReferences, clr);
                    }
                }

                public void onParameterMacro(MacroString.ParameterMacro pm) {
                    throw new NucleusUserException("Parameter macros not allowed in view definitions: " + pm);
                }
            }, clr);
        }
        orderedCmds.add(this);
    }
}
Also used : MacroString(org.datanucleus.util.MacroString) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) MacroString(org.datanucleus.util.MacroString)

Aggregations

NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 MacroString (org.datanucleus.util.MacroString)1