/*
 *    Copyright 2012 Jason Miller
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jj.application;

import jj.resource.Location;

/**
 * <p>
 * Type safe way to represent the locations of resources, either in the application structure
 * </p>
 * 
 * <pre>
 * (root location)
 * |-config.js
 * \--private
 *  |-private-specs
 *  |-public
 *  |-public-specs
 * </pre>
 * 
 * <p>or internally with virtual
 * 
 * <p>
 * This needs a little more work.  The core system should define
 * Virtual and AppBase (and later some system for jars) and those
 * are considered the roots.  All filesystem resources are located
 * under AppBase and can be resolved by appending to that root
 * directly
 * 
 * @author jason
 *
 */
public enum AppLocation implements Location {
	
	/** the paths of the application pieces */
	Base("", null, true, false),
	Private("private/", Base, true, false),
	Specs("specs/", Base, true, false),
	Public("public/", Base, true, false);
	
	private final String path;
	private final AppLocation parent;
	private final boolean ensureDirectory;
	private final boolean internal;
	
	private AppLocation(
		final String path,
		final AppLocation parent,
		final boolean ensureDirectory,
		final boolean internal
	) {
		this.path = path;
		this.parent = parent;
		this.ensureDirectory = ensureDirectory;
		this.internal = internal;
	}
	
	AppLocation parent() {
		return parent;
	}
	
	AppLocation root() {
		return parent == null ? this : parent.root();
	}
	
	String path() {
		return parent == null ? path : parent.path() + path;
	}
	
	public boolean internal() {
		return internal;
	}
	
	@Override
	public boolean parentInDirectory() {
		return ensureDirectory;
	}
}

@@ -714,24 +714,16 @@
 esources
-, either
  in the 
@@ -883,329 +883,8 @@
  * %0A
- * %3Cp%3Eor internally with virtual%0A * %0A * %3Cp%3E%0A * This needs a little more work.  The core system should define%0A * Virtual and AppBase (and later some system for jars) and those%0A * are considered the roots.  All filesystem resources are located%0A * under AppBase and can be resolved by appending to that root%0A * directly%0A * %0A
  * @
@@ -1007,27 +1007,8 @@
 e(%22%22
-, null, true, false
 ),%0A%09
@@ -1029,64 +1029,26 @@
 te/%22
-, Base, true, false),%0A%09Specs(%22specs/%22, Base, true, false
+),%0A%09Specs(%22specs/%22
 ),%0A%09
@@ -1067,27 +1067,8 @@
 ic/%22
-, Base, true, false
 );%0A%09
@@ -1100,116 +1100,8 @@
 th;%0A
-%09private final AppLocation parent;%0A%09private final boolean ensureDirectory;%0A%09private final boolean internal;%0A
 %09%0A%09p
@@ -1119,25 +1119,16 @@
 ocation(
-%0A%09%09final 
 String p
@@ -1134,464 +1134,67 @@
 path
-,%0A%09%09final AppLocation parent,%0A%09%09final boolean ensureDirectory,%0A%09%09final boolean internal%0A%09) %7B%0A%09%09this.path = path;%0A%09%09this.parent = parent;%0A%09%09this.ensureDirectory = ensureDirectory;%0A%09%09this.internal = internal;%0A%09%7D%0A%09%0A%09AppLocation parent() %7B%0A%09%09return parent;%0A%09%7D%0A%09%0A%09AppLocation root() %7B%0A%09%09return parent == null ? this : parent.root();%0A%09%7D%0A%09%0A%09String path() %7B%0A%09%09return parent == null ? path : parent.path() + path;%0A%09%7D%0A%09%0A%09public boolean internal() %7B%0A%09%09return internal
+) %7B%0A%09%09this.path = path;%0A%09%7D%0A%09%0A%09String path() %7B%0A%09%09return path
 ;%0A%09%7D
@@ -1258,23 +1258,12 @@
 urn 
-ensureDirectory
+true
 ;%0A%09%7D

simplify a lot