private String getPackage(UmlClass klass) {
   UmlPackage pkg = null;
   if (_omPkg != null) {
     pkg = UML13Utils.getPackage(UML13Utils.getModel(klass), _omPkg);
   } else {
     pkg = UML13Utils.getModel(klass);
   }
   return UML13Utils.getNamespaceName(pkg, klass);
 }
Ejemplo n.º 2
0
  /**
   * @param classifiers
   * @return
   */
  private Document generateConfig(Collection classifiers) {
    Element configEl = new Element("hibernate-configuration");

    Element sessEl = new Element("session-factory");
    configEl.addContent(sessEl);

    for (Iterator i = classifiers.iterator(); i.hasNext(); ) {
      Classifier klass = (Classifier) i.next();
      UmlPackage pkg = null;
      if (_pkgName != null) {
        pkg = UML13Utils.getPackage(UML13Utils.getModel(klass), _pkgName);
      } else {
        pkg = UML13Utils.getModel(klass);
      }

      String fileSuffix = _fileSuffix;
      if (fileSuffix == null) {
        fileSuffix = ".hbm.xml";
      }
      UmlClass superClass = UML13Utils.getSuperClass((UmlClass) klass);
      if (superClass == null) {
        String nn = UML13Utils.getNamespaceName(pkg, klass);
        String resourceName =
            nn.replace('.', '/') + Constant.FORWARD_SLASH + klass.getName() + fileSuffix;
        //               String implResourceName = resourceName + "/impl";
        Element mappingEl = new Element("mapping");
        sessEl.addContent(mappingEl);
        mappingEl.setAttribute("resource", resourceName);

        String resourceName1 =
            nn.replace('.', '/') + "/impl/" + klass.getName() + "Impl" + fileSuffix;
        Element mappingE2 = new Element("mapping");
        sessEl.addContent(mappingE2);
        mappingE2.setAttribute("resource", resourceName1);
      }
    }

    DocType docType =
        new DocType(
            "hibernate-configuration",
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN",
            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd");
    Document doc = new Document();
    doc.setDocType(docType);
    doc.setRootElement(configEl);
    return doc;
  }
  /**
   * @param classifiers
   * @return
   */
  private String generateConfig(Collection classifiers) {

    String methodList = "";
    String method = "";

    for (Iterator i = classifiers.iterator(); i.hasNext(); ) {
      Classifier klass = (Classifier) i.next();

      // System.out.println("classifier class name: " + klass.getName());

      for (Iterator j = UML13Utils.getAssociationEnds(klass).iterator(); j.hasNext(); ) {
        AssociationEnd thisEnd = (AssociationEnd) j.next();
        AssociationEnd otherEnd = UML13Utils.getOtherAssociationEnd(thisEnd);
        UmlPackage pkg = null;
        if (_pkgName != null) {
          pkg = UML13Utils.getPackage(UML13Utils.getModel(klass), _pkgName);
        } else {
          pkg = UML13Utils.getModel(klass);
        }
        String nn = UML13Utils.getNamespaceName(pkg, klass);

        if (_pkgName != null) {
          pkg = UML13Utils.getPackage(UML13Utils.getModel((UmlClass) otherEnd.getType()), _pkgName);
        } else {
          pkg = UML13Utils.getModel((UmlClass) otherEnd.getType());
        }

        String temp1 = UML13Utils.getNamespaceName(pkg, (UmlClass) otherEnd.getType());
        method = "";
        // the other end is collection, form a string
        if ((UML13Utils.isOne2Many(thisEnd, otherEnd) || UML13Utils.isMany2Many(thisEnd, otherEnd))
            && otherEnd.isNavigable()) {
          method = method + otherEnd.getName();
          method = method + nn;
          method = method + ".";
          //					method = method + ".impl.";
          method = method + thisEnd.getType().getName();
          //					method = method + "Impl";
          method = method + "=";
          method = method + temp1;
          //					method = method + ".impl.";
          method = method + ".";
          method = method + otherEnd.getType().getName();
          //					method = method + "Impl";
          method = method + "\n";

          // 3.0.1 release
          method = method + otherEnd.getName();
          method = method + nn;
          method = method + ".impl.";
          method = method + thisEnd.getType().getName();
          method = method + "Impl";
          method = method + "=";
          method = method + temp1;
          method = method + ".impl.";
          method = method + otherEnd.getType().getName();
          method = method + "Impl";
          method = method + "\n\n";
        }

        if (method != null && methodList != null) {
          methodList = methodList + method;
        } else if (method != null && methodList == null) {
          methodList = method;
        }
      }
    }

    String setUp = "";
    setUp = setUp + methodList;
    return setUp;
  }
Ejemplo n.º 4
0
  /**
   * @see
   *     gov.nih.nci.codegen.framework.ArtifactHandler#execute(gov.nih.nci.codegen.framework.Artifact)
   */
  public void execute(Artifact artifact) {
    RefObject ro = artifact.getSource();
    if (!(ro instanceof ModelElement)) {
      log.error("Artifact source is not instance of " + "org.omg.uml.foundation.core.ModelElement");
      throw new RuntimeException(
          "Artifact source is not instance of " + "org.omg.uml.foundation.core.ModelElement");
    }
    ModelElement me = (ModelElement) ro;
    try {
      UmlPackage pkg = null;
      if (_basePackage != null) {
        pkg = UML13Utils.getPackage(UML13Utils.getModel(me), _basePackage);

      } else {
        pkg = UML13Utils.getModel(me);
      }
      String nn = UML13Utils.getNamespaceName(pkg, me);
      String no = "";
      // based on whether the interfaceFlag in the control file is set to yes or no
      // the outputted file will or will not have a directory named impl in its path
      if (_interfaceFlag.equals("yes")) {
        no = nn;
      } else if (_wsFlag.equals("yes")) {

        no = nn + ".ws.";
      } else if (_pojoFlag != null && _pojoFlag.equals("yes")) {
        log.error("_pojoFlag.equals(yes)");
        no = nn + ".bean.";
      } else {
        if (nn.indexOf("evs") == -1) {
          no = nn + ".impl";
        } else {
          no = nn + "";
        }
      }

      StringBuffer nameBuf = new StringBuffer();
      if (_pkgPrefix != null && _pkgPrefix.trim().length() > 0) {
        nameBuf.append(_pkgPrefix.trim());
      }
      nameBuf.append(no);
      if (_pkgSuffix != null && _pkgSuffix.trim().length() > 0) {
        nameBuf.append(_pkgSuffix.trim());
      }
      nameBuf.append('.');
      if (_classPrefix != null && _classPrefix.trim().length() > 0) {
        nameBuf.append(_classPrefix.trim());
      }
      nameBuf.append(me.getName());
      if (_classSuffix != null && _classSuffix.trim().length() > 0) {
        nameBuf.append(_classSuffix.trim());
      }
      if (_classSuffix != null && _classSuffix.equals("Impl")) {
        String temp = nameBuf.toString();
        nameBuf = new StringBuffer(temp);
      }
      String fileSuffix = _fileSuffix;
      if (fileSuffix == null) {
        fileSuffix = "hbm.xml";
      }
      File f =
          new File(
              _baseDir + '/' + nameBuf.toString().replace('.', '/') + '.' + _fileSuffix.trim());

      File p = f.getParentFile();
      if (!p.exists()) {
        p.mkdirs();
      }
      f.createNewFile();
      FileWriter w = new FileWriter(f);
      w.write(artifact.getTarget().toString());
      w.flush();
      w.close();
    } catch (Exception ex) {
      log.error("error handling artifact" + ex.getMessage());
      throw new RuntimeException("error handling artifact", ex);
    }
  }