Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/AbstractContextExtender.java3
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/JET2Context.java42
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java91
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java58
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java117
5 files changed, 178 insertions, 133 deletions
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/AbstractContextExtender.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/AbstractContextExtender.java
index 8dd8794..fa1aa1c 100644
--- a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/AbstractContextExtender.java
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/AbstractContextExtender.java
@@ -10,7 +10,7 @@
*
* </copyright>
*
- * $Id: AbstractContextExtender.java,v 1.3 2007/09/17 20:48:33 pelder Exp $
+ * $Id: AbstractContextExtender.java,v 1.4 2007/11/29 21:37:21 pelder Exp $
* /
*******************************************************************************/
@@ -32,6 +32,7 @@ package org.eclipse.jet;
* <li> (Recommended) Implement a <code>public static <i>YourExtender</i> getInstance(JET2Context)</code> method that returns an instance the
* AbstractContextExtender subclass.</li>
* </ol>
+ * @deprecated Since 0.9.0. Use public methods {@link JET2Context#addPrivateData(String, Object)} and {@link JET2Context#getPrivateData(String)}
*/
public abstract class AbstractContextExtender
{
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/JET2Context.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/JET2Context.java
index 9436cc6..bb63513 100644
--- a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/JET2Context.java
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/JET2Context.java
@@ -10,7 +10,7 @@
*
* </copyright>
*
- * $Id: JET2Context.java,v 1.2 2007/04/12 18:02:42 pelder Exp $
+ * $Id: JET2Context.java,v 1.3 2007/11/29 21:37:21 pelder Exp $
* /
*******************************************************************************/
@@ -61,6 +61,8 @@ public final class JET2Context
private final Set logListeners = new LinkedHashSet();
private final Map extendedContextData = new HashMap();
+
+ private final Map privateData = new HashMap();
private TagFactory tagFactory = null;
@@ -331,6 +333,7 @@ public final class JET2Context
* @param extenderClass the extender class
* @param extenderData the data to be associated with the class
* @throws IllegalStateException if <code>extenderClass</code> has already been registered on this context.
+ * @deprecated Use {@link #addPrivateData(String, Object)} instead.
*/
void registerContextExtender(Class extenderClass, Object extenderData)
{
@@ -352,6 +355,7 @@ public final class JET2Context
* </P>
* @param extenderClass the context extender class.
* @return the associated data or <code>null</code>.
+ * @deprecated Use {@link #getPrivateData(String)} instead.
*/
Object getContextExtenderData(Class extenderClass)
{
@@ -359,6 +363,42 @@ public final class JET2Context
}
/**
+ * Return private data associated with the key.
+ * @param key a private data key.
+ * @return the private data or <code>null</code> if not data is associate with the key.
+ * @since 0.9.0
+ */
+ public Object getPrivateData(String key) {
+ return privateData.get(key);
+ }
+
+ /**
+ * Add private data to the context.
+ * @param key the key for the private data
+ * @param value the data value
+ * @throws IllegalStateException if <code>key</code> has already been used to add private data.
+ * @throws NullPointerException if <code>value</code> or <code>key</code> is <code>null</code>.
+ * @see #getPrivateData(String)
+ */
+ public void addPrivateData(String key, Object value) {
+ if(privateData.containsKey(key)) {
+ throw new IllegalStateException();
+ }
+ if(key == null || value == null) {
+ throw new NullPointerException();
+ }
+ privateData.put(key, value);
+ }
+
+ /**
+ * Remove private data associated with the key. Quietly succeeds there is no private data for the key.
+ * @param key the key for the private data
+ */
+ public void removePrivateData(String key) {
+ privateData.remove(key);
+ }
+
+ /**
* Log an error on the pass template
* @param templatePath
* @param tagInfo
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java
index 9fea079..68ff1aa 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/FormatContextExtender.java
@@ -16,77 +16,72 @@
*/
package org.eclipse.jet.internal.taglib.format;
-import org.eclipse.jet.AbstractContextExtender;
+
import org.eclipse.jet.JET2Context;
+
/**
* Provide storage for unique and milliseconds tags
*/
-public class FormatContextExtender extends AbstractContextExtender
+public final class FormatContextExtender
{
- private static final class ContextData {
-
- private long lastMilliseconds = 0;
- private int lastUnique = 0;
+ private static String PRIVATE_CONTEXT_DATA_KEY = FormatContextExtender.class.getName();
- public long getMilliseconds() {
- long next = System.currentTimeMillis();
- if (next <= lastMilliseconds) {
- next = lastMilliseconds + 1;
- }
- lastMilliseconds = next;
- return next;
- }
-
- public int getUnique() {
- int unique = lastUnique + 1;
- lastUnique = unique;
- return unique;
- }
-
- }
-
- public static FormatContextExtender getInstance(JET2Context context)
- {
- return new FormatContextExtender(context);
- }
-
/**
- * @param context
+ * Return a FormatContextExtender for the given context. A new FormatContextExtender is created if
+ * none exists.
+ * @param context the JET2Context to extend.
+ * @return the FormatContextExtender
+ * @throws NullPointerException if <code>context</code> is <code>null</code>.
*/
- private FormatContextExtender(JET2Context context)
+ public static FormatContextExtender getInstance(JET2Context context)
{
- super(context);
+ if(context == null) {
+ throw new NullPointerException();
+ }
+ FormatContextExtender ex = (FormatContextExtender)context.getPrivateData(PRIVATE_CONTEXT_DATA_KEY);
+ if (ex == null)
+ {
+ ex = new FormatContextExtender();
+ context.addPrivateData(PRIVATE_CONTEXT_DATA_KEY, ex);
+ }
+ return ex;
}
- /* (non-Javadoc)
- * @see org.eclipse.jet.AbstractContextExtender#createExtendedData(org.eclipse.jet.JET2Context)
+ private long lastMilliseconds = 0;
+
+ private int lastUnique = 0;
+
+ /**
*/
- protected Object createExtendedData(JET2Context context)
+ private FormatContextExtender()
{
- return new ContextData();
+ super();
}
-
-
/**
* Reurns a unique system time in milliseconds.
- */
- public long getMilliseconds() {
- return getData().getMilliseconds();
- }
-
- private ContextData getData()
+ */
+ public long getMilliseconds()
{
- return (ContextData)getExtendedData();
+ long next = System.currentTimeMillis();
+ if (next <= lastMilliseconds)
+ {
+ next = lastMilliseconds + 1;
+ }
+ lastMilliseconds = next;
+ return next;
}
/**
* Reurns a unique integer.
- */
- public int getUnique() {
- return getData().getUnique();
- }
+ */
+ public int getUnique()
+ {
+ int unique = lastUnique + 1;
+ lastUnique = unique;
+ return unique;
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java
index a6bee35..8f3816a 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java
@@ -35,7 +35,6 @@ import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jet.AbstractContextExtender;
import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.internal.InternalJET2Platform;
@@ -50,8 +49,9 @@ import org.eclipse.jet.transform.TransformContextListener;
* performing them at the end of a JET2 transformation.
*
*/
-public class WorkspaceContextExtender extends AbstractContextExtender
+public final class WorkspaceContextExtender
{
+ private static String PRIVATE_CONTEXT_DATA_KEY = WorkspaceContextExtender.class.getName();
private static final String RESOURCE_VAR_PREFIX = "org.eclipse.jet.resource."; //$NON-NLS-1$
/**
@@ -148,11 +148,11 @@ public class WorkspaceContextExtender extends AbstractContextExtender
private static final class ContextData implements TransformContextListener
{
- private final List workspaceActions = new ArrayList();
+ public final List workspaceActions = new ArrayList();
- private final Stack containerStack = new Stack();
+ public final Stack containerStack = new Stack();
- private final List finalWorkspaceActions = new ArrayList();
+ public final List finalWorkspaceActions = new ArrayList();
public ContextData()
{
@@ -266,35 +266,28 @@ public class WorkspaceContextExtender extends AbstractContextExtender
/**
* Create a workspace context extender on the passed context.
* @param context a JET2Context. Cannot be <code>null</code>.
+ * @deprecated Since 0.9.0, use {@link WorkspaceContextExtender#getInstance(JET2Context)} instead.
*/
public WorkspaceContextExtender(JET2Context context)
{
- super(context);
+ this(context, getInstance(context).contextData);
}
- /* (non-Javadoc)
- * @see org.eclipse.jet.AbstractContextExtender#createExtendedData(org.eclipse.jet.JET2Context)
- */
- protected Object createExtendedData(JET2Context context)
- {
- ContextData contextData = new ContextData();
- TransformContextExtender tce = new TransformContextExtender(context);
- tce.addListener(contextData);
- return contextData;
- }
-
- private final ContextData getData()
+ private WorkspaceContextExtender(JET2Context context, ContextData contextData)
{
- return (ContextData)getExtendedData();
+ this.contextData = contextData;
+ TransformContextExtender.getInstance(context).addListener(contextData);
}
+ private final ContextData contextData;
+
/**
* Add a new action to be executed when the JET2 transform commits.
* @param action the action to execute
*/
public void addAction(IWorkspaceAction action)
{
- getData().workspaceActions.add(action);
+ contextData.workspaceActions.add(action);
}
/**
@@ -309,7 +302,7 @@ public class WorkspaceContextExtender extends AbstractContextExtender
*/
public void addFinalAction(IWorkspaceAction action)
{
- getData().finalWorkspaceActions.add(action);
+ contextData.finalWorkspaceActions.add(action);
}
/**
* Push a default container onto the stack of default containers.
@@ -317,7 +310,7 @@ public class WorkspaceContextExtender extends AbstractContextExtender
*/
public void pushContainer(IContainer container)
{
- getData().containerStack.push(container);
+ contextData.containerStack.push(container);
}
/**
@@ -326,11 +319,11 @@ public class WorkspaceContextExtender extends AbstractContextExtender
*/
public void popContainer() throws JET2TagException
{
- if (getData().containerStack.isEmpty())
+ if (contextData.containerStack.isEmpty())
{
throw new JET2TagException(JET2Messages.WorkspaceContextExtender_NoParent);
}
- getData().containerStack.pop();
+ contextData.containerStack.pop();
}
/**
@@ -339,7 +332,7 @@ public class WorkspaceContextExtender extends AbstractContextExtender
*/
public boolean existsContainer()
{
- return !getData().containerStack.isEmpty();
+ return !contextData.containerStack.isEmpty();
}
/**
@@ -349,11 +342,11 @@ public class WorkspaceContextExtender extends AbstractContextExtender
*/
public IContainer getContainer() throws JET2TagException
{
- if (getData().containerStack.isEmpty())
+ if (contextData.containerStack.isEmpty())
{
throw new JET2TagException(JET2Messages.WorkspaceContextExtender_NoParent);
}
- return (IContainer)getData().containerStack.peek();
+ return (IContainer)contextData.containerStack.peek();
}
/**
@@ -363,7 +356,16 @@ public class WorkspaceContextExtender extends AbstractContextExtender
*/
public static WorkspaceContextExtender getInstance(JET2Context context)
{
- return new WorkspaceContextExtender(context);
+ if(context == null) {
+ throw new NullPointerException();
+ }
+ WorkspaceContextExtender ex = (WorkspaceContextExtender)context.getPrivateData(PRIVATE_CONTEXT_DATA_KEY);
+ if (ex == null)
+ {
+ ex = new WorkspaceContextExtender(context, new ContextData());
+ context.addPrivateData(PRIVATE_CONTEXT_DATA_KEY, ex);
+ }
+ return ex;
}
/**
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
index d5be963..72e1602 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
@@ -29,7 +29,6 @@ import java.util.Stack;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jet.AbstractContextExtender;
import org.eclipse.jet.BodyContentWriter;
import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2Context;
@@ -53,50 +52,49 @@ import org.osgi.framework.BundleException;
* Extender to the JET2Context for supporting JET2 Transforms
*
*/
-public class TransformContextExtender extends AbstractContextExtender
+public final class TransformContextExtender
{
+ private static String PRIVATE_CONTEXT_DATA_KEY = TransformContextExtender.class.getName();
+ private final org.eclipse.jet.transform.TransformContextExtender.ContextData contextData;
+ private final JET2Context context;
+
private static final class ContextData
{
- private final Stack templateStack = new Stack();
+ public final Stack templateStack = new Stack();
- private JET2TemplateLoader loader;
+ public JET2TemplateLoader loader;
- private List listeners = new ArrayList();
+ public List listeners = new ArrayList();
- private Object shellContext = null;
+ public Object shellContext = null;
- private IJETBundleDescriptor descriptor = null;
+ public IJETBundleDescriptor descriptor = null;
- private final List connectedTransforms = new ArrayList();
+ public final List connectedTransforms = new ArrayList();
}
/**
- * @param context
+ * Create a TransformContextExtender for the current context.
+ * @param context the context.
+ * @deprecated Since 0.9.0 use {@link TransformContextExtender#getInstance(JET2Context)}.
*/
public TransformContextExtender(JET2Context context)
{
- super(context);
- }
-
- private final ContextData getData()
- {
- return (ContextData)getExtendedData();
+ this(context, getInstance(context).contextData);
}
- /* (non-Javadoc)
- * @see org.eclipse.jet.AbstractContextExtender#createExtendedData(org.eclipse.jet.JET2Context)
- */
- protected Object createExtendedData(JET2Context context)
+ private TransformContextExtender(JET2Context context, ContextData contextData)
{
+ this.context = context;
+ this.contextData = contextData;
context.setTagFactory(new TagFactoryImpl(context));
- return new ContextData();
}
public String getId()
{
- return getData().descriptor.getId();
+ return contextData.descriptor.getId();
}
/**
@@ -105,7 +103,7 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public String getTemplatePath()
{
- return getData().templateStack.isEmpty() ? "" : (String)getData().templateStack.peek(); //$NON-NLS-1$
+ return contextData.templateStack.isEmpty() ? "" : (String)contextData.templateStack.peek(); //$NON-NLS-1$
}
/**
@@ -128,11 +126,11 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public void execute(String templatePath, boolean useSuper, JET2Writer writer) throws JET2TagException
{
- getData().templateStack.push(templatePath);
- getContext().setTemplatePath(getTemplatePath());
+ contextData.templateStack.push(templatePath);
+ context.setTemplatePath(getTemplatePath());
try
{
- JET2TemplateLoader templateLoader = getData().loader;
+ JET2TemplateLoader templateLoader = contextData.loader;
if(useSuper) {
templateLoader = templateLoader instanceof JET2TemplateLoaderExtension ? ((JET2TemplateLoaderExtension)templateLoader).getDelegateLoader() : null;
}
@@ -143,19 +141,19 @@ public class TransformContextExtender extends AbstractContextExtender
String msg = JET2Messages.JET2Context_CouldNotFindTemplate;
throw new JET2TagException(MessageFormat.format(msg, new Object []{ templatePath }));
}
- template.generate(getContext(), writer);
+ template.generate(context, writer);
}
finally
{
- getData().templateStack.pop();
- getContext().setTemplatePath(getTemplatePath());
+ contextData.templateStack.pop();
+ context.setTemplatePath(getTemplatePath());
}
}
public JET2TemplateLoader getLoader()
{
- return getData().loader;
+ return contextData.loader;
}
/**
@@ -164,11 +162,11 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public void setLoader(JET2TemplateLoader loader)
{
- if (getData().loader != null)
+ if (contextData.loader != null)
{
throw new IllegalStateException("loader already set"); //$NON-NLS-1$
}
- getData().loader = loader;
+ contextData.loader = loader;
}
/**
@@ -179,9 +177,9 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public void addListener(TransformContextListener listener)
{
- if (!getData().listeners.contains(listener))
+ if (!contextData.listeners.contains(listener))
{
- getData().listeners.add(listener);
+ contextData.listeners.add(listener);
}
}
@@ -193,7 +191,7 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public void removeListener(TransformContextListener listener)
{
- getData().listeners.remove(listener);
+ contextData.listeners.remove(listener);
}
/**
@@ -203,20 +201,20 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public void commit(IProgressMonitor monitor)
{
- monitor.beginTask(JET2Messages.JET2Context_CommittingActions, getData().listeners.size());
+ monitor.beginTask(JET2Messages.JET2Context_CommittingActions, contextData.listeners.size());
try
{
- for (Iterator i = getData().listeners.iterator(); i.hasNext();)
+ for (Iterator i = contextData.listeners.iterator(); i.hasNext();)
{
TransformContextListener listener = (TransformContextListener)i.next();
try
{
- listener.commit(getContext(), new SubProgressMonitor(monitor, 1));
+ listener.commit(context, new SubProgressMonitor(monitor, 1));
}
catch (JET2TagException e)
{
- getContext().logError(e);
+ context.logError(e);
}
monitor.worked(1);
}
@@ -235,7 +233,7 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public final Object getShellContext()
{
- return getData().shellContext;
+ return contextData.shellContext;
}
/**
@@ -254,11 +252,11 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public final void setShellContext(Object shellContext)
{
- if (getData().shellContext != null)
+ if (contextData.shellContext != null)
{
throw new IllegalStateException("shellContext already set"); //$NON-NLS-1$
}
- getData().shellContext = shellContext;
+ contextData.shellContext = shellContext;
}
/**
@@ -268,12 +266,12 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public void setBundleDescriptor(IJETBundleDescriptor descriptor)
{
- if (getData().descriptor != null)
+ if (contextData.descriptor != null)
{
throw new IllegalStateException();
}
- getData().descriptor = descriptor;
- getContext().setJETBundleId(descriptor.getId());
+ contextData.descriptor = descriptor;
+ context.setJETBundleId(descriptor.getId());
}
/**
@@ -282,7 +280,7 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public IJETBundleDescriptor getBundleDescriptor()
{
- return getData().descriptor;
+ return contextData.descriptor;
}
/**
@@ -330,7 +328,16 @@ public class TransformContextExtender extends AbstractContextExtender
*/
public static TransformContextExtender getInstance(JET2Context context)
{
- return new TransformContextExtender(context);
+ if(context == null) {
+ throw new NullPointerException();
+ }
+ TransformContextExtender ex = (TransformContextExtender)context.getPrivateData(PRIVATE_CONTEXT_DATA_KEY);
+ if (ex == null)
+ {
+ ex = new TransformContextExtender(context, new ContextData());
+ context.addPrivateData(PRIVATE_CONTEXT_DATA_KEY, ex);
+ }
+ return ex;
}
/**
@@ -378,7 +385,7 @@ public class TransformContextExtender extends AbstractContextExtender
try
{
bundleManager.connect(id, monitor != null ? monitor : new NullProgressMonitor());
- getData().connectedTransforms.add(id);
+ contextData.connectedTransforms.add(id);
final JET2TemplateLoader delegateLoader = bundleManager.getTemplateLoader(id);
final JET2TemplateLoader loader = getLoader();
@@ -403,7 +410,7 @@ public class TransformContextExtender extends AbstractContextExtender
{
// clean-up load transforms...
final IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
- for (Iterator i = getData().connectedTransforms.iterator(); i.hasNext();)
+ for (Iterator i = contextData.connectedTransforms.iterator(); i.hasNext();)
{
String id = (String)i.next();
bundleManager.disconnect(id);
@@ -413,17 +420,17 @@ public class TransformContextExtender extends AbstractContextExtender
public void runSubTransform(String id) throws JET2TagException
{
final IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
- final IJETBundleDescriptor savedDescriptor = getData().descriptor;
- final JET2TemplateLoader savedLoader = getData().loader;
+ final IJETBundleDescriptor savedDescriptor = contextData.descriptor;
+ final JET2TemplateLoader savedLoader = contextData.loader;
try
{
bundleManager.connect(id, new NullProgressMonitor());
- getData().connectedTransforms.add(id);
+ contextData.connectedTransforms.add(id);
final JET2TemplateLoader loader = bundleManager.getTemplateLoader(id);
final IJETBundleDescriptor descriptor = bundleManager.getDescriptor(id);
- getData().loader = loader;
- getData().descriptor = descriptor;
+ contextData.loader = loader;
+ contextData.descriptor = descriptor;
if(descriptor.getOverridesId() != null)
{
@@ -439,8 +446,8 @@ public class TransformContextExtender extends AbstractContextExtender
}
finally
{
- getData().descriptor = savedDescriptor;
- getData().loader = savedLoader;
+ contextData.descriptor = savedDescriptor;
+ contextData.loader = savedLoader;
}
}

Back to the top