Package org.raptorjs.resources.packaging

Source Code of org.raptorjs.resources.packaging.DependencyResource

package org.raptorjs.resources.packaging;

import org.raptorjs.resources.Resource;
import org.raptorjs.resources.ResourceManager;

public abstract class DependencyResource extends Dependency {
    private Resource resource = null;
    private boolean resourceResolved = false;
    private String path = null;
   
    public abstract ContentType getContentType();

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
   
    @Override
    public boolean isPackageInclude() {
        return false;
    }
   
    @Override
    public void init() {
        this.setPath(this.getProperty("path"));
    }
   
    public Resource getResource(ResourceManager resourceManager) {
        if (!this.resourceResolved) {
            PackageManifest mf = getParentPackageManifest();
            if (mf != null) {
                this.resource = mf.resolveResource(path, resourceManager);
            }
            else if (this.path.startsWith("/")) {
                this.resource = resourceManager.findResource(this.path);
            }
           
            this.resourceResolved = true;
        }
        return this.resource;
    }
   
    @Override
    public boolean exists(ResourceIncluderContext context) {
        Resource resource = this.getResource(context.getResourceManager());
        return resource != null;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime
                * result
                + ((getParentPackageManifest() == null) ? 0 : getParentPackageManifest()
                        .hashCode());
        result = prime * result + ((path == null) ? 0 : path.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        DependencyResource other = (DependencyResource) obj;
        if (getParentPackageManifest() == null) {
            if (other.getParentPackageManifest() != null)
                return false;
        } else if (!getParentPackageManifest().equals(other.getParentPackageManifest()))
            return false;
        if (path == null) {
            if (other.path != null)
                return false;
        } else if (!path.equals(other.path))
            return false;
        return true;
    }

   
   
   
}
TOP

Related Classes of org.raptorjs.resources.packaging.DependencyResource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.