convenience, as templates and types often created together
@param reference
@param name
@param executionContext
@return
555954
protected DocumentType upsertType(
            String reference,
            String name,
            ExecutionContext executionContext) {

        DocumentType documentType = documentTypeRepository.findByReference(reference);
        if(documentType != null) {
            documentType.setName(name);
        } else {
            documentType = documentTypeRepository.create(reference, name);
        }
        return executionContext.addResult(this, documentType);
    }
818423
@SuppressWarnings("unchecked")
    public <T> T getContextData(String name) {
        T rc = null;
        if (null != this.inheritableLocals) {
            rc = (T) this.inheritableLocals.get(name);
        }
        if (null == rc && null != this.locals) {
            rc = (T) this.locals.get(name);
        }
        return rc;
    }
262268
@Override
    public ITemplate __cloneMe(RythmEngine engine, ITemplate caller) {
        if (null == engine) throw new NullPointerException();
        TemplateBase tmpl = __internalClone();
        if (tmpl.__parent != null) {
            tmpl.__parent = (TemplateBase) tmpl.__parent.__cloneMe(engine, caller);
        }
        tmpl.__engine = engine;
        //tmpl.__templateClass = __templateClass;
        tmpl.__ctx = new __Context();
        //if (null != buffer) tmpl.__buffer = buffer;
        if (null != __buffer) tmpl.__buffer = new StringBuilder();
        tmpl.__renderArgs = new HashMap<String, Object>(__renderArgs.size());
        //tmpl.layoutContent = "";
        tmpl.layoutSections = new HashMap<String, String>();
        tmpl.layoutSections0 = new HashMap<String, String>();
        tmpl.renderProperties = new HashMap<String, Object>();
        //tmpl.section = null;
        //tmpl.tmpCaller = null;
        //tmpl.tmpOut = null;
        //tmpl.__logTime = __logTime;
        //tmpl.w = null;
        //tmpl.os = null;
        if (null != caller) {
            tmpl.__caller = (TextBuilder) caller;
            Map<String, Object> callerRenderArgs = new HashMap<String, Object>(((TemplateBase) caller).__renderArgs);
            Map<String, Class> types = tmpl.__renderArgTypeMap();
            for (Map.Entry<String, Object> entry : callerRenderArgs.entrySet()) {
                if (tmpl.__renderArgs.containsKey(entry.getKey())) continue;
                Object o = entry.getValue();
                if (null == o || __isDefVal(o)) continue;
                Class<?> c = types.get(entry.getKey());

                if (null == c || c.isAssignableFrom(o.getClass())) {
                    tmpl.__setRenderArg(entry.getKey(), o);
                }
            }
        }
        tmpl.__setUserContext(engine.renderSettings.userContext());
        return tmpl;
    }
646909
public void templateNameVerification(String expectedName)
			throws SyntaxException {

		if (!name.equals(expectedName)) {
			throw SyntaxException.create(null, source, MSG_MISNAMED_TPL,
					expectedName);
		}
	}
543695
private MetaHolder createCopy(MetaHolder source, ExecutionType executionType) {
        return MetaHolder.builder()
                .obj(source.getObj())
                .method(source.getMethod())
                .ajcMethod(source.getAjcMethod())
                .fallbackExecutionType(source.getFallbackExecutionType())
                .extendedFallback(source.isExtendedFallback())
                .extendedParentFallback(source.isExtendedParentFallback())
                .executionType(executionType)
                .args(source.getArgs())
                .observable(source.isObservable())
                .observableExecutionMode(source.getObservableExecutionMode())
                .defaultCollapserKey(source.getDefaultCollapserKey())
                .defaultCommandKey(source.getDefaultCommandKey())
                .defaultGroupKey(source.getDefaultGroupKey())
                .defaultThreadPoolKey(source.getDefaultThreadPoolKey())
                .defaultProperties(source.getDefaultProperties().orNull())
                .hystrixCollapser(source.getHystrixCollapser())
                .hystrixCommand(source.getHystrixCommand()).build();
    }
1163489
public Template globalLoad(String name, boolean lookupOnly) {

		// If this context was created without a Compiler object specified, then
		// no global lookups can be done. Just return null indicating that the
		// requested template can't be found.
		if (compiler == null) {
			return null;
		}

		// Use the full lookup to find the correct template file. This must
		// always be done on a global load because the actual template file on
		// disk may be different for different object templates. The raw
		// (unduplicated) value of LOADPATH can be used because it will not be
		// changed by the code below.
		SourceRepository repository = compiler.getSourceRepository();
		SourceFile source = repository.retrievePanSource(name,
				relativeLoadpaths);

		if (source.isAbsent()) {
			if (lookupOnly) {

				// Files that were searched for but not found are still
				// dependencies. Keep track of these so that they can be
				// included in the dependency file and checked when trying to
				// see if profiles are up-to-date.
				otherDependencies.add(source);
				return null;
			} else {

				// The lookupOnly flag was not set, so it is an error if the
				// template has not been found.
				throw EvaluationException.create((SourceRange) null,
						(BuildContext) this, MSG_CANNOT_LOCATE_TEMPLATE, name);
			}
		}

		// Now actually retrieve the other object's root, waiting if the
		// result isn't yet available.
		CompileCache ccache = compiler.getCompileCache();
		CompileResult cresult = ccache.waitForResult(source.getPath()
				.getAbsolutePath());

		Template template = null;
		try {
			// Extract the compiled template and ensure that the name is
			// correct. The template must not be null if no exception is thrown.
			template = cresult.template;
			template.templateNameVerification(name);

			// Found the template. Put this into the dependencies only if we're
			// really going to use it. I.e. if the lookupOnly flag is false.
			if (!lookupOnly) {
				dependencies.put(name, template);
				if (template.type == TemplateType.OBJECT) {
					objectDependencies.add(template.name);
				}
			}

		} catch (SyntaxException se) {

			// This can happen if there is a syntax error while including
			// the given template. If this isn't just a lookup, then convert
			// this into an evaluation exception
			// and throw it.
			if (!lookupOnly) {
				throw new EvaluationException(se.getMessage());
			} else {
				template = null;
			}

		} catch (EvaluationException ee) {

			// Eat the exception if we're only doing a lookup; otherwise,
			// rethrow it.
			if (!lookupOnly) {
				throw ee;
			} else {
				template = null;
			}

		}

		return template;
	}
391929
public static Object getLocalVar(ExecutionContext context, String name) {
        LexicalEnvironment localEnv = context.getLexicalEnvironment();
        if (localEnv.getRecord().hasBinding(context, name)) {
            return localEnv.getRecord().getBindingValue(context, name, false);
        }
        return null;
    }
921293
public Template getTemplate(final String name) throws ResourceNotFoundException {
        final Template template = this.cachedTemplates.get(name);
        if (template != null) {
            return template;
        }
        return createTemplateIfAbsent(name);
    }
634064
@Override
  public <CS, CD> MappingContext<CS, CD> create(CS source, Class<CD> destinationType) {
    Assert.notNull(source, "source");
    Assert.notNull(destinationType, "destinationType");

    return new MappingContextImpl<CS, CD>(this, source, Types.<CS>deProxy(source.getClass()), null,
        destinationType, null, null, false);
  }
1051455
public <T> JdbcMapperBuilder<T> newBuilder(final TypeReference<T> target) {
        return newBuilder(target.getType());
    }
1076476
public CompilationUnit createCompilationUnit(String name) {

        if (name != null && name.equals(getTemplateName())) {
            return new TextCompilationUnit(name, this, getText());
        }
        
        // Create a compilation unit for a .tea file
        return super.createCompilationUnit(name);
    }
58545
@Override
    public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
        if (obj instanceof Reference) {
            try {
                String jndiName = nameCtx == null ? "" : nameCtx.getNameInNamespace();
                jndiName += name == null ? "" : name.toString();
                String urlValue = (String) ((Reference) obj).get(0).getContent();
                return createURL(jndiName, urlValue);
            } catch (Throwable t) {
                NamingException ne = new NamingException();
                ne.initCause(t);
                throw ne;
            }
        }

        return null;
    }
873777
public <T extends CacheSpec<K, V>> T name(String name) {
      this.name = name;
      return Cast.as(this);
   }
15783
private TemplateClass tryLoadTemplate(String tmplName, RythmEngine engine, TemplateClass callerClass, ICodeType codeType, boolean processTagName) {
        //logger.info(">>> try load %s on [%s] with processTagName: %s", tmplName, callerClass.getKey(), processTagName);
        if (null == engine) {
            engine = getDefaultEngine();
        }
        if (engine.templateRegistered(tmplName)) {
            return null;
        }
        String rythmSuffix = engine.conf().resourceNameSuffix();
        final List<String> suffixes = new ArrayList<String>(Arrays.asList(RythmEngine.VALID_SUFFIXES));
        if (null == codeType) {
            codeType = TemplateResourceBase.getTypeOfPath(engine, tmplName);
        }
        if (ICodeType.DefImpl.RAW == codeType) {
            // use caller's code type
            codeType = callerClass.codeType;
        }
        final String tagNameOrigin = tmplName;
        boolean hasSuffix = false;
        String suffix = "";
        if (processTagName) {
            boolean withRythmSuffix = S.notEmpty(rythmSuffix);
            for (String s : suffixes) {
                if (tmplName.endsWith(s)) {
                    tmplName = tmplName.substring(0, tmplName.lastIndexOf(s));
                    suffix = s;
                    hasSuffix = true;
                    break;
                }
                if (withRythmSuffix && (tmplName.endsWith(s) || tmplName.endsWith(s + rythmSuffix))) {
                    tmplName = tmplName.substring(0, tmplName.lastIndexOf(s));
                    suffix = s + rythmSuffix;
                    hasSuffix = true;
                    break;
                }
            }
        }
        tmplName = tmplName.replace('.', '/');
        String sfx = codeType.resourceNameSuffix();
        if (S.notEmpty(sfx) && !suffixes.get(0).equals(sfx)) {
            suffixes.remove(sfx);
            suffixes.add(0, sfx);
        }

        final List<String> roots = new ArrayList<String>();
        String root0 = this.getResourceLoaderRoot().replace('\\', '/');
        if (root0.endsWith("/")) {
            root0 = root0.substring(0, root0.length() - 1);
        }

        roots.add(root0);

        // call template using relative path
        String currentPath = callerClass.getKey().toString();
        int pos = currentPath.lastIndexOf("/");
        if (-1 != pos) {
            currentPath = currentPath.substring(0, pos);
            if (currentPath.startsWith(root0)) {
                if (currentPath.length() > root0.length()) {
                    roots.add(0, currentPath);
                }
            } else {
                if (currentPath.startsWith("/")) {
                    currentPath = currentPath.substring(1);
                }
                if (!currentPath.startsWith(root0)) currentPath = root0 + "/" + currentPath;
                roots.add(0, currentPath);
            }
        }
        
        // call tag with import path
        if (null != callerClass.importPaths) {
            for (String s: callerClass.importPaths) {
                if (s.startsWith("java")) {
                    continue;
                }
                roots.add(0, root0 + "/" + s.replace('.', '/'));
            }
        }

        String tmplName0 = tmplName;
        for (String root : roots) {
            String tmplName1 = tmplName0;
            if (root.startsWith("/") && !tmplName1.startsWith("/")) {
                tmplName1 = "/" + tmplName0;
            }
            tmplName = tmplName1.startsWith(root) ? tmplName1 : root + "/" + tmplName0;
            if (hasSuffix) {
                ITemplateResource resource = load(tmplName + suffix);
                if (null == resource || !resource.isValid()) {
                    continue;
                }
                TemplateClass tc = engine.resourceManager().resourceLoaded(resource, false);
                return tc;
            } else {
                for (String suffix0 : suffixes) {
                    String path = tmplName + suffix0;
                    ITemplateResource resource = load(path);
                    if (null == resource || !resource.isValid()) {
                        continue;
                    }
                    TemplateClass tc = engine.resourceManager().resourceLoaded(resource, false);
                    return tc;
                }
            }
        }
        TemplateClass tc = processTagName ? tryLoadTemplate(tagNameOrigin, engine, callerClass, codeType, false) : null;
        if (null == tc) {
            TemplateResourceManager.reportNonResource(tmplName);
        }
        return tc;
    }
169911
function compile(template, context) {
        for (var name in context) {
            template = template.replace('{{' + name + '}}', context[name])
        }
        return template
    }
1093523
protected static String qualifiedNameFromIdAndContext(String name, String context) {
        if (!name.contains(".")) {
            return context + "." + name;
        }
        return name;
    }
19448
function(name, eagerCompile, cb) {
                if (name && name.raw) {
                    // this fixes autoescape for templates referenced in symbols
                    name = name.raw;
                }

                if (lib.isFunction(eagerCompile)) {
                    cb = eagerCompile;
                    eagerCompile = false;
                }

                if (typeof name !== 'string') {
                    throw new Error('template names must be a string: ' + name);
                }

                var tmpl = this.cache[name];

                if (tmpl) {
                    if (eagerCompile) {
                        tmpl.compile();
                    }

                    if (cb) {
                        cb(null, tmpl);
                    } else {
                        return tmpl;
                    }
                } else {
                    var syncResult;

                    lib.asyncIter(this.loaders, function(loader, i, next, done) {
                        function handle(src) {
                            if (src) {
                                done(src);
                            } else {
                                next();
                            }
                        }

                        if (loader.async) {
                            loader.getSource(name, function(err, src) {
                                if (err) {
                                    throw err;
                                }
                                handle(src);
                            });
                        } else {
                            handle(loader.getSource(name));
                        }
                    }, function(info) {
                        if (!info) {
                            var err = new Error('template not found: ' + name);
                            if (cb) {
                                cb(err);
                            } else {
                                throw err;
                            }
                        } else {
                            var tmpl = new Template(info.src, this,
                                info.path, eagerCompile);

                            if (!info.noCache) {
                                this.cache[name] = tmpl;
                            }

                            if (cb) {
                                cb(null, tmpl);
                            } else {
                                syncResult = tmpl;
                            }
                        }
                    }.bind(this));

                    return syncResult;
                }
            }