Package speculoos.utils

Examples of speculoos.utils.TypeHelper


   * method.
   *
   * @see speculoos.core.Mapper#map(java.lang.Object, java.util.Map)
   */
  public Object map(Object input, Map param) throws MapperException {
    TypeHelper th = TypeHelper.instance;
    StringBuffer sb = new StringBuffer();
    sb.append("(&");
    BeanInfo info;
    try {
      info = Introspector.getBeanInfo(input.getClass());
    } catch (IntrospectionException e) {
      throw new MapperException(getName()
          + ": cannot access fields info from Introspector", e);
    }
    PropertyDescriptor[] props = info.getPropertyDescriptors();
    for (int i = 0; i < props.length; i++) {
      PropertyDescriptor p = props[i];
      String n = (String) outputMap.get(p.getName());
      if (n == null)
        continue;
      Object o = th.get(input, p.getName());
      /* special handling for collections */
      if (o != null)
        if (o instanceof Collection) {
          for (Iterator it = ((Collection) o).iterator(); it
              .hasNext();)
View Full Code Here


          "Got exception while configuring pool", e);
    }
    if (log.isDebugEnabled())
      log.debug("[" + getName()
          + "] done starting pooled source with parameters : "
          + new TypeHelper().toMap(this));
    if (log.isInfoEnabled())
      log.info("[" + getName() + "] done starting pooled source");
  }
View Full Code Here

   * (non-Javadoc)
   *
   * @see speculoos.jndi.pool.JNDIConnectionPool#collectStatistics()
   */
  public Map collectStatistics() {
    return new TypeHelper().toMap(stats);
  }
View Full Code Here

    this.cn = new CompoundName(root.instance(env), Constants.SYNTAX);
    npmock.expects(once()).method("parse").with(
        eq("cn=toto,ou=Personnes,o=canam")).will(returnValue(cn));
    smi.setRoot(root);
    /* output map */
    smi.setTypeHelper(new TypeHelper());
    /* add mapper to src */
    this.output = new HashMap();
    output.put("telephoneNumber", "telephone");
    output.put("uid", "login");
    output.put("sites", "sites");
View Full Code Here

   * that may later be used for input to other mappers.
   *
   * @see speculoos.core.Mapper#map(java.lang.Object, java.util.Map)
   */
  public Object map(Object input, Map param) throws MapperException {
    TypeHelper th = TypeHelper.instance;
    BeanInfo info;
    try {
      info = Introspector.getBeanInfo(input.getClass());
    } catch (IntrospectionException e) {
      throw new MapperException(getName()
          + ": cannot access fields info from Introspector", e);
    }
    Attributes attributes = new BasicAttributes(isCaseIgnore());
    PropertyDescriptor[] props = info.getPropertyDescriptors();
    for (int i = 0; i < props.length; i++) {
      PropertyDescriptor p = props[i];
      String n = (String) outputMap.get(p.getName());
      if (n == null)
        continue;
      Attribute attribute = new BasicAttribute(n);
      Object o = th.get(input, p.getName());
      /* special handling for collections */
      if (o != null) {
        if (o instanceof Collection) {
          for (Iterator it = ((Collection) o).iterator(); it
              .hasNext();)
View Full Code Here

   * @throws MapperException
   */
  private Object makeObject(Object input, Map param)
      throws InstantiationException, IllegalAccessException,
      NamingException, MapperException {
    TypeHelper th = TypeHelper.instance;
    Object ret = klass.newInstance();
    SearchResult res = (SearchResult) input;
    Attributes attrs = res.getAttributes();
    for (NamingEnumeration e = attrs.getAll(); e.hasMore();) {
      Attribute attr = (Attribute) e.next();
      String id = attr.getID();
      String n = (String) outputMap.get(id);
      if (n == null)
        continue;
      /* type of field */
      Class fcls = th.getClass(ret, n);
      if (fcls == null) {
        continue;
      }
      /* handling of multiple values */
      if (attr.size() > 1 || Collection.class.isAssignableFrom(fcls)) {
        try {
          Collection c = (Collection) th.get(ret, n);
          if (c == null) {
            throw new MapperException(getName()
                + ": collection field '" + n
                + "' is not initialized in " + klass);
          }
          /* corresponding field must be a collection */
          for (NamingEnumeration ne = attr.getAll(); ne.hasMore();) {
            c.add(ne.next());
          }
        } catch (ClassCastException ex) {
          throw new MapperException(getName() + ": field " + n
              + " is not a collection in " + klass);
        }
      } else
        th.setString(ret, n, (String) attr.get());
    }
    /* try to set the DN attribute if it exists */
    String dn = (String) outputMap.get("__DN__");
    if (dn != null) {
      String rname = res.getName();
      if (!"".equals(rname)) {
        if(res.isRelative()) {
          rname = rname + "," + param.get("root");
        }
      } else {
        rname = param.get("root").toString();
      }
      th.set(ret, dn, rname);
    }
    return ret;
  }
View Full Code Here

    /* create source */
    leftmock = mock(SearchMapper.class);
    rightmock = mock(SearchMapper.class);
    /* configure source */
    sm = new AttributeJoinMapperImpl("toto");
    sm.setTypeHelper(new TypeHelper());
  }
View Full Code Here

    SearchMapperImpl smi = new SearchMapperImpl("search1");
    VariableString root = new VariableString("cn=${nom}");
    smi.setRoot(root);
    VariableString filter = new VariableString("email=${email}");
    smi.getInputChain().addMapper(new StringVariable("filter", filter));
    smi.setTypeHelper(new TypeHelper());
    src.add("search1", smi);
    /* start source */
    src.start(env);
    /* create mapper */
    SearchMapper sm = (SearchMapper) src.create("search1", new HashMap());
View Full Code Here

    SearchMapperImpl smi = new SearchMapperImpl();
    VariableString root = new VariableString("cn=${nom}");
    smi.setRoot(root);
    VariableString filter = new VariableString("email=${email}");
    smi.getInputChain().addMapper(new StringVariable("filter", filter));
    smi.setTypeHelper(new TypeHelper());
    src.add("search1", smi);
    /* create mapper */
    try {
      SearchMapper sm = (SearchMapper) src.create("search1",
          new HashMap());
View Full Code Here

    SearchMapperImpl smi = new SearchMapperImpl();
    VariableString root = new VariableString("cn=${nom}");
    smi.setRoot(root);
    VariableString filter = new VariableString("email=${email}");
    smi.getInputChain().addMapper(new StringVariable("filter", filter));
    smi.setTypeHelper(new TypeHelper());
    src.add("search1", smi);
    src.start(env);
    /* create mapper */
    try {
      SearchMapper sm = (SearchMapper) src
View Full Code Here

TOP

Related Classes of speculoos.utils.TypeHelper

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.