Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2006-02-06 17:21:39 -0500
committeratikhomirov2006-02-06 17:21:39 -0500
commit192b15753755a5c87fa73705ab2b4269aa77662d (patch)
tree927782e5cab2910450ce93ac30dc64d5214b2e17 /plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal
parentab3cbec7ac30ebc2acac1565d3a11e5de969c32b (diff)
downloadorg.eclipse.gmf-tooling-192b15753755a5c87fa73705ab2b4269aa77662d.tar.gz
org.eclipse.gmf-tooling-192b15753755a5c87fa73705ab2b4269aa77662d.tar.xz
org.eclipse.gmf-tooling-192b15753755a5c87fa73705ab2b4269aa77662d.zip
refactor - moved EmitterFactory/Dispatcher infrastructure to gmf.common to enable its use in oeg.codegen
Diffstat (limited to 'plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal')
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/ArrayKeyChain.java38
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DispatcherImpl.java78
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DynamicTemplateRegistry.java65
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/HierarchyKeyMap.java46
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/KeyChain.java59
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/KeyMap.java29
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/NoSuchTemplateException.java36
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StaticTemplateRegistry.java48
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/TemplateRegistry.java30
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/YAEmitterFactory.java160
10 files changed, 0 insertions, 589 deletions
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/ArrayKeyChain.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/ArrayKeyChain.java
deleted file mode 100644
index a5a39b533..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/ArrayKeyChain.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-/**
- * Although it's more straightforward just to override hasNext/next then to perform checks in advance,
- * did it that way for now to verify implementation in super. FIXME - refactor.
- * @author artem
- */
-public class ArrayKeyChain extends KeyChain {
- private final Object[] myKeys;
- private int myIndex = 0;
-
- public ArrayKeyChain(Object origin, Object singleKey) {
- this(origin, new Object[] {singleKey});
- }
-
- public ArrayKeyChain(Object origin, Object[] mappedKeys) {
- super(origin);
- myKeys = mappedKeys;
- }
-
- protected Object advance() {
- if (myIndex < myKeys.length) {
- return myKeys[myIndex++];
- }
- return null;
- }
-}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DispatcherImpl.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DispatcherImpl.java
deleted file mode 100644
index 0e22d84f0..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DispatcherImpl.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.codegen.jet.JETEmitter;
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.gmf.common.UnexpectedBehaviourException;
-import org.eclipse.gmf.graphdef.codegen.Dispatcher;
-
-/**
- * @author artem
- */
-public class DispatcherImpl extends Dispatcher {
-
- private final YAEmitterFactory myFactory;
-
- private final KeyMap myKeyMap;
-
- public DispatcherImpl(YAEmitterFactory factory, KeyMap keyMap) {
- myFactory = factory;
- myKeyMap = keyMap;
- }
-
- public String dispatch(Object key, Object argument) {
- final String pluginID = "org.eclipse.gmf.graphdef.codegen";
- final ILog traceFacility = Platform.getLog(Platform.getBundle(pluginID));
- try {
- StringBuffer errors = new StringBuffer();
- for (KeyChain it = myKeyMap.map(key); it.hasNext();) {
- Object nextKey = it.next();
- if (myFactory.checkEmitter(nextKey)) {
- try {
- JETEmitter em = myFactory.acquireEmitter(nextKey);
- return em.generate(new NullProgressMonitor(), new Object[] {argument});
- } catch (NoSuchTemplateException ex) {
- traceFacility.log(new Status(Status.ERROR, pluginID, 0, "Template for key '" + nextKey + "' failed", ex));
- errors.append(formatError(ex));
- errors.append("\n");
- } catch (UnexpectedBehaviourException ex) {
- traceFacility.log(new Status(Status.ERROR, pluginID, 0, "Template for key '" + nextKey + "' failed", ex));
- errors.append(formatError(ex));
- errors.append("\n");
- }
- }
- }
- if (errors.length() == 0) {
- // TODO option silent?
- return "// no suitable template found for '" + key + "'";
- } else {
- return errors.toString();
- }
- } catch (JETException ex) {
- traceFacility.log(new Status(Status.ERROR, pluginID, 0, ex.getMessage(), ex));
- return "ERROR: " + formatError(ex);
- }
- }
-
- public String dispatch(Object key, Args args) {
- return dispatch(key, (Object) args);
- }
-
- private static String formatError(Exception ex) {
- return ex.getClass().getSimpleName() + ": " + ex.getMessage();
- }
-}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DynamicTemplateRegistry.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DynamicTemplateRegistry.java
deleted file mode 100644
index 4b845c648..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DynamicTemplateRegistry.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-import java.text.MessageFormat;
-
-/**
- * Treat key as (part of) template path to allow <%=dispatcher.dispatch("../AnotherTemplate.javajet")%> use
- * Note, braces (<em>{</em> or <em>}</em>) within keys should be escaped, see {@link MessageFormat} class for details
- * @author artem
- */
-public class DynamicTemplateRegistry implements TemplateRegistry {
- private final String myPattern;
-
- /**
- * Uses simple pattern <code>"{0}"</code> (i.e. leave key as is) to initialize instance.
- */
- public DynamicTemplateRegistry() {
- this("{0}");
- }
-
- /**
- * Allows to add some prefix/suffix to the value of passed key. E.g. <code>"/templates-new/{0}.javajet"</code>
- * @param pattern string to pass to {@link MessageFormat}
- */
- public DynamicTemplateRegistry(String pattern) {
- myPattern = pattern;
- }
-
- /**
- * Treats key as (part of) template path
- */
- public String getTemplatePath(Object key) {
- return MessageFormat.format(myPattern, new Object[] { key });
- }
-
- /**
- * @return always false
- */
- public boolean hasGeneratorClass(Object key) {
- return false;
- }
-
- /**
- * @return always <code>null</code>
- */
- public Class getGeneratorClass(Object key) {
- return null;
- }
-
- /**
- * NO-OP
- */
- public void clean() {
- }
-}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/HierarchyKeyMap.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/HierarchyKeyMap.java
deleted file mode 100644
index 2c5cd0bba..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/HierarchyKeyMap.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-
-/**
- * XXX cache hierarchies?
- * @author artem
- */
-public class HierarchyKeyMap extends KeyMap {
-
- public HierarchyKeyMap() {
- }
-
- /**
- * Processes instances of {@link java.lang.Class} only, delegates to superclass otherwise
- */
- public KeyChain map(Object key) {
- if (false == key instanceof Class) {
- return super.map(key);
- }
- Class keyClass = (Class) key;
- Class[] immediateInterfaces = keyClass.getInterfaces();
- // make sure immediate interfaces are considered first in the key chain
- LinkedHashSet result = new LinkedHashSet(Arrays.asList(immediateInterfaces));
- LinkedList l = new LinkedList(result);
- while (!l.isEmpty()) {
- Class iface = (Class) l.removeFirst();
- result.add(iface);
- l.addAll(0, Arrays.asList(iface.getInterfaces()));
- }
- return new ArrayKeyChain(keyClass, result.toArray());
- }
-}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/KeyChain.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/KeyChain.java
deleted file mode 100644
index d189cf566..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/KeyChain.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * Key extraction and prioritization. <code>null</code> keys are not supported (useing null as eol indicator)
- * TODO add absract #reset()?
- * @author artem
- */
-public abstract class KeyChain/*<T>*/ implements Iterator/*<E>*/ {
- private final Object/*<T>*/ myOrigin;
- private Object/*<E>*/ myNextValue;
- private boolean myIsInitialized = false;
-
- public KeyChain(Object origin) {
- myOrigin = origin;
- }
-
- public final Object getOrigin() {
- return myOrigin;
- }
-
- public boolean hasNext() {
- if (!myIsInitialized) {
- myNextValue = advance();
- myIsInitialized = true;
- }
- return myNextValue != null;
- }
-
- /**
- * @return <code>null</code> to indicate EOL
- */
- protected abstract Object/*<E>*/ advance();
-
- public Object next() {
- if (hasNext()) {
- myIsInitialized = false;
- return myNextValue;
- }
- throw new NoSuchElementException();
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/KeyMap.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/KeyMap.java
deleted file mode 100644
index e87a50f44..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/KeyMap.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-/**
- * Logic of key extraction and prioritization.
- * @author artem
- * @see KeyChain
- */
-public class KeyMap/*<T,E>*/ {
-
- /**
- * Default implementation just returns the key itself as sole item in the chain
- * @param key
- * @return key chain with sole item that is key itself.
- */
- public KeyChain/*<T,E>*/ map(Object/*<T>*/ key) {
- return new ArrayKeyChain(key, key);
- }
-}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/NoSuchTemplateException.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/NoSuchTemplateException.java
deleted file mode 100644
index 6c7244b73..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/NoSuchTemplateException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-/**
- * @author artem
- */
-public class NoSuchTemplateException extends Exception {
-
- private static final long serialVersionUID = -1892646974029705702L;
-
- /**
- * @param templateName
- */
- public NoSuchTemplateException(String templateName) {
- super(templateName);
- }
-
- /**
- * @param templateName
- * @param cause
- */
- public NoSuchTemplateException(String templateName, Throwable cause) {
- super(templateName, cause);
- }
-
-}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StaticTemplateRegistry.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StaticTemplateRegistry.java
deleted file mode 100644
index 5e5863c09..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StaticTemplateRegistry.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author artem
- */
-public class StaticTemplateRegistry implements TemplateRegistry {
- private final Map pathMap = new HashMap/*<Object, String>*/();
- private final Map classMap = new HashMap/*<Object,Class>*/();
-
- public void put(Object key, String templatePath, Class generatorClass) {
- assert key != null && templatePath != null;
- pathMap.put(key, templatePath);
- if (generatorClass != null) {
- classMap.put(key, generatorClass);
- }
- }
-
- public String getTemplatePath(Object key) {
- return (String) pathMap.get(key);
- }
-
- public boolean hasGeneratorClass(Object key) {
- return classMap.containsKey(key);
- }
-
- public Class getGeneratorClass(Object key) {
- return (Class) classMap.get(key);
- }
-
- public void clean() {
- pathMap.clear();
- classMap.clear();
- }
-}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/TemplateRegistry.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/TemplateRegistry.java
deleted file mode 100644
index 1362fb8fc..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/TemplateRegistry.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-/**
- * XXX hm, it's possible to have only one JETEmitter per key. What if we'd like to reference same emitter with different keys?
- * TODO CompositeTemplateRegistry?
- * TODO move to gmf.common
- * @author artem
- */
-public interface TemplateRegistry {
-
- String getTemplatePath(Object key);
-
- boolean hasGeneratorClass(Object key);
-
- Class getGeneratorClass(Object key);
-
- void clean();
-
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/YAEmitterFactory.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/YAEmitterFactory.java
deleted file mode 100644
index 9d270df99..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/YAEmitterFactory.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.codegen.jet.JETEmitter;
-import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.gmf.common.UnexpectedBehaviourException;
-
-/**
- * Yet Another Emitter Factory
- *
- * @author artem
- */
-public class YAEmitterFactory {
-
- private final URL myBaseURL;
-
- private final TemplateRegistry myTemplates;
-
- private final boolean myUsePrecompiled;
-
- private final List/* <String> */myVariables;
-
- private final Map myCache;
-
- /**
- * FIXME variables - either String[] or wrap as UnmodifiableList
- *
- * @param baseURL
- * @param templates
- * @param usePrecompiled
- * @param variables
- */
- public YAEmitterFactory(URL baseURL, TemplateRegistry templates, boolean usePrecompiled, List/* <String> */variables, boolean cache) {
- assert baseURL != null && templates != null;
- assert variables == null || !variables.contains(null);
- myBaseURL = baseURL;
- myTemplates = templates;
- myUsePrecompiled = usePrecompiled;
- myVariables = variables == null ? Collections.EMPTY_LIST : variables;
- if (cache) {
- myCache = createCache();
- } else {
- myCache = null;
- }
- }
-
- /**
- * Instantiates {@link HashMap} by default. NOTE, this method is invoked
- * from constructor, object may not be fully initialized, don't use this
- * method for anything but cache instantiation.
- */
- protected Map/*<Object, JETEmitter>*/ createCache() {
- return new HashMap();
- }
-
- /**
- * @param key
- * @return <code>true</code> if template for the key passes is known to this factory
- */
- public boolean checkEmitter(Object key) {
- return checkCache(key) != null || myTemplates.getTemplatePath(key) != null;
- }
-
- /**
- * This is primary way to get emitters from this factory.
- * Checks cache (if there's one) first. Produces new emitter (with {@link #newEmitter(Object)}), caches and returns its outcome.
- */
- public JETEmitter acquireEmitter(Object key) throws JETException, NoSuchTemplateException, UnexpectedBehaviourException {
- JETEmitter em = checkCache(key);
- if (em != null) {
- return em;
- }
- em = newEmitter(key);
- cache(key, em);
- return em;
- }
-
- /**
- * Explicit way to produce new instance of emitter, passing over cache (if any).
- */
- public JETEmitter newEmitter(Object key) throws UnexpectedBehaviourException, NoSuchTemplateException, JETException {
- JETEmitter em;
- String fullPath = constructPath(key);
- ClassLoader cl;
- if (precompiledInUse(key)) {
- cl = myTemplates.getGeneratorClass(key).getClassLoader();
- } else {
- cl = getClass().getClassLoader();
- }
- em = new JETEmitter(fullPath, cl);
- feedVariables(em);
- initPrecompiled(key, em);
- return em;
- }
-
- private boolean precompiledInUse(Object key) {
- return myUsePrecompiled && myTemplates.hasGeneratorClass(key);
- }
-
- private void initPrecompiled(Object key, JETEmitter em) throws UnexpectedBehaviourException {
- try {
- if (precompiledInUse(key)) {
- Method m = myTemplates.getGeneratorClass(key).getMethod("generate", new Class[] { Object.class });
- em.setMethod(m);
- }
- } catch (NoSuchMethodException ex) {
- throw new UnexpectedBehaviourException("Bad template class", ex);
- }
- }
-
- private String constructPath(Object key) throws UnexpectedBehaviourException, NoSuchTemplateException {
- try {
- String path = myTemplates.getTemplatePath(key);
- if (path == null) {
- throw new NoSuchTemplateException(String.valueOf(key));
- }
- return new URL(myBaseURL, path).toString();
- } catch (MalformedURLException ex) {
- throw new UnexpectedBehaviourException(ex);
- }
- }
-
- private void feedVariables(JETEmitter em) throws JETException {
- for (Iterator it = myVariables.iterator(); it.hasNext();) {
- em.addVariable(null, (String) it.next());
- }
- }
-
- private JETEmitter checkCache(Object key) {
- if (myCache != null) {
- return (JETEmitter) myCache.get(key);
- }
- return null;
- }
-
- private void cache(Object key, JETEmitter emitter) {
- if (myCache != null) {
- myCache.put(key, emitter);
- }
- }
-}

Back to the top