Hi all, happy new year!

Does anyone here have a reliable way to find what bundle a loaded EOModel is in? I'm currently using the little bugger below, but obviously it will fail if the model does not contain any entites or if the entities are using EOGenericRecord as the class (rare, but happens).

--------
        /**
         * Attempts to resolve which framework/bundle an EOModel belongs to.
         */
        public static String bundleNameForEOModel( EOModel model ) {
                NSArray<EOEntity> entities = model.entities();

                if( entities == null || entities.count() == 0 )
                        return null;

                EOEntity entity = entities.lastObject();
                String className = entity.className();

                try {
                        Class<?> clazz = Class.forName( className );
                        return NSBundle.bundleForClass( clazz ).name();
                }
                catch( ClassNotFoundException e ) {
                        logger.error( "No bundle found for class: " + 
className, e );
                        return null;
                }
        }
--------

Cheers,
- Hugi

// Hugi Thordarson
// http://hugi.karlmenn.is/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to