Examples of ConverterHelper


Examples of org.apache.shale.util.ConverterHelper

                 "org.apache.shale.clay.convert.StringArrayConverter");
    }

    // test how Clay would use it to convert a string property into a target String[]
    public void testDefaults() {
        ConverterHelper helper = new ConverterHelper();
        String[] partialTriggers = {"one", "two", "three"};
        String asString = helper.asString(facesContext, String[].class, partialTriggers);
       
        assertNotNull(asString);
        assertEquals("one two three", asString);
       
        String[] asObject = (String[]) helper.asObject(facesContext, String[].class, asString);
        assertNotNull(asObject);
       
        assertEquals(partialTriggers .length, asObject.length);
        for (int i = 0; i < partialTriggers .length; i++) {
            assertEquals("item " + i + ":", partialTriggers[i], asObject[i]);
View Full Code Here

Examples of org.apache.shale.util.ConverterHelper

     * @param cl The type of object to convert to
     * @return target object type
     */
   private static Object convert(FacesContext context, Object obj, Class cl) {

      ConverterHelper converterHelper = new ConverterHelper();
      // correct target type
      if (cl.isInstance(obj)) {
          return obj;
      }
      // target type is String
      if (cl == String.class) {
          if (obj instanceof String) {
             return obj;
          } else {
             return converterHelper.asString(context, obj.getClass(), obj);
          }
      }
     
      if (obj instanceof String) {  
          // String to object
          return converterHelper.asObject(context, cl, (String) obj)
      } else {
          //Object to String
          String source = converterHelper.asString(context, obj.getClass(), obj);
          // String to Object
          return converterHelper.asObject(context, cl, source);
      }

   }
View Full Code Here

Examples of org.restlet.engine.converter.ConverterHelper

    public <T> T toObject(Representation source, Class<T> target,
            UniformResource resource) throws IOException {
        T result = null;

        if ((source != null) && source.isAvailable() && (source.getSize() != 0)) {
            ConverterHelper ch = ConverterUtils.getBestHelper(source, target,
                    resource);

            if (ch != null) {
                Context.getCurrentLogger().fine(
                        "The following converter was selected for the "
                                + source + " representation: " + ch);

                result = ch.toObject(source, target, resource);

                if (result instanceof Representation) {
                    Representation resultRepresentation = (Representation) result;

                    // Copy the variant metadata
View Full Code Here

Examples of org.restlet.engine.converter.ConverterHelper

     * @return The converted representation.
     */
    public Representation toRepresentation(Object source, Variant target,
            UniformResource resource) {
        Representation result = null;
        ConverterHelper ch = ConverterUtils.getBestHelper(source, target,
                resource);

        if (ch != null) {
            try {
                boolean loggable = (resource == null) ? true : resource
                        .isLoggable();

                if (loggable
                        && Context.getCurrentLogger().isLoggable(Level.FINE)) {
                    Context.getCurrentLogger().fine(
                            "Converter selected for "
                                    + source.getClass().getSimpleName() + ": "
                                    + ch.getClass().getSimpleName());
                }

                if (target == null) {
                    List<VariantInfo> variants = ch.getVariants(source
                            .getClass());

                    if ((variants != null) && !variants.isEmpty()) {
                        if (resource != null) {
                            target = resource.getClientInfo()
                                    .getPreferredVariant(variants,
                                            resource.getMetadataService());
                        } else {
                            target = variants.get(0);
                        }
                    } else {
                        target = new Variant();
                    }
                }

                result = ch.toRepresentation(source, target, resource);

                if (result != null) {
                    // Copy the variant metadata if necessary
                    if (result.getCharacterSet() == null) {
                        result.setCharacterSet(target.getCharacterSet());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.