/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import gplx.langs.gfs.*;
public abstract class IoItm_base implements Gfo_invk, CompareAble {
	public abstract int TypeId(); public abstract boolean Type_dir(); public abstract boolean Type_fil();
	public Io_url Url() {return ownerDir == null ? url : ownerDir.Url().GenSubFil(name); /*NOTE: must call .Url*/} Io_url url;		
	public IoItmDir OwnerDir() {return ownerDir;} IoItmDir ownerDir;
	public void OwnerDir_set(IoItmDir v) {if (v == this) throw Err_.new_wo_type("dir cannot be its own owner", "url", v.url.Raw());
		url = v == null && ownerDir != null
						? ownerDir.url.GenSubFil(name)	// create url, since ownerDir will soon be null; NOTE: must call .url
						: Io_url_.Empty;					// delete url, since ownerDir will be avail
		ownerDir = v;
	}
	public String Name() {return name;} private String name;
	public IoItm_base Name_(String v) {
		name = v; 
		if (ownerDir == null) url = url.OwnerDir().GenSubFil(name); 
		return this;
	} 
	public Object XtnProps_get(String key) {return props.Get_by(key);} Hash_adp props = Hash_adp_.Noop;
	public IoItm_base XtnProps_set(String key, Object val) {
		if (props == Hash_adp_.Noop) props = Hash_adp_.New();
		props.Del(key);
		props.Add(key, val);
		return this;
	}
	public int compareTo(Object comp) {return url.compareTo(((IoItm_base)comp).url);}	// NOTE: needed for comic importer (sort done on IoItmHash which contains IoItm_base)
//		public Object Data_get(String name)				{return Gfo_invk_.Invk_by_key(this, name);}
	@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
		if		(ctx.Match(k, IoItm_base_.Prop_Type))	return this.TypeId();
		else if	(ctx.Match(k, IoItm_base_.Prop_Path))	return this.Url();
		else if	(ctx.Match(k, IoItm_base_.Prop_Title))	return this.Url().NameOnly();	// needed for gfio script criteria;
		else if (ctx.Match(k, IoItm_base_.Prop_Ext))	return this.Url().Ext();		// needed for gfio script criteria; EX: where "ext LIKE '.java'"
		else return Gfo_invk_.Rv_unhandled;
	}
	@gplx.Internal protected void ctor_IoItmBase_url(Io_url url) {this.url = url; this.name = url.NameAndExt();}
	@gplx.Internal protected void ctor_IoItmBase_name(String name) {this.name = name;}
}
