Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.ext.beans;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import freemarker.core.CollectionAndSequence;
import freemarker.core._DelayedFTLTypeDescription;
import freemarker.core._DelayedJQuote;
import freemarker.core._TemplateModelException;
import freemarker.ext.util.ModelFactory;
import freemarker.ext.util.WrapperTemplateModel;
import freemarker.log.Logger;
import freemarker.template.AdapterTemplateModel;
import freemarker.template.ObjectWrapper;
import freemarker.template.SimpleScalar;
import freemarker.template.SimpleSequence;
import freemarker.template.TemplateCollectionModel;
import freemarker.template.TemplateHashModelEx;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import freemarker.template.TemplateModelIterator;
import freemarker.template.TemplateModelWithAPISupport;
import freemarker.template.TemplateScalarModel;
import freemarker.template.utility.StringUtil;
/**
* A class that will wrap an arbitrary object into {@link freemarker.template.TemplateHashModel}
* interface allowing calls to arbitrary property getters and invocation of
* accessible methods on the object from a template using the
* object.foo to access properties and object.bar(arg1, arg2) to
* invoke methods on it. You can also use the object.foo[index] syntax to
* access indexed properties. It uses Beans {@link java.beans.Introspector}
* to dynamically discover the properties and methods.
*/
public class BeanModel
implements TemplateHashModelEx, AdapterTemplateModel, WrapperTemplateModel, TemplateModelWithAPISupport {
private static final Logger LOG = Logger.getLogger("freemarker.beans");
protected final Object object;
protected final BeansWrapper wrapper;
// We use this to represent an unknown value as opposed to known value of null (JR)
static final TemplateModel UNKNOWN = new SimpleScalar("UNKNOWN");
static final ModelFactory FACTORY =
new ModelFactory()
{
@Override
public TemplateModel create(Object object, ObjectWrapper wrapper) {
return new BeanModel(object, (BeansWrapper) wrapper);
}
};
// I've tried to use a volatile ConcurrentHashMap field instead of HashMap + synchronized(this), but oddly it was
// a bit slower, at least on Java 8 u66.
private HashMap