Package com.codingcrayons.aspectfaces.configuration

Examples of com.codingcrayons.aspectfaces.configuration.Context


    AFWeaver.setDefaultCacheProvider(afCache);

    AFWeaver.addStaticConfiguration(getConfig(CONFIG));
    AFWeaver afWeaver = new AFWeaver(CONFIG, new JavaInspector(Administrator.class));

    Context context = new Context(Administrator.class.getName(), null, null, null, false);

    String fragment = afWeaver.generate(context, keyA);
    assertEquals(afCache.get(keyA), fragment);
    fragment = afWeaver.generate(context, keyA);
    assertEquals(afCache.get(keyA), fragment);
View Full Code Here


    assertEquals(afCache.get(regionB, keyAregB), fragment);
  }

  @Test(expectedExceptions = CacheProviderNotSetException.class)
  public void testCacheIntegrationFail() throws AFException {
    Context context = new Context(Administrator.class.getName(), null, null, null, true);
    AFWeaver.addStaticConfiguration(getConfig(CONFIG));
    AFWeaver.setDefaultCacheProvider(null);
    AFWeaver afWeaver = new AFWeaver(CONFIG);
    afWeaver.generate(context, keyA);
  }
View Full Code Here

  private String layoutInitTemplate(final String template, String startBoundary, String endBoundary, String layoutPath)
    throws AnnotationDescriptorNotFoundException, EvaluatorException, AnnotationNotRegisteredException,
    AnnotationNotFoundException, TemplateFileNotFoundException, TemplateFileAccessException,
    ConfigurationNotSetException, TagParserException {
    JavaInspector inspector = new JavaInspector(Administrator.class);
    Context context = new Context();

    AFWeaver.registerAllAnnotations();
    AFWeaver.setOpenVariableBoundaryIdentifier(startBoundary);
    AFWeaver.setCloseVariableBoundaryIdentifier(endBoundary);

    // set config (ignores fields)
    Configuration configuration = new Configuration("NAME") {
      @Override
      public String getAbsolutePath() {
        return "";
      }

      @Override
      protected StringBuilder getTemplate(String fileTemplatePath, String prefix)
        throws TemplateFileNotFoundException {
        if (fileTemplatePath.contains("layout")) {
          InputStream is = this.getClass().getResourceAsStream(fileTemplatePath);
          String tagContent = "";
          try {
            tagContent = Files.readInputStream(is);
          } catch (Exception e) {
            e.printStackTrace();
          }
          // add to cache
          return new StringBuilder(tagContent);
        } else {
          return new StringBuilder(template);
        }
      }

      @Override
      protected String getDelimiter() {
        return File.separator;
      }
    };
    configuration.addMapping(new Mapping("String", "path"));
    configuration.addMapping(new Mapping("Long", "path"));
    configuration.addMapping(new Mapping("Owner", "path"));
    configuration.addMapping(new Mapping("Integer", "path"));
    Settings settings = new Settings();
    configuration.setSettings(settings);
    context.setConfiguration(configuration);
    context.setOrderAnnotation("com.codingcrayons.aspectfaces.annotations.UiFormOrder");

    List<MetaProperty> metaProperties = inspector.inspect(context);
    UIFragmentComposer composer = new UIFragmentComposer();
    composer.addAllFields(metaProperties);
    context.setLayout(layoutPath);
    String out = composer.composeForm(context).getCompleteForm().toString();

    return out;
  }
View Full Code Here

  @Test
  public void testOrder() throws AnnotationDescriptorNotFoundException, EvaluatorException,
    AnnotationNotRegisteredException, AnnotationNotFoundException, TemplateFileNotFoundException,
    TemplateFileAccessException, ConfigurationNotSetException, TagParserException {

    Context context = new Context();
    JavaInspector inspector = initBasicAF(context, Address.class);

    String out = null;

    context.setOrderAnnotation("com.codingcrayons.aspectfaces.annotations.UiFormOrder");
    out = getAFGeneratedOutput(context, inspector);
    assertEquals(out, "id\ncountry\ncity\nstreet\npostcode\nowner\nversion\n");

    context.setOrderAnnotation("com.codingcrayons.aspectfaces.annotations.NONE");
    out = getAFGeneratedOutput(context, inspector);
    assertEquals(out, "city\ncountry\nid\nowner\npostcode\nstreet\nversion\n");
  }
View Full Code Here

    NoSuchFieldException, IllegalArgumentException, IllegalAccessException {

    LoggerMock loggerMock = new LoggerMock(UIFragmentComposer.class);
    ByteArrayOutputStream outputStream = loggerMock.getOutputStream();

    Context context = new Context();

    JavaInspector inspector = initBasicAF(context, AddressWithUICollision.class);

    String out = null;

    context.setOrderAnnotation("com.codingcrayons.aspectfaces.annotations.UiFormOrder");
    out = getAFGeneratedOutput(context, inspector);
    assertEquals(out, "id\nowner\ncountry\ncity\nstreet\npostcode\nversion\n");
    assertTrue(outputStream.toString().contains("Colliding field order with value"));
    outputStream.reset();

    context.setOrderAnnotation("com.codingcrayons.aspectfaces.annotations.UiOrder");
    out = getAFGeneratedOutput(context, inspector);
    assertEquals(out, "id\nowner\ncity\ncountry\npostcode\nstreet\nversion\n");
    assertTrue(outputStream.toString().contains("Colliding field order with value"));

    // reset logger back
View Full Code Here

      + "com.codingcrayons.aspectfaces.variableresolver.tagvariableresolvertest$person \n"
      + "com.codingcrayons.aspectfaces.variableResolver.TagVariableResolverTest$Person \n" + "iPerson.name ";

    JavaInspector inspector = new JavaInspector(Person.class);
    // context
    Context context = new Context();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("myVar", "YES!");
    context.setVariables(variables);

    AFWeaver.registerAllAnnotations();
    AFWeaver.setOpenVariableBoundaryIdentifier("$");
    AFWeaver.setCloseVariableBoundaryIdentifier("$");

    // set config (ignores fields)
    String CONFIG = "detail.config.xml";
    File file = new File(getResource("configuration/" + CONFIG));
    Configuration configuration = new StaticConfiguration(file.getName());
    configuration.addMapping(new Mapping("String", "path"));
    context.setConfiguration(configuration);

    List<MetaProperty> metaProperties = inspector.inspect(context);
    UIFragmentComposer composer = new UIFragmentComposer();
    composer.addAllFields(metaProperties);
    for (MetaProperty property : metaProperties) {
      @SuppressWarnings("unchecked")
      List<Variable> localVars = Collections.concatLists(context.getVariableList(),
        property.getTemplateVariables());
      TagVariableResolver vr = new TagVariableResolver();
      try {
        StringBuilder result = vr.resolve("FRAGMENT_NAME", template,
          AFWeaver.getOpenVariableBoundaryIdentifier(), AFWeaver.getCloseVariableBoundaryIdentifier(),
View Full Code Here

    ConfigurationStorage.getInstance().addConfiguration(
      new StaticConfiguration(CONFIG), new File(getConfig(CONFIG)), false, false
    );

    Context context = new Context("Test", null, null, null, false);
    context.setConfiguration(ConfigurationStorage.getInstance().getConfiguration(CONFIG));
    JavaInspector javaInspector = new JavaInspector(this.getClass());
    List<MetaProperty> metaProperties = javaInspector.inspect(context);

    for (MetaProperty metaProperty : metaProperties) {
      if (metaProperty.getName().equals(P_STRING)) {
View Full Code Here

      return EMPTY_HEAD + " nothing to inspect " + EMPTY_TAIL;
    }

    try {
      alias = getFragmentName(clazz);
      Context context = new Context(alias, profiles.toArray(new String[profiles.size()]), roles, layout, true);

      if (ignore != null) {
        // Ignored fields
        String expressedIgnoreString = (String) executeExpressionInElContext(ctx.getExpressionFactory(), ctx, ignore.getValue());
        if (expressedIgnoreString != null && !expressedIgnoreString.trim().isEmpty()) {
          context.getContextIgnoreSet().addAll(Arrays.asList(expressedIgnoreString.split(SEPARATOR)));
        }
      }
      // Possible extension
      hookAddToAFContext(context);
View Full Code Here

TOP

Related Classes of com.codingcrayons.aspectfaces.configuration.Context

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.