Package de.mhus.lib

Examples of de.mhus.lib.MException


      log.t("save config",this);
      FileOutputStream os = new FileOutputStream(file);
      properties.store(os, "");
      os.close();
    } catch (Exception e) {
      throw new MException(e);
    }
  }
View Full Code Here


    return name;
  }

  @Override
  public IConfig createConfig(String key) throws MException {
    throw new MException("not supported");
  }
View Full Code Here

    throw new MException("not supported");
  }

  @Override
  public int moveConfig(IConfig config, int newPos) throws MException {
    throw new MException("not supported");
  }
View Full Code Here

    throw new MException("not supported");
  }

  @Override
  public void removeConfig(IConfig config) throws MException {
    throw new MException("not supported");
  }
View Full Code Here

 
  @Override
  public void setPropertyData(String name, Object value) throws MException {
    if (model != null) {
      PojoAttribute attr = model.getAttribute(name);
      if (attr == null) throw new MException("attribute not found",name);
      try {
        attr.set(pojo,value);
      } catch (IOException e) {
        throw new MException(name,e);
      }
    }
  }
View Full Code Here

      f.prepareSave(con,object);
    }

    int c = sqlUpdate.getStatement(con).executeUpdate(attributes);
    if ( c != 1)
      throw new MException("update failed, updated objects " + c);
   
    for (FieldRelation f : relationList) {
      f.saved(con,object);
    }
View Full Code Here

  }

  @Override
  public int moveConfig(IConfig config, int newPos) throws MException {
    if (!(config instanceof XmlConfig))
      throw new MException("not a xmlconfig");
   
    if ( ((XmlConfig)config).element.getParentNode() != element)
      throw new MException("not child of this config");

    NodeList list = MXml.getLocalElements(element);
    if (list.getLength() == 1) {
      if (newPos == MOVE_FIRST || newPos == MOVE_LAST || newPos == 0)
        return 0;
      throw new MException("out of range");     
    }

    if (newPos == MOVE_FIRST) {
      element.removeChild(((XmlConfig)config).element);
      list = MXml.getLocalElements(element);
      element.insertBefore(((XmlConfig)config).element, list.item(0)); //XXX
      return 0;
    }
    if(newPos == MOVE_LAST) {
      element.removeChild(((XmlConfig)config).element);
      element.appendChild(((XmlConfig)config).element);
      return list.getLength()-1;
    }
    if (newPos == MOVE_DOWN) {
      for (int i = 0; i < list.getLength(); i++) {
        Node item = list.item(i);
        if (item == ((XmlConfig)config).element) {   // find element in children list
          if (i == list.getLength()-1)      // already last one
            throw new MException("out of range");
          Node next = list.item(i+1);
          element.removeChild(((XmlConfig)config).element);
          element.insertBefore(((XmlConfig)config).element, next); //XXX
          return i+1;
        }
      }
    }
    if (newPos == MOVE_UP) {
      for (int i = 0; i < list.getLength(); i++) {
        Node item = list.item(i);
        if (item == ((XmlConfig)config).element) {   // find element in children list
          if (i == 0)                // already first one
            throw new MException("out of range");
          Node before = list.item(i-1);
          element.removeChild(((XmlConfig)config).element);
          element.insertBefore(((XmlConfig)config).element, before); //XXX
          return i-1;
        }
      }
    }
   
    if (newPos < 0 || newPos >= list.getLength())
      throw new MException("out of range");     

    Node before = list.item(newPos);
    if (before == ((XmlConfig)config).element) // already on this pos
      return newPos;
   
View Full Code Here

  }

  @Override
  public void removeConfig(IConfig config) throws MException {
    if (!(config instanceof XmlConfig))
      throw new MException("not a xmlconfig");
   
    if ( ((XmlConfig)config).element.getParentNode() != element)
      throw new MException("not child of this config");

    element.removeChild(((XmlConfig)config).element);
  }
View Full Code Here

      node.put(key, array);
     
    }
   
    if (! (array instanceof ArrayNode) ) {
      throw new MException(key + " is not an array");
    }
   
    // create new object node in array
    ObjectNode out = array.objectNode();
    array.add(out);
View Full Code Here

  }

  @Override
  public int moveConfig(IConfig config, int newPos) throws MException {
    if (!(config instanceof JsonConfig))
      throw new MException("not JsonConfig");
   
    // find array node, to append new config
    JsonNode array = node.get(config.getName());
    if (array == null)
      throw new MException("config set not found");
   
    int pos = findPosOf((ArrayNode)array,(JsonConfig)config);
    if (pos < 0)
      throw new MException("could not find child");

    // make it simple if only one element is in list
    if (((ArrayNode)array).size() == 1) {
      if (newPos == MOVE_FIRST || newPos == MOVE_LAST || newPos == 0)
        return 0;
      throw new MException("out of range");
    }

    if (newPos == MOVE_FIRST) {
      ((ArrayNode)array).remove(pos);
      ((ArrayNode)array).insert(0, ((JsonConfig)config).node);
      return 0;
    }
    if(newPos == MOVE_LAST) {
      ((ArrayNode)array).remove(pos);
      ((ArrayNode)array).add(((JsonConfig)config).node);
      return ((ArrayNode)array).size()-1;
    }
   
    if (newPos == MOVE_DOWN) {
      if (pos == ((ArrayNode)array).size()-1)
        throw new MException("out of range");
       
      ((ArrayNode)array).remove(pos);
      ((ArrayNode)array).insert(pos+1, ((JsonConfig)config).node);
      return pos+1;
    }
   
    if (newPos == MOVE_UP) {
      if (pos == 0)
        throw new MException("out of range");

      ((ArrayNode)array).remove(pos);
      ((ArrayNode)array).insert(pos-1, ((JsonConfig)config).node);
      return pos-1;
    }
View Full Code Here

TOP

Related Classes of de.mhus.lib.MException

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.