Esempio n. 1
0
  /** @see railo.runtime.type.Array#prepend(java.lang.Object) */
  public Object prepend(Object value) throws PageException {
    Element element = XMLCaster.toElement(struct.getOwnerDocument(), value);
    Object obj = struct.getInnerArray().get(1, null);

    if (obj instanceof Element) {
      Element el = ((Element) obj);
      el.getParentNode().insertBefore(XMLCaster.toRawNode(element), el);
    } else {
      struct.getParentNode().appendChild(XMLCaster.toRawNode(element));
    }
    return struct.getInnerArray().prepend(element);
  }
Esempio n. 2
0
 /**
  * tests if object is a XML Object
  *
  * @param o Object to check
  * @return boolean
  */
 public static boolean isXML(Object o) {
   if (o instanceof Node || o instanceof NodeList) return true;
   if (o instanceof ObjectWrap) {
     return isXML(((ObjectWrap) o).getEmbededObject(null));
   }
   try {
     XMLCaster.toXMLStruct(XMLUtil.parse(XMLUtil.toInputSource(null, o), null, false), false);
     return true;
   } catch (Exception outer) {
     return false;
   }
 }
Esempio n. 3
0
  public void createMapping(
      PageContext pc, Component cfc, DatasourceConnection dc, ORMConfiguration ormConf)
      throws PageException {
    ComponentPro cfcp = ComponentUtil.toComponentPro(cfc);
    String id = id(HibernateCaster.getEntityName(cfcp));
    CFCInfo info = cfcs.get(id);
    // Long modified=cfcs.get(id);
    String xml;
    long cfcCompTime = ComponentUtil.getCompileTime(pc, cfcp.getPageSource());
    if (info == null
        || (ORMUtil.equals(info.getCFC(), cfcp))) { // && info.getModified()!=cfcCompTime
      StringBuilder sb = new StringBuilder();

      long xmlLastMod = loadMapping(sb, ormConf, cfcp);
      Element root;
      // create maaping
      if (true || xmlLastMod < cfcCompTime) { // MUSTMUST
        configuration = null;
        Document doc = null;
        try {
          doc = XMLUtil.newDocument();
        } catch (Throwable t) {
          t.printStackTrace();
        }

        root = doc.createElement("hibernate-mapping");
        doc.appendChild(root);
        pc.addPageSource(cfcp.getPageSource(), true);
        try {
          HBMCreator.createXMLMapping(pc, dc, cfcp, ormConf, root, this);
        } finally {
          pc.removeLastPageSource(true);
        }
        xml = XMLCaster.toString(root.getChildNodes(), true);
        saveMapping(ormConf, cfcp, root);
      }
      // load
      else {
        xml = sb.toString();
        root = Caster.toXML(xml).getOwnerDocument().getDocumentElement();
        /*print.o("1+++++++++++++++++++++++++++++++++++++++++");
        print.o(xml);
        print.o("2+++++++++++++++++++++++++++++++++++++++++");
        print.o(root);
        print.o("3+++++++++++++++++++++++++++++++++++++++++");*/

      }
      cfcs.put(id, new CFCInfo(ComponentUtil.getCompileTime(pc, cfcp.getPageSource()), xml, cfcp));
    }
  }
Esempio n. 4
0
 private static void saveMapping(ORMConfiguration ormConf, Component cfc, Element hm)
     throws ExpressionException {
   if (ormConf.saveMapping()) {
     Resource res = ComponentUtil.toComponentPro(cfc).getPageSource().getPhyscalFile();
     if (res != null) {
       res = res.getParentResource().getRealResource(res.getName() + ".hbm.xml");
       try {
         IOUtil.write(
             res,
             XMLCaster.toString(
                 hm,
                 false,
                 HibernateSessionFactory.HIBERNATE_3_PUBLIC_ID,
                 HibernateSessionFactory.HIBERNATE_3_SYSTEM_ID,
                 HibernateSessionFactory.HIBERNATE_3_ENCODING),
             HibernateSessionFactory.HIBERNATE_3_ENCODING,
             false);
       } catch (Exception e) {
       }
     }
   }
 }