[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

XML:DB implementation - Relationships between Collection, Resource and XMLContainer



I'm struggling with CollectionImpl.createResource(). What should be the
relationships between org.xmldb.api.base.Collection,
org.xmldb.api.base.Resource and org.ozoneDB.xml.util.XMLContainer? I
something like the following in mind but I'm not sure this is a valid route:

 public Resource createResource( String id, String type ) throws
XMLDBException {
        try {
            if ( ( id == null ) || ( id.equals("") ) ) {
                id = createId();
            }
            if ( type.equals(XMLResource.RESOURCE_TYPE) ) {
		    // what to do with this?
                return new XMLResourceImpl(database,this,
XMLContainer.newContainer( database, id));
            }
            else if ( type.equals(BinaryResource.RESOURCE_TYPE) ) {
                throw new XMLDBException( ErrorCodes.VENDOR_ERROR,
"BinaryResource: Not yet implemented");
            }
            else {
                throw new XMLDBException(ErrorCodes.UNKNOWN_RESOURCE_TYPE);
            }
        }
        catch (Exception e) {
            throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
e.toString());
        }
    }

Then for CollectionImpl.storeResource() i'm not sure how the storage of a
Resource should be viewed. If Collection should aggregate Resources we
should store the resource inside the Collection but then Collection needs to
have a list (Map) of Resources. On the other hand if we store it as a
separate object what denoted its relationship with a Collection?

   public void storeResource( Resource res ) throws XMLDBException {
        try {
            String id = res.getId();
            if ((id == null) || (id.length() == 0)) {
                id = createId();
            }
		// what to do whith this?
            database.createObject( Resource.class.getName(),
OzoneInterface.Public, id);
          }
          catch (Exception e) {
             throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
e.toString());
          }
    }

Any suggestions?

Best regards,
Per