FileDocCategorySizeDatePackage
SunCmpMappingsUtils.javaAPI DocGlassfish v2 API8965Fri May 04 22:34:42 BST 2007com.sun.jdo.api.persistence.mapping.ejb

SunCmpMappingsUtils

public class SunCmpMappingsUtils extends Object
Finder utilities for elements of the SunCmpMappings object graph.
author
vkraemer

Fields Summary
private static ResourceBundle
bundle
Constructors Summary
private SunCmpMappingsUtils()
Creates a new instance of SunCmpMappingsUtils

 //NOI18N

    
           
      
    
Methods Summary
public static CmpFieldMappingfindCmpFieldMapping(EntityMapping em, java.lang.String fname, boolean addEmpty)
Find the CmpFieldMapping element with a matching field-name element value

return
The CmpFieldMapping element or null if addEmpty is false and the field is not found.
param
em the root of the search
param
fname the value of the field-name element
param
addEmpty flag to add an empty version of the CmpFieldMapping element to the graph if one is not found.
throws
IllegalArgumentException If there is more than one cmp-field with a matching field-name element in the EntityMapping graph.

        CmpFieldMapping retVal = (CmpFieldMapping) findSingleCompatibleBean(
                "em", em, "fname", fname, "field-name", CmpFieldMapping.class); // NOI18N
        if ((null == retVal) && addEmpty) {
            retVal = new CmpFieldMapping();
            retVal.setFieldName(fname);
            em.addCmpFieldMapping(retVal);
        }
        return retVal;
    
public static CmrFieldMappingfindCmrFieldMapping(EntityMapping em, java.lang.String fname, boolean addEmpty)
Find the cmr-field-mapping element for a field in an EntityMapping object

return
the CmrFieldMapping element or null if addEmpty is false and the field is not found.
param
em The root of the search
param
fname the name of the field
param
addEmpty flag to add an empty version of the CmrFieldMapping element to the graph if one is not found.
throws
IllegalArgumentException If there is more than one cmr-field with a matching cmr-field-name element in the EntityMapping graph.

        CmrFieldMapping retVal = (CmrFieldMapping) findSingleCompatibleBean(
                "em", em, "fname", fname, "cmr-field-name", CmrFieldMapping.class); // NOI18N
        if ((null == retVal) && addEmpty) {
            retVal = new CmrFieldMapping();
            retVal.setCmrFieldName(fname);
            em.addCmrFieldMapping(retVal);
        }
        return retVal;
    
protected static java.util.ListfindCompatibleBeansWithValue(org.netbeans.modules.schema2beans.BaseBean root, java.lang.String propName, java.lang.String propVal, java.lang.Class type)
A utility for finding beans in a graph of BaseBean objects. Search the bean graph, starting at a given root, for beans where the named property has the given value. The returned list is filtered by assignment compatibility.

return
The assignment compatible BaseBeans that were found.
param
root The root of a search
param
propName The name of the element
param
propVal the value of the element
param
type The expected type of the value to be returned.
throws
IllegalArgumentException If the bean is not part of a complete bean graph.

        List retVal = null; 
        GraphManager gm = root.graphManager();
        if (null == gm) 
            throw new IllegalArgumentException(
                    bundle.getString("ERR_DISCONNECTED_NOT_SUPPORTED"));
        String[] props = root.findPropertyValue(propName, propVal);
        int len = 0;
        if (null != props)
            len = props.length;
        if (len > 0)
            retVal = new ArrayList(); 
        for (int i = 0; i < len; i++) {
            // get the bean that is the property's parent.
            BaseBean candidate = gm.getPropertyParent(props[i]); 
            if (type.isInstance(candidate))
                retVal.add(candidate);
        }
        return retVal;
    
public static EntityMappingfindEntityMapping(SunCmpMappings scms, java.lang.String bname, boolean addEmpty)
Find the EntityMapping element that correspond to a bean.

return
the EntityMapping element, or null if addEmpty is false and the EntityMapping is not found.
param
scms the root of the SunCmpMappings graph
param
bname The value of the ejb-name element for a bean in the graph
param
addEmpty flag to add an empty version of the EntityMapping element to the graph if one is not found.
throws
IllegalArgumentException if more than one EntityMapping element has an ejb-name element with the matching value

        EntityMapping retVal = (EntityMapping) findSingleCompatibleBean(
                "scms", scms, "bname", bname, "ejb-name", EntityMapping.class); // NOI18N
        if ((null == retVal) && addEmpty) {
            retVal = new EntityMapping();
            retVal.setEjbName(bname);
            SunCmpMapping scm = getFirstSunCmpMapping(scms, addEmpty);
            scm.addEntityMapping(retVal);
        }
        return retVal;
    
private static org.netbeans.modules.schema2beans.BaseBeanfindSingleCompatibleBean(java.lang.String argOneName, org.netbeans.modules.schema2beans.BaseBean argOne, java.lang.String argTwoName, java.lang.String argTwo, java.lang.String propName, java.lang.Class type)
helper method

        BaseBean retVal = null;
        if (null == argTwo || argTwo.length() < 1)
            throw new IllegalArgumentException(argTwoName);
        
        List l = findCompatibleBeansWithValue(argOne, propName, argTwo, 
            type);
        if (null != l) {
            if (l.size() == 1)
                retVal = (BaseBean) l.get(0);
            else if (l.size() > 1)
                throw new IllegalArgumentException(argOneName);
        }
        return retVal;
    
public static SunCmpMappinggetFirstSunCmpMapping(SunCmpMappings scms, boolean addEmpty)
Return the first SunCmpMapping element from the graph.

param
scms The root of a SunCmpMappings object graph
param
addEmpty flag to add an empty version of the SunCmpMapping element to the graph if one is not found.
return
The first SunCmpMapping element in the graph or null if it doesn't exists and addEmpty is false.

        SunCmpMapping retVal = null;
        if (0 < scms.sizeSunCmpMapping())
            retVal =  scms.getSunCmpMapping(0);
        if ((null == retVal) && addEmpty) {
            retVal = new SunCmpMapping();
            scms.addSunCmpMapping(retVal);
        }
        return retVal;