| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| UndefinedMacro |
|
| 1.2857142857142858;1.286 |
| 1 | /* | |
| 2 | * Copyright (C) 1998-2001 Semiotek Inc. All Rights Reserved. | |
| 3 | * | |
| 4 | * Redistribution and use in source and binary forms, with or without | |
| 5 | * modification, are permitted under the terms of either of the following | |
| 6 | * Open Source licenses: | |
| 7 | * | |
| 8 | * The GNU General Public License, version 2, or any later version, as | |
| 9 | * published by the Free Software Foundation | |
| 10 | * (http://www.fsf.org/copyleft/gpl.html); | |
| 11 | * | |
| 12 | * or | |
| 13 | * | |
| 14 | * The Semiotek Public License (http://webmacro.org/LICENSE.) | |
| 15 | * | |
| 16 | * This software is provided "as is", with NO WARRANTY, not even the | |
| 17 | * implied warranties of fitness to purpose, or merchantability. You | |
| 18 | * assume all risks and liabilities associated with its use. | |
| 19 | * | |
| 20 | * See www.webmacro.org for more information on the WebMacro project. | |
| 21 | */ | |
| 22 | ||
| 23 | package org.webmacro.engine; | |
| 24 | ||
| 25 | import org.webmacro.Context; | |
| 26 | import org.webmacro.FastWriter; | |
| 27 | import org.webmacro.Macro; | |
| 28 | import org.webmacro.PropertyException; | |
| 29 | import org.webmacro.TemplateVisitor; | |
| 30 | import org.webmacro.Visitable; | |
| 31 | ||
| 32 | /** | |
| 33 | * Looks like a Macro, but really it's an undefined variable. | |
| 34 | */ | |
| 35 | public final class UndefinedMacro implements Macro, Visitable | |
| 36 | { | |
| 37 | ||
| 38 | 2 | final static private UndefinedMacro _singleton = new UndefinedMacro(); |
| 39 | ||
| 40 | private UndefinedMacro () | |
| 41 | 2 | { |
| 42 | 2 | } |
| 43 | ||
| 44 | static public UndefinedMacro getInstance () | |
| 45 | { | |
| 46 | 8 | return _singleton; |
| 47 | } | |
| 48 | ||
| 49 | public final String toString () | |
| 50 | { | |
| 51 | 0 | throw new UnsupportedOperationException( |
| 52 | "Cannot invoke toString() on an undefined variable."); | |
| 53 | } | |
| 54 | ||
| 55 | public void accept (TemplateVisitor v) | |
| 56 | { | |
| 57 | 0 | v.visitString(toString()); |
| 58 | 0 | } |
| 59 | ||
| 60 | /** | |
| 61 | * Returns the wrapped object, context is ignored. | |
| 62 | */ | |
| 63 | public final Object evaluate (Context context) | |
| 64 | { | |
| 65 | 11038 | return _singleton; |
| 66 | } | |
| 67 | ||
| 68 | public Object get (Object key) | |
| 69 | { | |
| 70 | 0 | return _singleton; |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Throws an exception -- cannot write an undefined. | |
| 75 | */ | |
| 76 | public final void write (FastWriter out, Context context) | |
| 77 | throws PropertyException | |
| 78 | { | |
| 79 | 4 | throw new PropertyException.UndefinedVariableException(); |
| 80 | } | |
| 81 | } |