Examples of TypeFactory


Examples of org.apache.xmlrpc.common.TypeFactory

    private void testCustomDateFormat(ClientProvider pProvider) throws Exception {
        final DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        XmlRpcClient client = pProvider.getClient();
        XmlRpcClientConfigImpl config = getConfig(pProvider);
        client.setConfig(config);
        TypeFactory typeFactory = getCustomDateTypeFactory(client, format);
        client.setTypeFactory(typeFactory);
        Calendar cal1 = Calendar.getInstance();
        XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "DateConverter.tomorrow", new Object[]{cal1.getTime()});
        final String got = XmlRpcTestCase.writeRequest(client, request);
        final String expect = "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
View Full Code Here

Examples of org.codehaus.jackson.map.type.TypeFactory

            throw new ZencoderClientException(hcee.getResponseBodyAsString(), hcee);
        }

        List<ZencoderJobDetailResponse> jobs = null;
        try {
            TypeFactory typeFactory = TypeFactory.defaultInstance();
            jobs = mapper.readValue(
                    response.getBody(),
                    typeFactory.constructCollectionType(List.class, ZencoderJobDetailResponse.class));

        } catch (Exception e) {
            throw new ZencoderClientException(
                    "Unable to deserialize ZencoderCreateJobResponse as JSON",
                    e);
View Full Code Here

Examples of org.codehaus.jackson.map.type.TypeFactory

   
    // @since 1.9
    public void testJavaType() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        TypeFactory tf = TypeFactory.defaultInstance();
        // first simple type:
        String json = mapper.writeValueAsString(tf.constructType(String.class));
        assertEquals(quote(java.lang.String.class.getName()), json);
        // and back
        JavaType t = mapper.readValue(json, JavaType.class);
        assertNotNull(t);
        assertEquals(String.class, t.getRawClass());
View Full Code Here

Examples of org.codehaus.jackson.map.type.TypeFactory

                mapper._deserializerProvider = mapper._deserializerProvider.withAbstractTypeResolver(resolver);
            }

            //@Override
            public void addTypeModifier(TypeModifier modifier) {
                TypeFactory f = mapper._typeFactory;
                f = f.withModifier(modifier);
                mapper.setTypeFactory(f);
            }

            //@Override
            public void addValueInstantiators(ValueInstantiators instantiators) {
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.type.TypeFactory

      }
    }
  }
 
  public IConstructor convertMapToGrammar(IMap definition) {
    TypeFactory TF = TypeFactory.getInstance();
    TypeStore TS = new TypeStore();
    Type Grammar = TF.abstractDataType(TS, "Grammar");
    Type Symbol = TF.abstractDataType(TS, "Symbol");
    Type Production = TF.abstractDataType(TS, "Production");
    Type grammar = TF.constructor(TS, Grammar, "grammar", TF.setType(Symbol), "starts", TF.mapType(Symbol, Production), "rules");

    return vf.constructor(grammar, vf.set(), definition);
  }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.type.TypeFactory

  private void initMethodAndStatusValues(final IEvaluatorContext ctx) {
    if (methodValues.isEmpty() || statusValues.isEmpty()) {
      Environment env = ctx.getHeap().getModule("util::Webserver");
      Type methodType = env.getAbstractDataType("Method");
      TypeFactory tf = TypeFactory.getInstance();
      methodValues.put(Method.DELETE, vf.constructor(env.getConstructor(methodType, "delete", tf.voidType())));
      methodValues.put(Method.GET, vf.constructor(env.getConstructor(methodType, "get", tf.voidType())));
      methodValues.put(Method.HEAD, vf.constructor(env.getConstructor(methodType, "head", tf.voidType())));
      methodValues.put(Method.POST, vf.constructor(env.getConstructor(methodType, "post", tf.voidType())));
      methodValues.put(Method.PUT, vf.constructor(env.getConstructor(methodType, "put", tf.voidType())));
     
      Type statusType = env.getAbstractDataType("Status");
                       
      statusValues.put(vf.constructor(env.getConstructor(statusType, "ok", tf.voidType())), Status.OK);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "created", tf.voidType())), Status.CREATED);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "accepted", tf.voidType())), Status.ACCEPTED);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "noContent", tf.voidType())), Status.NO_CONTENT);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "partialContent", tf.voidType())), Status.PARTIAL_CONTENT);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "redirect", tf.voidType())), Status.REDIRECT);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "notModified", tf.voidType())), Status.NOT_MODIFIED);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "badRequest", tf.voidType())), Status.BAD_REQUEST);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "unauthorized", tf.voidType())), Status.UNAUTHORIZED);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "forbidden", tf.voidType())), Status.FORBIDDEN);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "notFound", tf.voidType())), Status.NOT_FOUND);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "rangeNotSatisfiable", tf.voidType())), Status.RANGE_NOT_SATISFIABLE);
      statusValues.put(vf.constructor(env.getConstructor(statusType, "internalError", tf.voidType())), Status.INTERNAL_ERROR);
      // yes, we acknowledge our sins
      argTypes[1] = methodType;
    }
  }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.type.TypeFactory

  private IValue callGenerator(Type type, int depthLimit) {
    if (depthLimit < 0) {
      return null;
    }
    TypeFactory tf = TypeFactory.getInstance();

    ICallableValue generator = generators.get(type);
    Result<IValue> result = generator.call(new Type[] { tf.integerType() },
        new IValue[] { vf.integer(depthLimit) }, null);
    return result.getValue();
  }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.type.TypeFactory

  }
 
  @Override
  public <U extends IValue> Result<U> fieldAccess(String name, TypeStore store) {
    IValueFactory vf = getValueFactory();
    TypeFactory tf = getTypeFactory();

    ISourceLocation value = getValue();
    String stringResult = null;
    Integer intResult = null;
    Integer tupleA = null;
    Integer tupleB = null;
    switch (name) {
    case "scheme":
      stringResult = value.getScheme();
      break;

    case "authority":
      stringResult = value.hasAuthority() ? value.getAuthority() : "";
      break;

    case "host":
    case "user":
    case "port":
      URI uri = value.getURI();
      if (!ctx.getResolverRegistry().supportsHost(uri)) {
        throw new UndeclaredField(name, "The scheme " + uri.getScheme() + " does not support the " + name + " field, use authority instead.", tf.sourceLocationType(), ctx.getCurrentAST());
      }
      if (name.equals("host")) {
        stringResult = uri.getHost();
      }
      else if (name.equals("user")) {
        stringResult = uri.getUserInfo();
      }
      else {
        intResult = uri.getPort();
      }
      if (stringResult == null && intResult == null) {
        stringResult = "";
      }
      break;

    case "path":
      stringResult = value.hasPath() ? value.getPath() : "";
      break;

    case "query":
      stringResult = value.hasQuery() ? value.getQuery() : "";
      break;

    case "fragment":
      stringResult = value.hasFragment() ? value.getFragment() : "";
      break;

    case "length":
      if (value.hasOffsetLength()) {
        intResult = value.getLength();
        break;
      }
      throw RuntimeExceptionFactory.unavailableInformation(ctx.getCurrentAST(), ctx.getStackTrace());

    case "offset":
      if (value.hasOffsetLength()) {
        intResult = value.getOffset();
        break;
      }
      throw RuntimeExceptionFactory.unavailableInformation(ctx.getCurrentAST(), ctx.getStackTrace());

    case "begin":
      if (value.hasLineColumn()) {
        tupleA = value.getBeginLine();
        tupleB = value.getBeginColumn();
        break;
      }
      throw RuntimeExceptionFactory.unavailableInformation(ctx.getCurrentAST(), ctx.getStackTrace());

    case "end":
      if (value.hasLineColumn()) {
        tupleA = value.getEndLine();
        tupleB = value.getEndColumn();
        break;
      }
      throw RuntimeExceptionFactory.unavailableInformation(ctx.getCurrentAST(), ctx.getStackTrace());
   
    case "uri":
      stringResult = value.getURI().toString();
      break;

    case "top":
      return makeResult(tf.sourceLocationType(), vf.sourceLocation(value.getURI()), ctx);

    // now the calculated fields
    case "parent": {
      String path = value.hasPath() ? value.getPath() : "";
      if (path.equals("") || path.equals("/")) {
        throw RuntimeExceptionFactory.noParent(getValue(), ctx.getCurrentAST(), ctx.getStackTrace());
      }
      // remove one or more /'s at the end
      if (path.endsWith("/")) {
        path = path.substring(0, path.length() -1);
      }
      int i = path.lastIndexOf((int)'/');
      if (i != -1) {
        path = path.substring(0, i);
        if (value.getScheme().equalsIgnoreCase("file")) {
          // there is a special case for file references to windows paths.
          // the root path should end with a / (c:/ not c:)
          if (path.lastIndexOf((int)'/') == 0 && path.endsWith(":")) {
            path += "/";
          }
        }
        return fieldUpdate("path", makeResult(tf.stringType(), vf.string(path), ctx), store);
      }
      throw RuntimeExceptionFactory.noParent(getValue(), ctx.getCurrentAST(), ctx.getStackTrace());
    }

    case "file": {
      String path = value.hasPath() ? value.getPath() : "";
     
      if (path.equals("")) {
        throw RuntimeExceptionFactory.noParent(getValue(), ctx.getCurrentAST(), ctx.getStackTrace());
      }
      int i = path.lastIndexOf((int)'/');
     
      if (i != -1) {
        stringResult = path.substring(i+1);
      }
      else {
        stringResult = path;
      }
      break;
    }

    case "ls": {
      try {
        ISourceLocation resolved = ctx.getHeap().resolveSourceLocation(value);
        if (!ctx.getResolverRegistry().isDirectory(resolved.getURI())) {
          throw RuntimeExceptionFactory.io(vf.string("You can only access ls on a directory, or a container."), ctx.getCurrentAST(), ctx.getStackTrace());
        }
        Result<IValue> resRes = makeResult(getType(), resolved, ctx);

        IListWriter w = ctx.getValueFactory().listWriter();
        Type stringType = tf.stringType();

        for (String elem : ctx.getResolverRegistry().listEntries(resolved.getURI())) {
          w.append(resRes.add(makeResult(stringType, vf.string(elem), ctx)).getValue());
        }

        IList result = w.done();
        // a list of loc's
        return makeResult(result.getType(), result, ctx);
       
      } catch (IOException e) {
        throw RuntimeExceptionFactory.io(vf.string(e.getMessage()), ctx.getCurrentAST(), ctx.getStackTrace());
      }
     
    }

    case "extension" : {
      String path = value.hasPath() ? value.getPath() : "";
      int i = path.lastIndexOf((int)'.');
      if (i != -1) {
        stringResult = path.substring(i + 1);
      }
      else {
        stringResult = "";
      }
      break;
    }
   
    case "params" : {
      String query = value.hasQuery() ? value.getQuery() : "";
      IMapWriter res = vf.mapWriter(tf.stringType(), tf.stringType());
     
      if (query != null && query.length() > 0) {
        String[] params = query.split("&");
        for (String param : params) {
          String[] keyValue = param.split("=");
          res.put(vf.string(keyValue[0]), vf.string(keyValue[1]));
        }
      }
     
      IMap map = res.done();
      return makeResult(map.getType(), map, ctx);
    }

    default:
      throw new UndeclaredField(name, getTypeFactory().sourceLocationType(), ctx.getCurrentAST());
    }

    if (stringResult != null) {
      return makeResult(tf.stringType(), vf.string(stringResult), ctx);
    }
    if (intResult != null) {
      return makeResult(tf.integerType(), vf.integer(intResult), ctx);
    }
    if (tupleA != null && tupleB != null) {
      return makeResult(intTuple, vf.tuple(vf.integer(tupleA), vf.integer(tupleB)), ctx);
    }
    throw new RuntimeException("A case not handled? " + name);
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.type.TypeFactory

  /**
   * @return list of built-in color names
   */
  public IList colorNames() {
    TypeFactory types = TypeFactory.getInstance();
    IListWriter w = vf.listWriter(types.stringType());
    String strings[] = new String[colorNames.size()];
    Arrays.sort(colorNames.keySet().toArray(strings));
    for (String s : strings) {
      w.append(vf.string(s));
    }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.type.TypeFactory

  public void initElem(IFigureConstructionEnv env, MouseOver mparent, boolean swtSeen, boolean visible, NameResolver resolver){
    if(innerFig != null){
      innerFig.destroy(env);
    }
    TypeFactory tf = TypeFactory.getInstance();
    IList originalsL = VF.list(originals.toArray(tmpArray));
    IConstructor figureCons = (IConstructor) env.getCallBackEnv().executeRascalCallBackSingleArgument(whole,tf.listType(tf.valueType()),originalsL).getValue();
    innerFig = FigureFactory.make(env, figureCons, prop, childProps);
    innerFig.registerIds(env, resolver);
    innerFig.registerConverts(resolver);
    setInnerFig( innerFig);
    prop.stealExternalPropertiesFrom(innerFig.prop);
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.