RE: Runtime Error: how to find cayenne.xml

From: Dave Paules (dn..uantumleap.us)
Date: Tue Mar 04 2003 - 17:02:04 EST

  • Next message: Andrus Adamchik: "Re: how to set username/password ?"

    Hi Andrus and Holger,
    I've tried your suggestions regarding subclassing Configuration or
    DefaultConfiguration.

    I created a subclass of DefaultConfiguration and placed that class in the
    same package directory as the cayenne.xml, *.driver.xml and *.map.xml files.
    The call to Configuration.initSharedConfig() still fails, but now when
    trying to parse the .xml file for domains.

    Here's the stack trace:
    ERROR Configuration: Error initializing shared Configuration
    org.objectstyle.cayenne.ConfigException:
    [database.cayenne_config.CayenneConfigLoader] : Failed to load domain and/or
    its maps/nodes.
            at
    org.objectstyle.cayenne.conf.RuntimeLoadDelegate.finishedLoading(RuntimeLoad
    Delegate.java:419)
            at
    org.objectstyle.cayenne.conf.ConfigLoader.loadDomains(ConfigLoader.java:118)
            at
    org.objectstyle.cayenne.conf.Configuration.init(Configuration.java:260)
            at
    org.objectstyle.cayenne.conf.Configuration.initSharedConfig(Configuration.ja
    va:214)
            at database.DBTests.MultiUserTest.loadCayenne(MultiUserTest.java:34)
            at database.DBTests.MultiUserTest.<init>(MultiUserTest.java:22)
            at database.DBTests.MultiUserTest.main(MultiUserTest.java:26)
    java.lang.RuntimeException: Error initializing shared Configuration
            at
    org.objectstyle.cayenne.conf.Configuration.initSharedConfig(Configuration.ja
    va:217)
            at database.DBTests.MultiUserTest.loadCayenne(MultiUserTest.java:34)
            at database.DBTests.MultiUserTest.<init>(MultiUserTest.java:22)
            at database.DBTests.MultiUserTest.main(MultiUserTest.java:26)
    Exception in thread "main"

    Here is how I am loading the cayenne framework:
                    CayenneConfigLoader CCL = new CayenneConfigLoader();
                    Configuration.initSharedConfig(CCL);

    CayenneConfigLoader is my subclass of DefaultConfiguration and exists within
    /database/cayenne_config. This is where the *.xml files are as well. That
    way, if I re-package or shift resources around, only this one class must be
    moved with them. It's implementation of getDomainConfig is similar to
    Holger's:

            public InputStream getDomainConfig() {
                    URL cayenneURL =
    this.getClass().getResource(Configuration.DOMAIN_FILE);
                    try {
                            InputStream inStream = cayenneURL.openStream();
                            return inStream;
                    } catch(IOException exception) {
                            return null;
                    }
            }

    Why does the parser within ConfigLoader.loadDomains() fail when reading the
    InputStream? The InputStream isn't null.... I am very confusd.

    Dave Paules
    Quantum Leap Innovations
    DaveP

    -----Original Message-----
    From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    Sent: Tuesday, February 25, 2003 1:03 AM
    To: cayenne-user
    Subject: Re: Runtime Error: how to find cayenne.xml

    Configuration class was meant to be extensible, so if default behavior
    doesn't suit the developer, subclassing is the way to go. Just make sure
    you install your own configuration by doing something like:

       Configuration.initSharedConfig(new MyConfig());

    Default implementation looks for resource named "cayenne.xml",
    "database/cayenne_config/cayenne.xml" is obviously a different resource
    and is therefore not recognized. For your custom implementation you may
    change that, for instance by using approach suggested by Holger:

        http://objectstyle.org/cayenne/lists/cayenne-devel/2003/02/0119.html

    Another, totally different approach to the same task is to keep Cayenne
    files separate from CLASSPATH locations in development, but add them to
    the final deployment jar. This is an addition introduced in 1.0a6. I use
    it all the time:

        http://objectstyle.org/cayenne/userguide/deploy/cdeploy.html

    Hope this helps.

    Andrus

    Holger Hoffstätte wrote:
    > Paul,
    >
    > some more info on your problem with packaged config files. It _should_
    > work but currently does not - I verified - and it's not really Cayenne's
    > fault. ClassLoader.getResource() does not look inside packages and will
    > only find files at the root of classpath entries, unless the resource is
    > specified with a path and that's something we currently can't do. There
    > are ways around that (I just implemented a nifty solution that does 99% of
    > what you want) but one obscure problem remains, so for the time being I
    > recommend you put the config files where they work.
    >
    > regards
    > Holger
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Mar 04 2003 - 17:09:06 EST