Package freemarker.ext.beans

Examples of freemarker.ext.beans.BeansWrapper


            }
        }

        public Object exec(List arguments) throws TemplateModelException {
            ObjectWrapper ow = env.getObjectWrapper();
            BeansWrapper bw =
                ow instanceof BeansWrapper
                ? (BeansWrapper)ow
                : BeansWrapper.getDefaultInstance();
            return bw.newInstance(cl, arguments);
        }
View Full Code Here


        CURRENT.set(previous);
    }

    public BeansWrapper getObjectWrapper() {
        if (objectWrapper == null) {
            objectWrapper = new BeansWrapper(Configuration.VERSION_2_3_21);
        }
        return objectWrapper;
    }
View Full Code Here

    }
    Writer out = null;
    try {
     
      cfg.setDirectoryForTemplateLoading(path);
      cfg.setObjectWrapper(new BeansWrapper());
      Template temp = cfg.getTemplate(tName);
      out = new PrintWriter(real);

      if (this.parent != null) {
        log.info("need to putall parent.props");
View Full Code Here

            Configuration fc = new Configuration();
            fc.setLocalizedLookup(false);
            fc.setTagSyntax(SQUARE_BRACKET_TAG_SYNTAX);
            fc.setTemplateUpdateDelay(Integer.MAX_VALUE);
            fc.setNumberFormat("computer");
            BeansWrapper bw = (BeansWrapper) fc.getObjectWrapper();
            bw.setExposureLevel(EXPOSE_PROPERTIES_ONLY);
            return fc;
        }
View Full Code Here

    protected abstract Component getBean();

    protected Map unwrapParameters(Map params) {
        Map map = new HashMap(params.size());
        BeansWrapper objectWrapper = BeansWrapper.getDefaultInstance();
        for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();

            Object value = entry.getValue();

            if (value != null) {
                // the value should ALWAYS be a decendant of TemplateModel
                if (value instanceof TemplateModel) {
                    try {
                        map.put(entry.getKey(), objectWrapper
                            .unwrap((TemplateModel) value));
                    } catch (TemplateModelException e) {
                        LOG.error("failed to unwrap [" + value
                            + "] it will be ignored", e);
                    }
View Full Code Here

        return javaFields.toArray(new JavaField[javaFields.size()]);
    }

    private Map<String, Object> _getContext() throws TemplateModelException {
        BeansWrapper wrapper = BeansWrapper.getDefaultInstance();

        TemplateHashModel staticModels = wrapper.getStaticModels();

        Map<String, Object> context = new HashMap<String, Object>();

        context.put("hbmFileName", _hbmFileName);
        context.put("ormFileName", _ormFileName);
        context.put("modelHintsFileName", _modelHintsFileName);
        context.put("springFileName", _springFileName);
        context.put("springBaseFileName", _springBaseFileName);
        context.put("springHibernateFileName", _springHibernateFileName);
        context.put(
                "springInfrastructureFileName", _springInfrastructureFileName);
        context.put("apiDir", _apiDir);
        context.put("implDir", _implDir);
        context.put("sqlDir", _sqlDir);
        context.put("sqlFileName", _sqlFileName);
        context.put("beanLocatorUtil", _beanLocatorUtil);
        context.put("beanLocatorUtilShortName", _beanLocatorUtilShortName);
        context.put("propsUtil", _propsUtil);
        context.put("portletName", _portletName);
        context.put("portletShortName", _portletShortName);
        context.put("portletPackageName", _portletPackageName);
        context.put("outputPath", _outputPath);
        context.put("serviceOutputPath", _serviceOutputPath);
        context.put("packagePath", _packagePath);
        context.put("pluginName", _pluginName);
        context.put("author", _author);
        context.put("serviceBuilder", this);

        context.put("arrayUtil", ArrayUtil_IW.getInstance());
        context.put("modelHintsUtil", _modelHints.getModelHints());
        context.put(
                "resourceActionsUtil", ResourceActionsUtil.getResourceActions());
        context.put("stringUtil", StringUtil_IW.getInstance());
        context.put("system", staticModels.get("java.lang.System"));
        context.put("tempMap", wrapper.wrap(new HashMap<String, Object>()));
        context.put(
                "textFormatter", staticModels.get(TextFormatter.class.getName()));
        context.put("validator", Validator_IW.getInstance());

        return context;
View Full Code Here

    Configuration cfg = new Configuration();

    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    BeansWrapper wrapper = new BeansWrapper();
    wrapper.setSimpleMapWrapper(true);
    cfg.setObjectWrapper(wrapper);

    Map<Object, Object> model = buildModel(ticketsMap);

    try {
View Full Code Here

    protected abstract Component getBean();

    protected Map unwrapParameters(Map params) {
        Map map = new HashMap(params.size());
        BeansWrapper objectWrapper = BeansWrapper.getDefaultInstance();
        for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();

            Object value = entry.getValue();

            if (value != null) {
                // the value should ALWAYS be a decendant of TemplateModel
                if (value instanceof TemplateModel) {
                    try {
                        map.put(entry.getKey(), objectWrapper.unwrap((TemplateModel) value));
                    } catch (TemplateModelException e) {
                        if (LOG.isErrorEnabled()) {
                            LOG.error("failed to unwrap [#0] it will be ignored", e, value.toString());
                        }
                    }
View Full Code Here

  /**
   * Tests the client package for method.
   */
  public void testClientPackageFor() throws Exception {
    BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
    HashMap<String, String> conversions = new HashMap<String, String>();
    conversions.put("org.codehaus.enunciate.samples", "red.herring");
    conversions.put("org.codehaus.enunciate.samples.xfire_client.with.a.nested", "org.codehaus.enunciate.other.pckg.and.nested");
    ClientPackageForMethod packageForMethod = new ClientPackageForMethod(conversions);
    TypeDeclaration typeDeclaration = getDeclaration("org.codehaus.enunciate.samples.xfire_client.with.a.nested.pckg.NestedPackageClass");
    assertEquals("org.codehaus.enunciate.other.pckg.and.nested.pckg", packageForMethod.exec(Arrays.asList(wrapper.wrap(typeDeclaration))));
    assertEquals("org.codehaus.enunciate.other.pckg.and.nested.pckg", packageForMethod.exec(Arrays.asList(wrapper.wrap(typeDeclaration.getPackage()))));
    assertEquals("org.codehaus.enunciate.other.pckg.and.nested.pckg.plus.extra", packageForMethod.exec(Arrays.asList(wrapper.wrap("org.codehaus.enunciate.samples.xfire_client.with.a.nested.pckg.plus.extra"))));
    assertEquals("red.herring.xfire_client", packageForMethod.exec(Arrays.asList(wrapper.wrap("org.codehaus.enunciate.samples.xfire_client"))));
    for (FieldDeclaration fieldDeclaration : typeDeclaration.getFields()) {
      if ("items".equals(fieldDeclaration.getSimpleName())) {
        assertEquals("java.util", packageForMethod.exec(Arrays.asList(wrapper.wrap(fieldDeclaration.getType()))));
      }
      else if ("type".equals(fieldDeclaration.getSimpleName())) {
        assertEquals("org.codehaus.enunciate.other.pckg.and.nested.pckg", packageForMethod.exec(Arrays.asList(wrapper.wrap(fieldDeclaration.getType()))));
      }
    }
  }
View Full Code Here

  /**
   * Tests the string representation of the qname model.
   */
  public void testGetAsString() throws Exception {
    QNameModel model = new QNameModel(new QName("urn:testGetAsString", "element"), new BeansWrapper()) {

      @Override
      protected String lookupPrefix(String namespace) {
        if ("urn:testGetAsString".equals(namespace)) {
          return "tgas";
View Full Code Here

TOP

Related Classes of freemarker.ext.beans.BeansWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.