Esempio n. 1
0
  static void changeWindowProperty(
      Client c,
      Window w,
      int property,
      int type,
      short format,
      byte mode,
      int len,
      byte[] value,
      boolean sendevent)
      throws IOException {
    synchronized (w) {
      Property p;
      int totalSize = len * (format / 8);
      p = w.getProperty();
      while (p != null) {
        if (p.propertyName == property) break;
        p = p.next;
      }

      if (p != null) {
        if ((format != p.format) && (mode != PropModeReplace)) {
          System.err.println("error!");
          c.errorReason = 8; // BadMatch
          return;
        }
        if ((type != p.type) && (mode != PropModeReplace)) {
          System.err.println("error!");
          c.errorReason = 8; // BadMatch
          return;
        }
        if (mode == PropModeReplace) {
          p.data = value;
          p.size = len;
          p.format = format;
          p.type = type;
        } else if (len == 0) {
        } else if (mode == PropModeAppend) {
          byte[] foo = new byte[(format / 8) * (len + p.size)];
          if (p.size > 0) System.arraycopy(p.data, 0, foo, 0, p.size);
          System.arraycopy(value, 0, foo, p.size, totalSize);
          p.size += len;
          p.data = foo;
        } else if (mode == PropModePrepend) {
          byte[] foo = new byte[(format / 8) * (len + p.size)];
          System.arraycopy(value, 0, foo, 0, totalSize);
          if (p.size > 0) System.arraycopy(p.data, 0, foo, totalSize, p.size);
          p.size += len;
          p.data = foo;
        }
        // change;
      } else {
        //    w.setProperty(null);
        p = new Property();
        p.propertyName = property;
        p.type = type;
        p.format = (short) format;
        p.data = value;
        p.size = len;
        p.next = w.getProperty();
        w.setProperty(p);
      }

      if (p != null) {
        if (p.propertyName == 9
            && // CUT_BUFFER0
            w == w.screen.root
            && p.size > 0) {
          CopyPaste.setString(new String(p.data, 0, p.size));
        }
        if (w.screen.windowmode != WeirdX.InBrowser
            && p.propertyName == 39
            && p.type == 31
            && p.size > 0
            && w.ddxwindow != null) {
          java.awt.Window frame = w.getFrame();
          if (frame != null && (frame instanceof java.awt.Frame)) {
            ((java.awt.Frame) frame).setTitle(new String(p.data));
          }
        }
      }
    }

    if (sendevent) {
      c.cevent.mkPropertyNotify(w.id, property, (int) System.currentTimeMillis(), 0);
      w.sendEvent(c.cevent, 1, null);
    }
  }
 // 循环处理每个需要处理的程序对象
 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   // 定义一个文件输出流,用于生成额外的文件
   PrintStream ps = null;
   try {
     // 遍历每个被@Persistent修饰的class文件
     for (Element t : roundEnv.getElementsAnnotatedWith(Persistent.class)) {
       // 获取正在处理的类名
       Name clazzName = t.getSimpleName();
       // 获取类定义前的@Persistent Annotation
       Persistent per = t.getAnnotation(Persistent.class);
       // 创建文件输出流
       ps = new PrintStream(new FileOutputStream(clazzName + ".hbm.xml"));
       // 执行输出
       ps.println("<?xml version=\"1.0\"?>");
       ps.println("<!DOCTYPE hibernate-mapping PUBLIC");
       ps.println("	\"-//Hibernate/Hibernate " + "Mapping DTD 3.0//EN\"");
       ps.println("	\"http://www.hibernate.org/dtd/" + "hibernate-mapping-3.0.dtd\">");
       ps.println("<hibernate-mapping>");
       ps.print("	<class name=\"" + t);
       // 输出per的table()的值
       ps.println("\" table=\"" + per.table() + "\">");
       for (Element f : t.getEnclosedElements()) {
         // 只处理成员变量上的Annotation
         if (f.getKind() == ElementKind.FIELD) // ①
         {
           // 获取成员变量定义前的@Id Annotation
           Id id = f.getAnnotation(Id.class); // ②
           // 当@Id Annotation存在时输出<id.../>元素
           if (id != null) {
             ps.println(
                 "		<id name=\""
                     + f.getSimpleName()
                     + "\" column=\""
                     + id.column()
                     + "\" type=\""
                     + id.type()
                     + "\">");
             ps.println("		<generator class=\"" + id.generator() + "\"/>");
             ps.println("		</id>");
           }
           // 获取成员变量定义前的@Property Annotation
           Property p = f.getAnnotation(Property.class); // ③
           // 当@Property Annotation存在时输出<property.../>元素
           if (p != null) {
             ps.println(
                 "		<property name=\""
                     + f.getSimpleName()
                     + "\" column=\""
                     + p.column()
                     + "\" type=\""
                     + p.type()
                     + "\"/>");
           }
         }
       }
       ps.println("	</class>");
       ps.println("</hibernate-mapping>");
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   } finally {
     if (ps != null) {
       try {
         ps.close();
       } catch (Exception ex) {
         ex.printStackTrace();
       }
     }
   }
   return true;
 }