| Method from org.apache.xmlbeans.impl.tool.BaseSchemaResourceManager Detail: |
abstract protected void deleteFile(String filename)
Deletes a file. Sometimes immediately after writing a new file
we notice that it's exactly the same as an existing file and
we delete it. We never delete a file that was given to us
by the user. |
abstract protected boolean fileExists(String filename)
Returns true if the given filename exists. The filenames
are of the form "/foo/bar/zee.xsd" and should be construed
as rooted at the root of the project. |
abstract protected String[] getAllXSDFilenames()
Returns a list of all the XSD filesnames in the project. |
protected String getDefaultSchemaDir() {
return "./schema";
}
|
protected String getIndexFilename() {
return "./xsdownload.xml";
}
|
protected final void init() {
if (fileExists(getIndexFilename()))
{
try
{
_importsDoc = DownloadedSchemasDocument.Factory.parse( inputStreamForFile( getIndexFilename() ) );
}
catch (IOException e)
{
_importsDoc = null;
}
catch (Exception e)
{
throw (IllegalStateException)(new IllegalStateException("Problem reading xsdownload.xml: please fix or delete this file")).initCause(e);
}
}
if (_importsDoc == null)
{
try
{
_importsDoc = DownloadedSchemasDocument.Factory.parse(
"< dls:downloaded-schemas xmlns:dls='http://www.bea.com/2003/01/xmlbean/xsdownload' defaultDirectory='" + getDefaultSchemaDir() + "'/ >"
);
}
catch (Exception e)
{
throw (IllegalStateException)(new IllegalStateException()).initCause(e);
}
}
String defaultDir = _importsDoc.getDownloadedSchemas().getDefaultDirectory();
if (defaultDir == null)
defaultDir = getDefaultSchemaDir();;
_defaultCopyDirectory = defaultDir;
// now initialize data structures
DownloadedSchemaEntry[] entries = _importsDoc.getDownloadedSchemas().getEntryArray();
for (int i = 0; i < entries.length; i++)
{
updateResource(entries[i]);
}
}
|
abstract protected InputStream inputStreamForFile(String filename) throws IOException
Gets the data in the given filename as an InputStream. |
public SchemaImportResolver.SchemaResource lookupResource(String nsURI,
String schemaLocation) {
SchemaResource result = fetchFromCache(nsURI, schemaLocation);
if (result != null)
{
if (_redownloadSet != null)
{
redownloadResource(result);
}
return result;
}
if (schemaLocation == null)
{
warning("No cached schema for namespace '" + nsURI + "', and no url specified");
return null;
}
result = copyOrIdentifyDuplicateURL(schemaLocation, nsURI);
if (_redownloadSet != null)
_redownloadSet.add(result);
return result;
}
Called when the ImportLoader wishes to resolve the
given import. Should return a SchemaResource whose
"equals" relationship reveals when a SchemaResource is
duplicated and shouldn't be examined again.
Returns null if the resource reference should be ignored. |
public final void process(String[] uris,
String[] filenames,
boolean sync,
boolean refresh,
boolean imports) {
if (refresh)
{
_redownloadSet = new HashSet();
}
else
{
_redownloadSet = null;
}
if (filenames.length > 0)
syncCacheWithLocalXsdFiles(filenames, true);
else if (sync)
syncCacheWithLocalXsdFiles(getAllXSDFilenames(), false);
Set starterset = new HashSet();
for (int i = 0; i < uris.length; i++)
{
SchemaResource resource = (SchemaResource)lookupResource(null, uris[i]);
if (resource != null)
starterset.add(resource);
}
for (int i = 0; i < filenames.length; i++)
{
SchemaResource resource = (SchemaResource)_resourceForFilename.get(filenames);
if (resource != null)
starterset.add(resource);
}
SchemaResource[] starters = (SchemaResource[])
starterset.toArray(new SchemaResource[0]);
if (refresh)
redownloadEntries(starters);
if (imports)
resolveImports(starters);
_redownloadSet = null;
}
|
public final void processAll(boolean sync,
boolean refresh,
boolean imports) {
if (refresh)
{
_redownloadSet = new HashSet();
}
else
{
_redownloadSet = null;
}
String[] allFilenames = getAllXSDFilenames();
if (sync)
syncCacheWithLocalXsdFiles(allFilenames, false);
SchemaResource[] starters = (SchemaResource[])
_resourceForFilename.values().toArray(new SchemaResource[0]);
if (refresh)
redownloadEntries(starters);
if (imports)
resolveImports(starters);
_redownloadSet = null;
}
|
public void reportActualNamespace(SchemaImportResolver.SchemaResource rresource,
String actualNamespace) {
SchemaResource resource = (SchemaResource)rresource;
String oldNamespace = resource.getNamespace();
if (oldNamespace != null && _resourceForNamespace.get(oldNamespace) == resource)
_resourceForNamespace.remove(oldNamespace);
if (!_resourceForNamespace.containsKey(actualNamespace))
_resourceForNamespace.put(actualNamespace, resource);
resource.setNamespace(actualNamespace);
}
Updates actual namespace in the table. |
public final void syncCacheWithLocalXsdFiles(String[] filenames,
boolean deleteOnlyMentioned) {
Set seenResources = new HashSet();
Set vanishedResources = new HashSet();
for (int i = 0; i < filenames.length; i++)
{
String filename = filenames[i];
// first, if the filename matches exactly, trust the filename
SchemaResource resource = (SchemaResource)_resourceForFilename.get(filename);
if (resource != null)
{
if (fileExists(filename))
seenResources.add(resource);
else
vanishedResources.add(resource);
continue;
}
// new file that is not in the index?
// not if the digest is known to the index and the original file is gone - that's a rename!
String digest = null;
try
{
digest = shaDigestForFile(filename);
resource = (SchemaResource)_resourceForDigest.get(digest);
if (resource != null)
{
String oldFilename = resource.getFilename();
if (!fileExists(oldFilename))
{
warning("File " + filename + " is a rename of " + oldFilename);
resource.setFilename(filename);
seenResources.add(resource);
if (_resourceForFilename.get(oldFilename) == resource)
_resourceForFilename.remove(oldFilename);
if (_resourceForFilename.containsKey(filename))
_resourceForFilename.put(filename, resource);
continue;
}
}
}
catch (IOException e)
{
// unable to read digest... no problem, ignore then
}
// ok, this really is a new XSD file then, of unknown URL origin
DownloadedSchemaEntry newEntry = addNewEntry();
newEntry.setFilename(filename);
warning("Caching information on new local file " + filename);
if (digest != null)
newEntry.setSha1(digest);
seenResources.add(updateResource(newEntry));
}
if (deleteOnlyMentioned)
deleteResourcesInSet(vanishedResources, true);
else
deleteResourcesInSet(seenResources, false);
}
Adds items to the cache that point to new files that aren't
described in the cache, and optionally deletes old entries.
If an old file is gone and a new file is
found with exactly the same contents, the cache entry is moved
to point to the new file. |
abstract protected void warning(String msg)
Produces diagnostic messages such as "downloading X to file Y". |
public final void writeCache() throws IOException {
InputStream input = _importsDoc.newInputStream(new XmlOptions().setSavePrettyPrint());
writeInputStreamToFile(input, getIndexFilename());
}
|
abstract protected void writeInputStreamToFile(InputStream input,
String filename) throws IOException
Writes an entire file in one step. An InputStream is passed and
copied to the file. |