http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultArrayAdapter.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultArrayAdapter.java b/src/main/java/freemarker/template/DefaultArrayAdapter.java deleted file mode 100644 index 578976c..0000000 --- a/src/main/java/freemarker/template/DefaultArrayAdapter.java +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.io.Serializable; -import java.lang.reflect.Array; - -import freemarker.ext.util.WrapperTemplateModel; - -/** - * Adapts an {@code array} of a non-primitive elements to the corresponding {@link TemplateModel} interface(s), most - * importantly to {@link TemplateHashModelEx}. If you aren't wrapping an already existing {@code array}, but build a - * sequence specifically to be used from a template, also consider using {@link SimpleSequence} (see comparison there). - * - * <p> - * Thread safety: A {@link DefaultListAdapter} is as thread-safe as the array that it wraps is. Normally you only - * have to consider read-only access, as the FreeMarker template language doesn't allow writing these sequences (though - * of course, Java methods called from the template can violate this rule). - * - * <p> - * This adapter is used by {@link DefaultObjectWrapper} if its {@code useAdaptersForCollections} property is - * {@code true}, which is the default when its {@code incompatibleImprovements} property is 2.3.22 or higher. - * - * @see SimpleSequence - * @see DefaultListAdapter - * @see TemplateSequenceModel - * - * @since 2.3.22 - */ -public abstract class DefaultArrayAdapter extends WrappingTemplateModel implements TemplateSequenceModel, - AdapterTemplateModel, WrapperTemplateModel, Serializable { - - /** - * Factory method for creating new adapter instances. - * - * @param array - * The array to adapt; can't be {@code null}. Must be an array. - * @param wrapper - * The {@link ObjectWrapper} used to wrap the items in the array. Has to be - * {@link ObjectWrapperAndUnwrapper} because of planned future features. - */ - public static DefaultArrayAdapter adapt(Object array, ObjectWrapperAndUnwrapper wrapper) { - final Class componentType = array.getClass().getComponentType(); - if (componentType == null) { - throw new IllegalArgumentException("Not an array"); - } - - if (componentType.isPrimitive()) { - if (componentType == int.class) { - return new IntArrayAdapter((int[]) array, wrapper); - } - if (componentType == double.class) { - return new DoubleArrayAdapter((double[]) array, wrapper); - } - if (componentType == long.class) { - return new LongArrayAdapter((long[]) array, wrapper); - } - if (componentType == boolean.class) { - return new BooleanArrayAdapter((boolean[]) array, wrapper); - } - if (componentType == float.class) { - return new FloatArrayAdapter((float[]) array, wrapper); - } - if (componentType == char.class) { - return new CharArrayAdapter((char[]) array, wrapper); - } - if (componentType == short.class) { - return new ShortArrayAdapter((short[]) array, wrapper); - } - if (componentType == byte.class) { - return new ByteArrayAdapter((byte[]) array, wrapper); - } - return new GenericPrimitiveArrayAdapter(array, wrapper); - } else { - return new ObjectArrayAdapter((Object[]) array, wrapper); - } - } - - private DefaultArrayAdapter(ObjectWrapper wrapper) { - super(wrapper); - } - - public final Object getAdaptedObject(Class hint) { - return getWrappedObject(); - } - - private static class ObjectArrayAdapter extends DefaultArrayAdapter { - - private final Object[] array; - - private ObjectArrayAdapter(Object[] array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < array.length ? wrap(array[index]) : null; - } - - public int size() throws TemplateModelException { - return array.length; - } - - public Object getWrappedObject() { - return array; - } - - } - - private static class ByteArrayAdapter extends DefaultArrayAdapter { - - private final byte[] array; - - private ByteArrayAdapter(byte[] array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < array.length ? wrap(Byte.valueOf(array[index])) : null; - } - - public int size() throws TemplateModelException { - return array.length; - } - - public Object getWrappedObject() { - return array; - } - - } - - private static class ShortArrayAdapter extends DefaultArrayAdapter { - - private final short[] array; - - private ShortArrayAdapter(short[] array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < array.length ? wrap(Short.valueOf(array[index])) : null; - } - - public int size() throws TemplateModelException { - return array.length; - } - - public Object getWrappedObject() { - return array; - } - - } - - private static class IntArrayAdapter extends DefaultArrayAdapter { - - private final int[] array; - - private IntArrayAdapter(int[] array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < array.length ? wrap(Integer.valueOf(array[index])) : null; - } - - public int size() throws TemplateModelException { - return array.length; - } - - public Object getWrappedObject() { - return array; - } - - } - - private static class LongArrayAdapter extends DefaultArrayAdapter { - - private final long[] array; - - private LongArrayAdapter(long[] array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < array.length ? wrap(Long.valueOf(array[index])) : null; - } - - public int size() throws TemplateModelException { - return array.length; - } - - public Object getWrappedObject() { - return array; - } - - } - - private static class FloatArrayAdapter extends DefaultArrayAdapter { - - private final float[] array; - - private FloatArrayAdapter(float[] array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < array.length ? wrap(Float.valueOf(array[index])) : null; - } - - public int size() throws TemplateModelException { - return array.length; - } - - public Object getWrappedObject() { - return array; - } - - } - - private static class DoubleArrayAdapter extends DefaultArrayAdapter { - - private final double[] array; - - private DoubleArrayAdapter(double[] array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < array.length ? wrap(Double.valueOf(array[index])) : null; - } - - public int size() throws TemplateModelException { - return array.length; - } - - public Object getWrappedObject() { - return array; - } - - } - - private static class CharArrayAdapter extends DefaultArrayAdapter { - - private final char[] array; - - private CharArrayAdapter(char[] array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < array.length ? wrap(Character.valueOf(array[index])) : null; - } - - public int size() throws TemplateModelException { - return array.length; - } - - public Object getWrappedObject() { - return array; - } - - } - - private static class BooleanArrayAdapter extends DefaultArrayAdapter { - - private final boolean[] array; - - private BooleanArrayAdapter(boolean[] array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < array.length ? wrap(Boolean.valueOf(array[index])) : null; - } - - public int size() throws TemplateModelException { - return array.length; - } - - public Object getWrappedObject() { - return array; - } - - } - - /** - * Much slower than the specialized versions; used only as the last resort. - */ - private static class GenericPrimitiveArrayAdapter extends DefaultArrayAdapter { - - private final Object array; - private final int length; - - private GenericPrimitiveArrayAdapter(Object array, ObjectWrapper wrapper) { - super(wrapper); - this.array = array; - length = Array.getLength(array); - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < length ? wrap(Array.get(array, index)) : null; - } - - public int size() throws TemplateModelException { - return length; - } - - public Object getWrappedObject() { - return array; - } - - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultIterableAdapter.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultIterableAdapter.java b/src/main/java/freemarker/template/DefaultIterableAdapter.java deleted file mode 100644 index 3bca9c3..0000000 --- a/src/main/java/freemarker/template/DefaultIterableAdapter.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Iterator; - -import freemarker.ext.util.WrapperTemplateModel; -import freemarker.template.utility.ObjectWrapperWithAPISupport; - -/** - * Adapts an {@link Iterable} to the corresponding {@link TemplateModel} interface(s), most importantly to - * {@link TemplateCollectionModel}. This should only be used if {@link Collection} is not implemented by the adapted - * object, because then {@link DefaultListAdapter} and {@link DefaultNonListCollectionAdapter} gives more functionality. - * - * <p> - * Thread safety: A {@link DefaultIterableAdapter} is as thread-safe as the {@link Iterable} that it wraps is. Normally - * you only have to consider read-only access, as the FreeMarker template language doesn't provide mean to call - * {@link Iterator} modifier methods (though of course, Java methods called from the template can violate this rule). - * - * <p> - * This adapter is used by {@link DefaultObjectWrapper} if its {@link DefaultObjectWrapper#setIterableSupport(boolean) - * iterableSupport} property is {@code true}, which is not the default for backward compatibility (so you have to set it - * explicitly). - * - * @since 2.3.25 - */ -@SuppressWarnings("serial") -public class DefaultIterableAdapter extends WrappingTemplateModel implements TemplateCollectionModel, - AdapterTemplateModel, WrapperTemplateModel, TemplateModelWithAPISupport, Serializable { - - private final Iterable<?> iterable; - - /** - * Factory method for creating new adapter instances. - * - * @param iterable - * The collection to adapt; can't be {@code null}. - * @param wrapper - * The {@link ObjectWrapper} used to wrap the items in the array. Has to be - * {@link ObjectWrapperAndUnwrapper} because of planned future features. - */ - public static DefaultIterableAdapter adapt(Iterable<?> iterable, ObjectWrapperWithAPISupport wrapper) { - return new DefaultIterableAdapter(iterable, wrapper); - } - - private DefaultIterableAdapter(Iterable<?> iterable, ObjectWrapperWithAPISupport wrapper) { - super(wrapper); - this.iterable = iterable; - } - - public TemplateModelIterator iterator() throws TemplateModelException { - return new DefaultUnassignableIteratorAdapter(iterable.iterator(), getObjectWrapper()); - } - - public Object getWrappedObject() { - return iterable; - } - - public Object getAdaptedObject(Class hint) { - return getWrappedObject(); - } - - public TemplateModel getAPI() throws TemplateModelException { - return ((ObjectWrapperWithAPISupport) getObjectWrapper()).wrapAsAPI(iterable); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultIteratorAdapter.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultIteratorAdapter.java b/src/main/java/freemarker/template/DefaultIteratorAdapter.java deleted file mode 100644 index 7ca7f31..0000000 --- a/src/main/java/freemarker/template/DefaultIteratorAdapter.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.io.Serializable; -import java.util.Iterator; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import freemarker.ext.util.WrapperTemplateModel; - -/** - * Adapts an {@link Iterator} to the corresponding {@link TemplateModel} interface(s), most importantly to - * {@link TemplateCollectionModel}. The resulting {@link TemplateCollectionModel} can only be listed (iterated) once. - * If the user tries list the variable for a second time, an exception will be thrown instead of silently gettig an - * empty (or partial) listing. - * - * <p> - * Thread safety: A {@link DefaultListAdapter} is as thread-safe as the array that it wraps is. Normally you only - * have to consider read-only access, as the FreeMarker template language doesn't allow writing these sequences (though - * of course, Java methods called from the template can violate this rule). - * - * <p> - * This adapter is used by {@link DefaultObjectWrapper} if its {@code useAdaptersForCollections} property is - * {@code true}, which is the default when its {@code incompatibleImprovements} property is 2.3.22 or higher. - * - * @since 2.3.22 - */ -public class DefaultIteratorAdapter extends WrappingTemplateModel implements TemplateCollectionModel, - AdapterTemplateModel, WrapperTemplateModel, Serializable { - - @SuppressFBWarnings(value="SE_BAD_FIELD", justification="We hope it's Seralizable") - private final Iterator iterator; - private boolean iteratorOwnedBySomeone; - - /** - * Factory method for creating new adapter instances. - * - * @param iterator - * The iterator to adapt; can't be {@code null}. - */ - public static DefaultIteratorAdapter adapt(Iterator iterator, ObjectWrapper wrapper) { - return new DefaultIteratorAdapter(iterator, wrapper); - } - - private DefaultIteratorAdapter(Iterator iterator, ObjectWrapper wrapper) { - super(wrapper); - this.iterator = iterator; - } - - public Object getWrappedObject() { - return iterator; - } - - public Object getAdaptedObject(Class hint) { - return getWrappedObject(); - } - - public TemplateModelIterator iterator() throws TemplateModelException { - return new SimpleTemplateModelIterator(); - } - - /** - * Not thread-safe. - */ - private class SimpleTemplateModelIterator implements TemplateModelIterator { - - private boolean iteratorOwnedByMe; - - public TemplateModel next() throws TemplateModelException { - if (!iteratorOwnedByMe) { - checkNotOwner(); - iteratorOwnedBySomeone = true; - iteratorOwnedByMe = true; - } - - if (!iterator.hasNext()) { - throw new TemplateModelException("The collection has no more items."); - } - - Object value = iterator.next(); - return value instanceof TemplateModel ? (TemplateModel) value : wrap(value); - } - - public boolean hasNext() throws TemplateModelException { - // Calling hasNext may looks safe, but I have met sync. problems. - if (!iteratorOwnedByMe) { - checkNotOwner(); - } - - return iterator.hasNext(); - } - - private void checkNotOwner() throws TemplateModelException { - if (iteratorOwnedBySomeone) { - throw new TemplateModelException( - "This collection value wraps a java.util.Iterator, thus it can be listed only once."); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultListAdapter.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultListAdapter.java b/src/main/java/freemarker/template/DefaultListAdapter.java deleted file mode 100644 index 39b107f..0000000 --- a/src/main/java/freemarker/template/DefaultListAdapter.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.io.Serializable; -import java.util.AbstractSequentialList; -import java.util.List; - -import freemarker.ext.util.WrapperTemplateModel; -import freemarker.template.utility.ObjectWrapperWithAPISupport; -import freemarker.template.utility.RichObjectWrapper; - -/** - * Adapts a {@link List} to the corresponding {@link TemplateModel} interface(s), most importantly to - * {@link TemplateSequenceModel}. If you aren't wrapping an already existing {@link List}, but build a sequence - * specifically to be used from a template, also consider using {@link SimpleSequence} (see comparison there). - * - * <p> - * Thread safety: A {@link DefaultListAdapter} is as thread-safe as the {@link List} that it wraps is. Normally you only - * have to consider read-only access, as the FreeMarker template language doesn't allow writing these sequences (though - * of course, Java methods called from the template can violate this rule). - * - * <p> - * This adapter is used by {@link DefaultObjectWrapper} if its {@code useAdaptersForCollections} property is - * {@code true}, which is the default when its {@code incompatibleImprovements} property is 2.3.22 or higher. - * - * @see SimpleSequence - * @see DefaultArrayAdapter - * @see TemplateSequenceModel - * - * @since 2.3.22 - */ -public class DefaultListAdapter extends WrappingTemplateModel implements TemplateSequenceModel, - AdapterTemplateModel, WrapperTemplateModel, TemplateModelWithAPISupport, Serializable { - - protected final List list; - - /** - * Factory method for creating new adapter instances. - * - * @param list - * The list to adapt; can't be {@code null}. - * @param wrapper - * The {@link ObjectWrapper} used to wrap the items in the array. - */ - public static DefaultListAdapter adapt(List list, RichObjectWrapper wrapper) { - // [2.4] DefaultListAdapter should implement TemplateCollectionModelEx, so this choice becomes unnecessary - return list instanceof AbstractSequentialList - ? new DefaultListAdapterWithCollectionSupport(list, wrapper) - : new DefaultListAdapter(list, wrapper); - } - - private DefaultListAdapter(List list, RichObjectWrapper wrapper) { - super(wrapper); - this.list = list; - } - - public TemplateModel get(int index) throws TemplateModelException { - return index >= 0 && index < list.size() ? wrap(list.get(index)) : null; - } - - public int size() throws TemplateModelException { - return list.size(); - } - - public Object getAdaptedObject(Class hint) { - return getWrappedObject(); - } - - public Object getWrappedObject() { - return list; - } - - private static class DefaultListAdapterWithCollectionSupport extends DefaultListAdapter implements - TemplateCollectionModel { - - private DefaultListAdapterWithCollectionSupport(List list, RichObjectWrapper wrapper) { - super(list, wrapper); - } - - public TemplateModelIterator iterator() throws TemplateModelException { - return new DefaultUnassignableIteratorAdapter(list.iterator(), getObjectWrapper()); - } - - } - - public TemplateModel getAPI() throws TemplateModelException { - return ((ObjectWrapperWithAPISupport) getObjectWrapper()).wrapAsAPI(list); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultMapAdapter.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultMapAdapter.java b/src/main/java/freemarker/template/DefaultMapAdapter.java deleted file mode 100644 index 68c1438..0000000 --- a/src/main/java/freemarker/template/DefaultMapAdapter.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.io.Serializable; -import java.util.Map; -import java.util.SortedMap; - -import freemarker.core._DelayedJQuote; -import freemarker.core._TemplateModelException; -import freemarker.ext.util.WrapperTemplateModel; -import freemarker.template.utility.ObjectWrapperWithAPISupport; - -/** - * Adapts a {@link Map} to the corresponding {@link TemplateModel} interface(s), most importantly to - * {@link TemplateHashModelEx}. If you aren't wrapping an already existing {@link Map}, but build a hash specifically to - * be used from a template, also consider using {@link SimpleHash} (see comparison there). - * - * <p> - * Thread safety: A {@link DefaultMapAdapter} is as thread-safe as the {@link Map} that it wraps is. Normally you only - * have to consider read-only access, as the FreeMarker template language doesn't allow writing these hashes (though of - * course, Java methods called from the template can violate this rule). - * - * <p> - * This adapter is used by {@link DefaultObjectWrapper} if its {@code useAdaptersForCollections} property is - * {@code true}, which is the default when its {@code incompatibleImprovements} property is 2.3.22 or higher. - * - * @since 2.3.22 - */ -public class DefaultMapAdapter extends WrappingTemplateModel - implements TemplateHashModelEx2, AdapterTemplateModel, WrapperTemplateModel, TemplateModelWithAPISupport, - Serializable { - - private final Map map; - - /** - * Factory method for creating new adapter instances. - * - * @param map - * The map to adapt; can't be {@code null}. - * @param wrapper - * The {@link ObjectWrapper} used to wrap the items in the array. - */ - public static DefaultMapAdapter adapt(Map map, ObjectWrapperWithAPISupport wrapper) { - return new DefaultMapAdapter(map, wrapper); - } - - private DefaultMapAdapter(Map map, ObjectWrapper wrapper) { - super(wrapper); - this.map = map; - } - - public TemplateModel get(String key) throws TemplateModelException { - Object val; - try { - val = map.get(key); - } catch (ClassCastException e) { - throw new _TemplateModelException(e, - "ClassCastException while getting Map entry with String key ", - new _DelayedJQuote(key)); - } catch (NullPointerException e) { - throw new _TemplateModelException(e, - "NullPointerException while getting Map entry with String key ", - new _DelayedJQuote(key)); - } - - if (val == null) { - // Check for Character key if this is a single-character string. - // In SortedMap-s, however, we can't do that safely, as it can cause ClassCastException. - if (key.length() == 1 && !(map instanceof SortedMap)) { - Character charKey = Character.valueOf(key.charAt(0)); - try { - val = map.get(charKey); - if (val == null) { - TemplateModel wrappedNull = wrap(null); - if (wrappedNull == null || !(map.containsKey(key) || map.containsKey(charKey))) { - return null; - } else { - return wrappedNull; - } - } - } catch (ClassCastException e) { - throw new _TemplateModelException(e, - "Class casting exception while getting Map entry with Character key ", - new _DelayedJQuote(charKey)); - } catch (NullPointerException e) { - throw new _TemplateModelException(e, - "NullPointerException while getting Map entry with Character key ", - new _DelayedJQuote(charKey)); - } - } else { // No char key fallback was possible - TemplateModel wrappedNull = wrap(null); - if (wrappedNull == null || !map.containsKey(key)) { - return null; - } else { - return wrappedNull; - } - } - } - - return wrap(val); - } - - public boolean isEmpty() { - return map.isEmpty(); - } - - public int size() { - return map.size(); - } - - public TemplateCollectionModel keys() { - return new SimpleCollection(map.keySet(), getObjectWrapper()); - } - - public TemplateCollectionModel values() { - return new SimpleCollection(map.values(), getObjectWrapper()); - } - - public KeyValuePairIterator keyValuePairIterator() { - return new MapKeyValuePairIterator(map, getObjectWrapper()); - } - - public Object getAdaptedObject(Class hint) { - return map; - } - - public Object getWrappedObject() { - return map; - } - - public TemplateModel getAPI() throws TemplateModelException { - return ((ObjectWrapperWithAPISupport) getObjectWrapper()).wrapAsAPI(map); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultNonListCollectionAdapter.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultNonListCollectionAdapter.java b/src/main/java/freemarker/template/DefaultNonListCollectionAdapter.java deleted file mode 100644 index 30d2df7..0000000 --- a/src/main/java/freemarker/template/DefaultNonListCollectionAdapter.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.io.Serializable; -import java.util.Collection; -import java.util.List; - -import freemarker.core._DelayedShortClassName; -import freemarker.core._TemplateModelException; -import freemarker.ext.util.WrapperTemplateModel; -import freemarker.template.utility.ObjectWrapperWithAPISupport; - -/** - * <b>Experimental - subject to change:</b> Adapts a non-{@link List} Java {@link Collection} to the corresponding - * {@link TemplateModel} interface(s), most importantly to {@link TemplateCollectionModelEx}. For {@link List}-s, use - * {@link DefaultListAdapter}, or else you lose indexed element access. - * - * <p> - * Thread safety: A {@link DefaultNonListCollectionAdapter} is as thread-safe as the {@link Collection} that it wraps - * is. Normally you only have to consider read-only access, as the FreeMarker template language doesn't allow writing - * these collections (though of course, Java methods called from the template can violate this rule). - * - * <p> - * This adapter is used by {@link DefaultObjectWrapper} if its {@code useAdaptersForCollections} property is - * {@code true}, which is the default when its {@code incompatibleImprovements} property is 2.3.22 or higher, and its - * {@link DefaultObjectWrapper#setForceLegacyNonListCollections(boolean) forceLegacyNonListCollections} property is - * {@code false}, which is still not the default as of 2.3.22 (so you have to set it explicitly). - * - * <p> - * <b>Experimental status warning:</b> This class is subject to change on non-backward compatible ways, hence, it - * shouldn't be used from outside FreeMarker yet. - * - * @since 2.3.22 - */ -public class DefaultNonListCollectionAdapter extends WrappingTemplateModel implements TemplateCollectionModelEx, - AdapterTemplateModel, WrapperTemplateModel, TemplateModelWithAPISupport, Serializable { - - private final Collection collection; - - /** - * Factory method for creating new adapter instances. - * - * @param collection - * The collection to adapt; can't be {@code null}. - * @param wrapper - * The {@link ObjectWrapper} used to wrap the items in the array. Has to be - * {@link ObjectWrapperAndUnwrapper} because of planned future features. - */ - public static DefaultNonListCollectionAdapter adapt(Collection collection, ObjectWrapperWithAPISupport wrapper) { - return new DefaultNonListCollectionAdapter(collection, wrapper); - } - - private DefaultNonListCollectionAdapter(Collection collection, ObjectWrapperWithAPISupport wrapper) { - super(wrapper); - this.collection = collection; - } - - public TemplateModelIterator iterator() throws TemplateModelException { - return new DefaultUnassignableIteratorAdapter(collection.iterator(), getObjectWrapper()); - } - - public int size() { - return collection.size(); - } - - public boolean isEmpty() { - return collection.isEmpty(); - } - - public Object getWrappedObject() { - return collection; - } - - public Object getAdaptedObject(Class hint) { - return getWrappedObject(); - } - - public boolean contains(TemplateModel item) throws TemplateModelException { - Object itemPojo = ((ObjectWrapperAndUnwrapper) getObjectWrapper()).unwrap(item); - try { - return collection.contains(itemPojo); - } catch (ClassCastException e) { - throw new _TemplateModelException(e, - "Failed to check if the collection contains the item. Probably the item's Java type, ", - itemPojo != null ? new _DelayedShortClassName(itemPojo.getClass()) : (Object) "Null", - ", doesn't match the type of (some of) the collection items; see cause exception."); - } - } - - public TemplateModel getAPI() throws TemplateModelException { - return ((ObjectWrapperWithAPISupport) getObjectWrapper()).wrapAsAPI(collection); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultObjectWrapper.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultObjectWrapper.java b/src/main/java/freemarker/template/DefaultObjectWrapper.java deleted file mode 100644 index 13fb104..0000000 --- a/src/main/java/freemarker/template/DefaultObjectWrapper.java +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.w3c.dom.Node; - -import freemarker.ext.beans.BeansWrapper; -import freemarker.ext.beans.BeansWrapperConfiguration; -import freemarker.ext.dom.NodeModel; - -/** - * The default implementation of the {@link ObjectWrapper} interface. Usually, you don't need to create instances of - * this, as an instance of this is already the default value of the - * {@link Configuration#setObjectWrapper(ObjectWrapper) object_wrapper setting}. Then the - * {@link #DefaultObjectWrapper(Version) incompatibleImprovements} of the {@link DefaultObjectWrapper} will be the same - * that you have set for the {@link Configuration} itself. As of this writing, it's highly recommended to use - * {@link Configuration#Configuration(Version) incompatibleImprovements} 2.3.22 (or higher). - * - * <p> - * If you still need to create an instance, that should be done with an {@link DefaultObjectWrapperBuilder} (or - * with {@link Configuration#setSetting(String, String)} with {@code "object_wrapper"} key), not with - * its constructor, as that allows FreeMarker to reuse singletons. For new projects, it's recommended to set - * {@link DefaultObjectWrapperBuilder#setForceLegacyNonListCollections(boolean) forceLegacyNonListCollections} to - * {@code false}, and {@link DefaultObjectWrapperBuilder#setIterableSupport(boolean) iterableSupport} to {@code true}; - * setting {@code incompatibleImprovements} to 2.3.22 won't do these, as they could break legacy templates too easily. - * - * <p> - * This class is only thread-safe after you have finished calling its setter methods, and then safely published it (see - * JSR 133 and related literature). When used as part of {@link Configuration}, of course it's enough if that was safely - * published and then left unmodified. - */ -public class DefaultObjectWrapper extends freemarker.ext.beans.BeansWrapper { - - /** @deprecated Use {@link DefaultObjectWrapperBuilder} instead, but mind its performance */ - @Deprecated - static final DefaultObjectWrapper instance = new DefaultObjectWrapper(); - - private boolean useAdaptersForContainers; - private boolean forceLegacyNonListCollections; - private boolean iterableSupport; - - /** - * Creates a new instance with the incompatible-improvements-version specified in - * {@link Configuration#DEFAULT_INCOMPATIBLE_IMPROVEMENTS}. - * - * @deprecated Use {@link DefaultObjectWrapperBuilder}, or in rare cases, - * {@link #DefaultObjectWrapper(Version)} instead. - */ - @Deprecated - public DefaultObjectWrapper() { - this(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); - } - - /** - * Use {@link DefaultObjectWrapperBuilder} instead if possible. Instances created with this constructor won't share - * the class introspection caches with other instances. See {@link BeansWrapper#BeansWrapper(Version)} (the - * superclass constructor) for more details. - * - * @param incompatibleImprovements - * It's the same as in {@link BeansWrapper#BeansWrapper(Version)}, plus these changes: - * <ul> - * <li>2.3.22 (or higher): The default value of - * {@link #setUseAdaptersForContainers(boolean) useAdaptersForContainers} changes to - * {@code true}.</li> - * <li>2.3.24 (or higher): When wrapping an {@link Iterator}, operations on it that only check if the - * collection is empty without reading an element from it, such as {@code ?has_content}, - * won't cause the a later iteration (or further emptiness check) to fail anymore. Earlier, in - * certain situations, the second operation has failed saying that the iterator "can be listed only - * once". - * </ul> - * - * @since 2.3.21 - */ - public DefaultObjectWrapper(Version incompatibleImprovements) { - this(new DefaultObjectWrapperConfiguration(incompatibleImprovements) { }, false); - } - - /** - * Use {@link #DefaultObjectWrapper(DefaultObjectWrapperConfiguration, boolean)} instead if possible; - * it does the same, except that it tolerates a non-{@link DefaultObjectWrapperConfiguration} configuration too. - * - * @since 2.3.21 - */ - protected DefaultObjectWrapper(BeansWrapperConfiguration bwCfg, boolean writeProtected) { - super(bwCfg, writeProtected, false); - DefaultObjectWrapperConfiguration dowDowCfg = bwCfg instanceof DefaultObjectWrapperConfiguration - ? (DefaultObjectWrapperConfiguration) bwCfg - : new DefaultObjectWrapperConfiguration(bwCfg.getIncompatibleImprovements()) { }; - useAdaptersForContainers = dowDowCfg.getUseAdaptersForContainers(); - forceLegacyNonListCollections = dowDowCfg.getForceLegacyNonListCollections(); - iterableSupport = dowDowCfg.getIterableSupport(); - finalizeConstruction(writeProtected); - } - - /** - * Calls {@link BeansWrapper#BeansWrapper(BeansWrapperConfiguration, boolean)} and sets up - * {@link DefaultObjectWrapper}-specific fields. - * - * @since 2.3.22 - */ - protected DefaultObjectWrapper(DefaultObjectWrapperConfiguration dowCfg, boolean writeProtected) { - this((BeansWrapperConfiguration) dowCfg, writeProtected); - } - - /** - * Wraps the parameter object to {@link TemplateModel} interface(s). Simple types like numbers, strings, booleans - * and dates will be wrapped into the corresponding {@code SimpleXxx} classes (like {@link SimpleNumber}). - * {@link Map}-s, {@link List}-s, other {@link Collection}-s, arrays and {@link Iterator}-s will be wrapped into the - * corresponding {@code SimpleXxx} or {@code DefaultXxxAdapter} classes (like {@link SimpleHash} or - * {@link DefaultMapAdapter}), depending on {@link #getUseAdaptersForContainers()} and - * {@link #getForceLegacyNonListCollections()}. After that, the wrapping is handled by - * {@link #handleUnknownType(Object)}, so see more there. - */ - @Override - public TemplateModel wrap(Object obj) throws TemplateModelException { - if (obj == null) { - return super.wrap(null); - } - if (obj instanceof TemplateModel) { - return (TemplateModel) obj; - } - if (obj instanceof String) { - return new SimpleScalar((String) obj); - } - if (obj instanceof Number) { - return new SimpleNumber((Number) obj); - } - if (obj instanceof java.util.Date) { - if (obj instanceof java.sql.Date) { - return new SimpleDate((java.sql.Date) obj); - } - if (obj instanceof java.sql.Time) { - return new SimpleDate((java.sql.Time) obj); - } - if (obj instanceof java.sql.Timestamp) { - return new SimpleDate((java.sql.Timestamp) obj); - } - return new SimpleDate((java.util.Date) obj, getDefaultDateType()); - } - final Class<?> objClass = obj.getClass(); - if (objClass.isArray()) { - if (useAdaptersForContainers) { - return DefaultArrayAdapter.adapt(obj, this); - } else { - obj = convertArray(obj); - // Falls through (a strange legacy...) - } - } - if (obj instanceof Collection) { - if (useAdaptersForContainers) { - if (obj instanceof List) { - return DefaultListAdapter.adapt((List<?>) obj, this); - } else { - return forceLegacyNonListCollections - ? (TemplateModel) new SimpleSequence((Collection<?>) obj, this) - : (TemplateModel) DefaultNonListCollectionAdapter.adapt((Collection<?>) obj, this); - } - } else { - return new SimpleSequence((Collection<?>) obj, this); - } - } - if (obj instanceof Map) { - return useAdaptersForContainers - ? (TemplateModel) DefaultMapAdapter.adapt((Map<?, ?>) obj, this) - : (TemplateModel) new SimpleHash((Map<?, ?>) obj, this); - } - if (obj instanceof Boolean) { - return obj.equals(Boolean.TRUE) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; - } - if (obj instanceof Iterator) { - return useAdaptersForContainers - ? (TemplateModel) DefaultIteratorAdapter.adapt((Iterator<?>) obj, this) - : (TemplateModel) new SimpleCollection((Iterator<?>) obj, this); - } - if (iterableSupport && obj instanceof Iterable) { - return DefaultIterableAdapter.adapt((Iterable<?>) obj, this); - } - return handleUnknownType(obj); - } - - /** - * Called for an object that isn't considered to be of a "basic" Java type, like for an application specific type, - * or for a W3C DOM node. In its default implementation, W3C {@link Node}-s will be wrapped as {@link NodeModel}-s - * (allows DOM tree traversal), others will be wrapped using {@link BeansWrapper#wrap(Object)}. - * - * <p> - * When you override this method, you should first decide if you want to wrap the object in a custom way (and if so - * then do it and return with the result), and if not, then you should call the super method (assuming the default - * behavior is fine with you). - */ - protected TemplateModel handleUnknownType(Object obj) throws TemplateModelException { - if (obj instanceof Node) { - return wrapDomNode(obj); - } - return super.wrap(obj); - } - - public TemplateModel wrapDomNode(Object obj) { - return NodeModel.wrap((Node) obj); - } - - /** - * Converts an array to a java.util.List. - */ - protected Object convertArray(Object arr) { - // FM 2.4: Use Arrays.asList instead - final int size = Array.getLength(arr); - ArrayList list = new ArrayList(size); - for (int i = 0; i < size; i++) { - list.add(Array.get(arr, i)); - } - return list; - } - - /** - * The getter pair of {@link #setUseAdaptersForContainers(boolean)}. - * - * @since 2.3.22 - */ - public boolean getUseAdaptersForContainers() { - return useAdaptersForContainers; - } - - /** - * Sets if to wrap container objects ({@link Map}-s, {@link List}-s, arrays and such) the legacy copying approach or - * the newer adapter approach should be used. {@code true} is recommended, which is also the default when the - * {@code incompatible_improvements} of this instance was set to {@link Configuration#VERSION_2_3_22} or higher. To - * understand the difference, check some of the classes that implement the two approaches: - * <ul> - * <li>Copying approach: {@link SimpleHash}, {@link SimpleSequence}</li> - * <li>Adapter approach: {@link DefaultMapAdapter}, {@link DefaultListAdapter}, {@link DefaultArrayAdapter}, - * {@link DefaultIteratorAdapter}</li> - * </ul> - * - * <p> - * See also the related Version History entry under 2.3.22 in the FreeMarker Manual, which gives a breakdown of - * the consequences. - * - * <p> - * <b>Attention:</b> For backward compatibility, currently, non-{@link List} collections (like {@link Set}-s) will - * only be wrapped with adapter approach (with {@link DefaultNonListCollectionAdapter}) if - * {@link #setForceLegacyNonListCollections(boolean) forceLegacyNonListCollections} was set to {@code false}. - * Currently the default is {@code true}, but in new projects you should set it to {@code false}. See - * {@link #setForceLegacyNonListCollections(boolean)} for more. - * - * @see #setForceLegacyNonListCollections(boolean) - * - * @since 2.3.22 - */ - public void setUseAdaptersForContainers(boolean useAdaptersForContainers) { - checkModifiable(); - this.useAdaptersForContainers = useAdaptersForContainers; - } - - /** - * Getter pair of {@link #setForceLegacyNonListCollections(boolean)}; see there. - * - * @since 2.3.22 - */ - public boolean getForceLegacyNonListCollections() { - return forceLegacyNonListCollections; - } - - /** - * Specifies whether non-{@link List} {@link Collection}-s (like {@link Set}-s) must be wrapped by pre-fetching into - * a {@link SimpleSequence}. The modern approach is wrapping into a {@link DefaultNonListCollectionAdapter}. This - * setting only has effect when {@link #getUseAdaptersForContainers()} is also {@code true}, as otherwise - * {@link SimpleSequence} will be used regardless of this. In new projects you should set this to {@code false}. At - * least before {@code incompatible_improvements} 2.4.0 it defaults to {@code true}, because of backward - * compatibility concerns: with {@link TemplateSequenceModel} templates could access the items by index if they - * wanted to (the index values were defined by the iteration order). This was not very useful, or was even - * confusing, and it conflicts with the adapter approach. - * - * @see #setUseAdaptersForContainers(boolean) - * - * @since 2.3.22 - */ - public void setForceLegacyNonListCollections(boolean forceLegacyNonListCollections) { - checkModifiable(); - this.forceLegacyNonListCollections = forceLegacyNonListCollections; - } - - /** - * Getter pair of {@link #setIterableSupport(boolean)}; see there. - * - * @since 2.3.25 - */ - public boolean getIterableSupport() { - return iterableSupport; - } - - /** - * Specifies whether {@link Iterable}-s (not to be confused with {@link Iterator}-s) that don't implement any other - * recognized Java interfaces (most notably {@link Collection}) will be recognized as listable objects - * ({@link TemplateCollectionModel}-s), or they will be just seen as generic objects (JavaBean-s). Defaults to - * {@code false} for backward compatibility, but in new projects you should set this to {@code true}. Before setting - * this to {@code true} in older projects, check if you have called {@code myIterable.iterator()} directly from any - * templates, because the Java API is only exposed to the templates if the {@link Iterable} is wrapped as generic - * object. - * - * @since 2.3.25 - */ - public void setIterableSupport(boolean iterableSupport) { - checkModifiable(); - this.iterableSupport = iterableSupport; - } - - /** - * Returns the lowest version number that is equivalent with the parameter version. - * - * @since 2.3.22 - */ - protected static Version normalizeIncompatibleImprovementsVersion(Version incompatibleImprovements) { - _TemplateAPI.checkVersionNotNullAndSupported(incompatibleImprovements); - Version bwIcI = BeansWrapper.normalizeIncompatibleImprovementsVersion(incompatibleImprovements); - return incompatibleImprovements.intValue() < _TemplateAPI.VERSION_INT_2_3_22 - || bwIcI.intValue() >= _TemplateAPI.VERSION_INT_2_3_22 - ? bwIcI : Configuration.VERSION_2_3_22; - } - - /** - * @since 2.3.22 - */ - @Override - protected String toPropertiesString() { - String bwProps = super.toPropertiesString(); - - // Remove simpleMapWrapper, as its irrelevant for this wrapper: - if (bwProps.startsWith("simpleMapWrapper")) { - int smwEnd = bwProps.indexOf(','); - if (smwEnd != -1) { - bwProps = bwProps.substring(smwEnd + 1).trim(); - } - } - - return "useAdaptersForContainers=" + useAdaptersForContainers + ", forceLegacyNonListCollections=" - + forceLegacyNonListCollections + ", iterableSupport=" + iterableSupport + bwProps; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultObjectWrapperBuilder.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultObjectWrapperBuilder.java b/src/main/java/freemarker/template/DefaultObjectWrapperBuilder.java deleted file mode 100644 index 7a6a027..0000000 --- a/src/main/java/freemarker/template/DefaultObjectWrapperBuilder.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; -import java.util.Map; -import java.util.WeakHashMap; - -import freemarker.ext.beans.BeansWrapperBuilder; -import freemarker.ext.beans._BeansAPI; - -/** - * Gets/creates a {@link DefaultObjectWrapper} singleton instance that's already configured as specified in the - * properties of this object; this is recommended over using the {@link DefaultObjectWrapper} constructors. The returned - * instance can't be further configured (it's write protected). - * - * <p>See {@link BeansWrapperBuilder} for more info, as that works identically. - * - * @since 2.3.21 - */ -public class DefaultObjectWrapperBuilder extends DefaultObjectWrapperConfiguration { - - private final static Map<ClassLoader, Map<DefaultObjectWrapperConfiguration, WeakReference<DefaultObjectWrapper>>> - INSTANCE_CACHE = new WeakHashMap< - ClassLoader, Map<DefaultObjectWrapperConfiguration, WeakReference<DefaultObjectWrapper>>>(); - private final static ReferenceQueue<DefaultObjectWrapper> INSTANCE_CACHE_REF_QUEUE - = new ReferenceQueue<DefaultObjectWrapper>(); - - /** - * Creates a builder that creates a {@link DefaultObjectWrapper} with the given {@code incompatibleImprovements}; - * using at least 2.3.22 is highly recommended. See {@link DefaultObjectWrapper#DefaultObjectWrapper(Version)} for - * more information about the impact of {@code incompatibleImprovements} values. - */ - public DefaultObjectWrapperBuilder(Version incompatibleImprovements) { - super(incompatibleImprovements); - } - - /** For unit testing only */ - static void clearInstanceCache() { - synchronized (INSTANCE_CACHE) { - INSTANCE_CACHE.clear(); - } - } - - /** - * Returns a {@link DefaultObjectWrapper} instance that matches the settings of this builder. This will be possibly - * a singleton that is also in use elsewhere. - */ - public DefaultObjectWrapper build() { - return _BeansAPI.getBeansWrapperSubclassSingleton( - this, INSTANCE_CACHE, INSTANCE_CACHE_REF_QUEUE, DefaultObjectWrapperFactory.INSTANCE); - } - - private static class DefaultObjectWrapperFactory - implements _BeansAPI._BeansWrapperSubclassFactory<DefaultObjectWrapper, DefaultObjectWrapperConfiguration> { - - private static final DefaultObjectWrapperFactory INSTANCE = new DefaultObjectWrapperFactory(); - - public DefaultObjectWrapper create(DefaultObjectWrapperConfiguration bwConf) { - return new DefaultObjectWrapper(bwConf, true); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultObjectWrapperConfiguration.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultObjectWrapperConfiguration.java b/src/main/java/freemarker/template/DefaultObjectWrapperConfiguration.java deleted file mode 100644 index cde1eca..0000000 --- a/src/main/java/freemarker/template/DefaultObjectWrapperConfiguration.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import freemarker.ext.beans.BeansWrapperConfiguration; - -/** - * Holds {@link DefaultObjectWrapper} configuration settings and defines their defaults. - * You will not use this abstract class directly, but concrete subclasses like {@link DefaultObjectWrapperBuilder}. - * Unless, you are developing a builder for a custom {@link DefaultObjectWrapper} subclass. In that case, note that - * overriding the {@link #equals} and {@link #hashCode} is important, as these objects are used as {@link ObjectWrapper} - * singleton lookup keys. - * - * @since 2.3.22 - */ -public abstract class DefaultObjectWrapperConfiguration extends BeansWrapperConfiguration { - - private boolean useAdaptersForContainers; - private boolean forceLegacyNonListCollections; - private boolean iterableSupport; - - protected DefaultObjectWrapperConfiguration(Version incompatibleImprovements) { - super(DefaultObjectWrapper.normalizeIncompatibleImprovementsVersion(incompatibleImprovements), true); - useAdaptersForContainers = getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_22; - forceLegacyNonListCollections = true; // [2.4]: = IcI < _TemplateAPI.VERSION_INT_2_4_0; - } - - /** See {@link DefaultObjectWrapper#getUseAdaptersForContainers()}. */ - public boolean getUseAdaptersForContainers() { - return useAdaptersForContainers; - } - - /** See {@link DefaultObjectWrapper#setUseAdaptersForContainers(boolean)}. */ - public void setUseAdaptersForContainers(boolean useAdaptersForContainers) { - this.useAdaptersForContainers = useAdaptersForContainers; - } - - /** See {@link DefaultObjectWrapper#getForceLegacyNonListCollections()}. */ - public boolean getForceLegacyNonListCollections() { - return forceLegacyNonListCollections; - } - - /** See {@link DefaultObjectWrapper#setForceLegacyNonListCollections(boolean)}. */ - public void setForceLegacyNonListCollections(boolean legacyNonListCollectionWrapping) { - this.forceLegacyNonListCollections = legacyNonListCollectionWrapping; - } - - /** - * See {@link DefaultObjectWrapper#getIterableSupport()}. - * - * @since 2.3.25 - */ - public boolean getIterableSupport() { - return iterableSupport; - } - - /** - * See {@link DefaultObjectWrapper#setIterableSupport(boolean)}. - * - * @since 2.3.25 - */ - public void setIterableSupport(boolean iterableSupport) { - this.iterableSupport = iterableSupport; - } - - @Override - public int hashCode() { - int result = super.hashCode(); - final int prime = 31; - result = result * prime + (useAdaptersForContainers ? 1231 : 1237); - result = result * prime + (forceLegacyNonListCollections ? 1231 : 1237); - result = result * prime + (iterableSupport ? 1231 : 1237); - return result; - } - - @Override - public boolean equals(Object that) { - if (!super.equals(that)) return false; - final DefaultObjectWrapperConfiguration thatDowCfg = (DefaultObjectWrapperConfiguration) that; - return useAdaptersForContainers == thatDowCfg.getUseAdaptersForContainers() - && forceLegacyNonListCollections == thatDowCfg.forceLegacyNonListCollections - && iterableSupport == thatDowCfg.iterableSupport; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/DefaultUnassignableIteratorAdapter.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/DefaultUnassignableIteratorAdapter.java b/src/main/java/freemarker/template/DefaultUnassignableIteratorAdapter.java deleted file mode 100644 index 383c390..0000000 --- a/src/main/java/freemarker/template/DefaultUnassignableIteratorAdapter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** - * As opposed to {@link DefaultIteratorAdapter}, this simpler {@link Iterator} adapter is used in situations where the - * {@link TemplateModelIterator} won't be assigned to FreeMarker template variables, only used internally by - * {@code #list} or custom Java code. Because of that, it doesn't have to handle the situation where the user tries to - * iterate over the same value twice. - */ -class DefaultUnassignableIteratorAdapter implements TemplateModelIterator { - - private final Iterator<?> it; - private final ObjectWrapper wrapper; - - DefaultUnassignableIteratorAdapter(Iterator<?> it, ObjectWrapper wrapper) { - this.it = it; - this.wrapper = wrapper; - } - - public TemplateModel next() throws TemplateModelException { - try { - return wrapper.wrap(it.next()); - } catch (NoSuchElementException e) { - throw new TemplateModelException("The collection has no more items.", e); - } - } - - public boolean hasNext() throws TemplateModelException { - return it.hasNext(); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/EmptyMap.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/EmptyMap.java b/src/main/java/freemarker/template/EmptyMap.java deleted file mode 100644 index 13c4448..0000000 --- a/src/main/java/freemarker/template/EmptyMap.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -/** - * Read-only empty map. {@link #remove(Object)}, {@link #clear()} and - * {@link #putAll(Map)} with an empty {@link Map} as parameter are supported - * operations (and do nothing) since FreeMarker 2.3.20. - * - * @deprecated Use {@link Collections#EMPTY_MAP} on J2SE 1.3 or later. - */ -@Deprecated -public class EmptyMap implements Map, Cloneable { - public static final EmptyMap instance = new EmptyMap(); - - public void clear() { - // no op - } - - public boolean containsKey(Object arg0) { - return false; - } - - public boolean containsValue(Object arg0) { - return false; - } - - public Set entrySet() { - return Collections.EMPTY_SET; - } - - public Object get(Object arg0) { - return null; - } - - public boolean isEmpty() { - return true; - } - - public Set keySet() { - return Collections.EMPTY_SET; - } - - public Object put(Object arg0, Object arg1) { - throw new UnsupportedOperationException("This Map is read-only."); - } - - public void putAll(Map arg0) { - // Checking for arg0.isEmpty() wouldn't reflect precisely how putAll in - // AbstractMap works. - if (arg0.entrySet().iterator().hasNext()) { - throw new UnsupportedOperationException("This Map is read-only."); - } - } - - public Object remove(Object arg0) { - return null; - } - - public int size() { - return 0; - } - - public Collection values() { - return Collections.EMPTY_LIST; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/FalseTemplateBooleanModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/FalseTemplateBooleanModel.java b/src/main/java/freemarker/template/FalseTemplateBooleanModel.java deleted file mode 100644 index 560ad02..0000000 --- a/src/main/java/freemarker/template/FalseTemplateBooleanModel.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -/** - * Used for the {@link TemplateBooleanModel#TRUE} singleton. - */ -final class FalseTemplateBooleanModel implements SerializableTemplateBooleanModel { - - public boolean getAsBoolean() { - return false; - } - - private Object readResolve() { - return FALSE; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/GeneralPurposeNothing.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/GeneralPurposeNothing.java b/src/main/java/freemarker/template/GeneralPurposeNothing.java deleted file mode 100644 index e078980..0000000 --- a/src/main/java/freemarker/template/GeneralPurposeNothing.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.util.ArrayList; -import java.util.List; - -/** - * Singleton object representing nothing, used by ?if_exists built-in. - * It is meant to be interpreted in the most sensible way possible in various contexts. - * This can be returned to avoid exceptions. - */ - -final class GeneralPurposeNothing -implements TemplateBooleanModel, TemplateScalarModel, TemplateSequenceModel, TemplateHashModelEx, TemplateMethodModelEx { - - private static final TemplateModel instance = new GeneralPurposeNothing(); - - private static final TemplateCollectionModel EMPTY_COLLECTION = new SimpleCollection(new ArrayList(0)); - - private GeneralPurposeNothing() { - } - - static TemplateModel getInstance() { - return instance; - } - - public String getAsString() { - return ""; - } - - public boolean getAsBoolean() { - return false; - } - - public boolean isEmpty() { - return true; - } - - public int size() { - return 0; - } - - public TemplateModel get(int i) throws TemplateModelException { - throw new TemplateModelException("Empty list"); - } - - public TemplateModel get(String key) { - return null; - } - - public Object exec(List args) { - return null; - } - - public TemplateCollectionModel keys() { - return EMPTY_COLLECTION; - } - - public TemplateCollectionModel values() { - return EMPTY_COLLECTION; - } -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/LocalizedString.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/LocalizedString.java b/src/main/java/freemarker/template/LocalizedString.java deleted file mode 100755 index 3cd4857..0000000 --- a/src/main/java/freemarker/template/LocalizedString.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.util.Locale; - -import freemarker.core.Environment; - -/** - * An abstract base class for scalars that vary by locale. - * Here is a silly usage example. - * <code> - * TemplateScalarModel localizedYes = new LocalizedString() { - * public String getLocalizedString(java.util.Locale locale) { - * String lang = locale.getLanguage(); - * if "fr".equals(lang) - * return "oui"; - * else if "de".equals(lang) - * return "sÃ"; - * else - * return "yes"; - * } - * }; - * </code> - */ - -abstract public class LocalizedString implements TemplateScalarModel { - - - public String getAsString() throws TemplateModelException { - Environment env = Environment.getCurrentEnvironment(); - Locale locale = env.getLocale(); - return getLocalizedString(locale); - } - - abstract public String getLocalizedString(Locale locale) throws TemplateModelException; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/MalformedTemplateNameException.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/MalformedTemplateNameException.java b/src/main/java/freemarker/template/MalformedTemplateNameException.java deleted file mode 100644 index fdc4cfd..0000000 --- a/src/main/java/freemarker/template/MalformedTemplateNameException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.io.IOException; - -import freemarker.cache.TemplateNameFormat; -import freemarker.template.utility.StringUtil; - -/** - * Indicates that the template name given was malformed according the {@link TemplateNameFormat} in use. Note that for - * backward compatibility, {@link TemplateNameFormat#DEFAULT_2_3_0} doesn't throw this exception, - * {@link TemplateNameFormat#DEFAULT_2_4_0} does. This exception extends {@link IOException} for backward compatibility. - * - * @since 2.3.22 - * - * @see TemplateNotFoundException - * @see Configuration#getTemplate(String) - */ -public class MalformedTemplateNameException extends IOException { - - private final String templateName; - private final String malformednessDescription; - - public MalformedTemplateNameException(String templateName, String malformednessDescription) { - super("Malformed template name, " + StringUtil.jQuote(templateName) + ": " + malformednessDescription); - this.templateName = templateName; - this.malformednessDescription = malformednessDescription; - } - - public String getTemplateName() { - return templateName; - } - - public String getMalformednessDescription() { - return malformednessDescription; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/MapKeyValuePairIterator.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/MapKeyValuePairIterator.java b/src/main/java/freemarker/template/MapKeyValuePairIterator.java deleted file mode 100644 index 4c5c1c0..0000000 --- a/src/main/java/freemarker/template/MapKeyValuePairIterator.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -import freemarker.template.TemplateHashModelEx2.KeyValuePair; -import freemarker.template.TemplateHashModelEx2.KeyValuePairIterator; - -/** - * Implementation of {@link KeyValuePairIterator} for a {@link TemplateHashModelEx2} that wraps or otherwise uses a - * {@link Map} internally. - * - * @since 2.3.25 - */ -public class MapKeyValuePairIterator implements KeyValuePairIterator { - - private final Iterator<Entry<?, ?>> entrySetIterator; - - private final ObjectWrapper objectWrapper; - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public <K, V> MapKeyValuePairIterator(Map<?, ?> map, ObjectWrapper objectWrapper) { - entrySetIterator = ((Map) map).entrySet().iterator(); - this.objectWrapper = objectWrapper; - } - - public boolean hasNext() { - return entrySetIterator.hasNext(); - } - - public KeyValuePair next() { - final Entry<?, ?> entry = entrySetIterator.next(); - return new KeyValuePair() { - - public TemplateModel getKey() throws TemplateModelException { - return wrap(entry.getKey()); - } - - public TemplateModel getValue() throws TemplateModelException { - return wrap(entry.getValue()); - } - - }; - } - - private TemplateModel wrap(Object obj) throws TemplateModelException { - return (obj instanceof TemplateModel) ? (TemplateModel) obj : objectWrapper.wrap(obj); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/ObjectWrapper.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/ObjectWrapper.java b/src/main/java/freemarker/template/ObjectWrapper.java deleted file mode 100644 index 4f97418..0000000 --- a/src/main/java/freemarker/template/ObjectWrapper.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 freemarker.template; - -import java.util.Map; -import java.util.ResourceBundle; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import freemarker.ext.beans.BeansWrapper; -import freemarker.ext.beans.BeansWrapperBuilder; -import freemarker.ext.util.WrapperTemplateModel; - -/** - * Maps Java objects to the type-system of FreeMarker Template Language (see the {@link TemplateModel} - * interfaces). Thus this is what decides what parts of the Java objects will be accessible in the templates and how. - * - * <p>For example, with a {@link BeansWrapper} both the items of {@link Map} and the JavaBean properties (the getters) - * of an object are accessible in template uniformly with the {@code myObject.foo} syntax, where "foo" is the map key or - * the property name. This is because both kind of object is wrapped by {@link BeansWrapper} into a - * {@link TemplateHashModel} implementation that will call {@link Map#get(Object)} or the getter method, transparently - * to the template language. - * - * @see Configuration#setObjectWrapper(ObjectWrapper) - */ -@SuppressFBWarnings(value="IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION", justification="BC") -public interface ObjectWrapper { - - /** - * An {@link ObjectWrapper} that exposes the object methods and JavaBeans properties as hash elements, and has - * custom handling for Java {@link Map}-s, {@link ResourceBundle}-s, etc. It doesn't treat - * {@link org.w3c.dom.Node}-s specially, however. As of 2.3.22, using - * {@link DefaultObjectWrapper} with its {@code incompatibleImprovements} property set to 2.3.22 (or higher) is - * recommended instead. - * - * @deprecated Use {@link BeansWrapperBuilder#build()} instead; this instance isn't read-only - * and thus can't be trusted. - */ - @Deprecated - ObjectWrapper BEANS_WRAPPER = BeansWrapper.getDefaultInstance(); - - /** - * The legacy default object wrapper implementation, focusing on backward compatibility and out-of-the W3C DOM - * wrapping box extra features. See {@link DefaultObjectWrapper} for more information. - * - * @deprecated Use {@link DefaultObjectWrapperBuilder#build()} instead; this instance isn't read-only and thus can't - * be trusted. - */ - @Deprecated - ObjectWrapper DEFAULT_WRAPPER = DefaultObjectWrapper.instance; - - /** - * Object wrapper that uses {@code SimpleXXX} wrappers only. - * It behaves like the {@link #DEFAULT_WRAPPER}, but for objects - * that it does not know how to wrap as a {@code SimpleXXX} it - * throws an exception. It makes no use of reflection-based - * exposure of anything, which may makes it a good candidate for security-restricted applications. - * - * @deprecated No replacement as it was seldom if ever used by anyone; this instance isn't - * read-only and thus can't be trusted. - */ - @Deprecated - ObjectWrapper SIMPLE_WRAPPER = SimpleObjectWrapper.instance; - - /** - * Makes a {@link TemplateModel} out of a non-{@link TemplateModel} object, usually by "wrapping" it into a - * {@link TemplateModel} implementation that delegates to the original object. - * - * @param obj The object to wrap into a {@link TemplateModel}. If it already implements {@link TemplateModel}, - * it should just return the object as is. If it's {@code null}, the method should return {@code null} - * (however, {@link BeansWrapper}, has a legacy option for returning a null model object instead, but it's not - * a good idea). - * - * @return a {@link TemplateModel} wrapper of the object passed in. To support un-wrapping, you may consider the - * return value to implement {@link WrapperTemplateModel} and {@link AdapterTemplateModel}. - * The default expectation is that the {@link TemplateModel} isn't less thread safe than the wrapped object. - * If the {@link ObjectWrapper} returns less thread safe objects, that should be clearly documented, as it - * restricts how it can be used, like, then it can't be used to wrap "shared variables" - * ({@link Configuration#setSharedVaribles(Map)}). - */ - TemplateModel wrap(Object obj) throws TemplateModelException; - -}
