Java could use code templates.

Hi,
I have often wondered why Java does not have a facility for code generation. It could be simple, like templates. For example, I am tired of writing getter and setter functions that do nothing but return or set the value of a member field. What I would like to see is something like a preprocessor but more powerful. Here is some sample code:
(Template definitions)
<template name="get">
public <value ref="type"/> get <value ref="name"/> () {
return this.<value ref="name"/>;
</template>
<template name="set">
public void set <value ref="name"/>(<value ref="type"/> in) {
this.<value ref="name"/> = in;
</template>
(Template uses)
<use template="get" name="customer" type="string"/>
<use template="set" name="customer" type="string"/>
(Resulting code)
public String getCustomer() {
return this.customer;
public void setCustomer(String in) {
this.customer = in;
This could have applications for generating code for connecting to JDBC databases as well.
-mephtu

mephtu wrote:
Hi,
I have often wondered why Java does not have a facility for code generation. It could be simple, like templates. For example, I am tired of writing getter and setter functions that do nothing but return or set the value of a member field. Then one or both of the the following is true.
1. You are over using setters/getters
2. You are creating boiler plate code anyways so learn how to generate code and start doing that (that is NOT the same as templates.)
>
This could have applications for generating code for connecting to JDBC databases as well.I have been using code generation since about the time java first came into existance. And that was about the time when templates first gained wide acceptance (using different implementations) in C++.
Templates are not needed for code generation and actually there isn't any point since one certainly doesn't need to worry about typing.

Similar Messages

  • Using code templates in Flash Builder

    Hi, all;
    I know how to change most of the templates so that they go from the default "uncuddled" brackets to "cuddled"
    i.e.
    public function notCuddled():void
         //TODO
    vs.
    public function cuddled():void {
         //yay! no wasted space
    However, I have not found the template used for the constructor for a generated Class, so I get:
    package my.package {
         public class MyLovelyCuddledClass {
              public function MyLovelyCuddledClass()
              {//wasted line that I have to manually fix
    I love the new productivity enhamcements in FB 4.5, and they are so great that little nitpicks like this stand out.  Can anyone tell me where I can find the template that is used for this, so I can code to the fullest potential of the tool?
    TIA;
    Amy

    Hi Amy,
    You can customize 'New class' generation under Preferences->Editors->Flash
    Builder->FileTemplates->Action Script->New ActionScript class.
    Currently there are no template variables available constructors. But you
    can customize it as following,
    $
    ${import_declaration}
    $ {
      public function ${class_name}() {

  • Can't get popup window to work, could use code help.

    This is the first time I've tried to open a popup window in
    flash, and I can't get it to work. The site I'm building has the
    navigation buttons contained in an animated movie clip. All of the
    navigation buttons work fine. But there's a link that the company
    wants me to add that opens a window to another site who hosts a
    video commercial for the company (it has to be a link to the other
    site, it can't be added directly to the customers site).
    The link the other company sent me is for javascript (I'll
    include it in the attached code), and the code works great if I
    just insert the javascript in the html. But I wanted to try and get
    the link in the Flash menu. I've tried several versions of the
    code, from applying it directly to the button to naming an instance
    of it and attaching the actionscript in the movie clip. When I'm
    done, I get two different problems. On my XP machine, I get a
    warning error about the flash trying to open something to another
    server. On my Vista machine, nothing happens at all.
    Anyway, I'm including the original javascript and several
    versions of the actionscript I've tried (with the actual site
    information replaced with "fakeurl.com", wasn't sure how these
    forums felt about including site info). Any help at all would be
    greatly appreciated. I've searched and searched for about a week,
    and I'm tempted to just do away with the Flash button and use a
    cheesy javascript button for this one link.
    Thanks!
    MoAtt

    In article <[email protected]>,
    [email protected] wrote:
    > All I want to do is have a Close Window link in my popup window that works.
    Select your text that you want to act as a trigger to close the window,
    just as if you were going to create a link.
    Then paste the following line of code into the link Inspector:
    javascript:self.close();
    That should do the trick.
    Cheers Martin

  • Code Template Design - SQL LOADER

    Hi,
    We extract data from 12 csv files which have 10+ million rows using SQL Loader into staging table. We use each of these tables in at least two different mappings to populate our Dimensions & Facts.
    Now moving to CT's -
    Using Code Template,
    Code Template LCT_FILE_TO_ORACLE_SQLLDR and DEFAULT_ORACLE_TARGET_CT , i am able to load the data into the staging table. But this involves loading the data into work table and then into our Staging table. So we are loading our data twice.
    So I decided to write my own code template which loads the data from file directly to staging table bypassing work table.
    Developed an Integration CT which write's data directly to my staging table.
    But the issue is , I am miissing the audit. The CT does not shows me any record count it processed. This might be issue since i don't have any work tables.
    Is there a way we can capture audit ?
    Regards,
    Samurai.

    Hi David,
    I was thinking of getting the details from log file (using jytho) but did not know how to update the audit statistics. If you can get me that, it would be great.
    I go through all your blogs :-) . I am following the baby step as per your blog :-) I am moving towards bulk loading.
    Trying to design a CT
    a) SQL Loader
    1) Create a named pipe in unix to hold data into memory
    2) Bulk load data from MYSQL or SYBASE into a named pipe
    3) Then load the data into oracle table using SQLLoader
    4) Drop the named pipe
    OR
    b) External Table
    1) Bulk load data from MYSQL or SYBASE into a file ( zip the data)
    2) Then load the data into oracle external table with preprocessor option
    From our past experience in our current enviornment, quering or transforming data across external table with 10+ million rows was slower than a doing it across a table ( dba's will come after me for issuing such statements). So was trying to use SQL loader first.
    Regards,
    Samurai.
    BTW You know me by other name.
    Edited by: Samurai on Mar 4, 2010 3:12 PM

  • How to install new fonts using code in java?

    Hi,
    How to install font in a system using java, provided i know the font file's address. Is there any specific class/method available for this purpose? Copying the file to windows/font directory will work for windows, but I think it wont be generic to all operating system. So is there anyway to install a font using code?
    I also want to know how to make the font available only until my application window is open, It must be available to all other external applications like photoshop, word etc., When I close my window it must un-install automatically or be made not available to other applications. Any suggestions? Please do help! Thanks in advance...

    I have already tried the above, But the font created using input stream is available only to my application* and is not viewable in photoshop.*. I realize this. Like I said, I know of no method that will register/deregister the font with the system. You'll have to create your own method that takes the operating system into account.
    String os = System.getPropery("os.name");
    if(os.equals("Windows Vista")) {
    }else if(os.equals("Windows XP")) {
    }else if(os.equals("Windows NT")) {
    }else if(os.equals("Solaris")) {
    AIX
    Digital Unix
    FreeBSD
    HP UX
    Irix
    Linux
    Mac OS
    Mac OS X
    MPE/iX
    Netware 4.11
    OS/2
    Solaris
    Windows 2000
    Windows 95
    Windows 98
    Windows NT
    Windows Vista
    Windows XPYou'll need the standard font directory for each system. I think all the window ones are C:\Windows\Font\ . Each OS probably has its own little quark (like having several font directories or throwing different security exceptions). Undoubtly it's going to require some research and a bit of trial and error. You can probably work some magic with Runtime.exec(...) as well.
    The alternative would be to google for some libraries that offer similar functionality, or promt the user for the system's font directory and save the location of the directory in a file somewhere for future use (so the user dosen't have to specify the font directory everytime he/she starts up the application).

  • How Can I execute a java program using java code?

    {color:#000000}Hello,
    i am in great trouble someone please help me. i want to execute java program through java code i have compiled the java class using Compiler API now i want to execute this Class file through java code please help me, thanks in advance
    {color}

    Thanks Manko.
    i think my question was not clear enough.. actually i want to run this class using some java code . like any IDE would do i am making a text editor for java, as my term project i have been able to complie the code usign compiler api and it genertaes the class file but now i want to run this class file "THROUGH JAVA CODE" instead of using Java command. I want to achive it programatically. do you have any idea about it.. thanks in advance

  • Code syntax error in header using a template?

    Now running CS5 DW in a 32 bit Windows/Vista ultimate environment. The improved error messages have brought to light a problem that I apparently have had for a long time but didn't know it as CS4 simply flagged the line but no message.
    Many of my site pages use a template http://a0540807.uscgaux.info/Templates/A0540807_Skeleton_2010.dwt
    If I build or edit a page using this template in CS5, when in code view I see "There is a syntax error on line 57. Code hinting may not work until you fix this error.  Line 57 is within the header of the page and is simply </script>
    But if I simply detach the template from the page, the error goes away and it says no syntax errors.
    So I am confused, is there an issue with the code or is this a Dreamweaver issue dealing with template usage?
    While the error appears cosmetic, I keep wondering what to do to eliminate. Apparently, I have had this situation a long time as Line 57 is also identified back in CS4 but no error message until CS5. Any pointers are appreciated. Thanks.
    Andy

    I don't actually think there is any problem with your page...run one of your child pages through the W3C validator: http://validator.w3.org/ . I cast a page from your template and it came through with flying colors!
    Beth

  • Websites for downloading code-templates (java and jsp) existing ?

    Hi,
    I'm searching for a website, offering code examples or templates (in java and jsp) for downloading.
    For example: A code for creating a new xml-file, login-procedure or sending an e-mail with a java-program, I can customize.
    I know, for asp.net such websites for downloading code-templates are existing (e.g. a German website: http://www.aspheute.com).
    So I think for java and jsp those sites will also be existing�
    Does anyone know some links ?
    bye
    Chris

    Yes, with google - I'll surely find some matches, but I'm looking for links and websites which will be provided by personal experiences.
    With google - you won't find any personal experiences...
    bye
    Chris

  • I made a movie purchase assuming I could use an authorization code received to download. How do I cancell the transaction ?

    I made a movie purchase assuming I could use an authorization code received to download. How do I cancell the transaction ?

    dfviens wrote:
    I made a movie purchase assuming I could use an authorization code received to download. How do I cancell the transaction ?
    Not sure what that means.
    But purchases are final as per the Itunes Terms and Conditions. No refunds are available.
    However that does not mean you can't wait to download it.  Or just pause the download until you are at a location where you wish to download it.

  • Finding java version used from compiled code

    Is there a way to find the java version used to compile the java file from the compiled files,i.e., class files?

    that information is encapsulated within the .class file, I don't think so.
    The class file has a minor_version/major_version field.
    However using jikes and sun jdk 1.3.1 both produce a version number of 45.3. According to a footnote in the JVM spec that corresponds to a class file format for java of 1.0.2. And both obviously are newer than that version of java.
    Based on that I don't think one can expect those numbers to changed based on the java version but rather on any changes in the class file itself.

  • Useful Code of the Day:  Hideable Tree Nodes

    Someone posted about how they could selectively hide tree nodes, and I already had this AbstractTreeModel class (which does some things DefaultTreeModel does and some it doesn't) and a concrete subclass for TreeNode objects, so I was thinking how one could do hideable nodes. So I came up with this solution.
    There's 4 classes here:
    - AbstractTreeModel is the base for the concrete TreeNodeTreeModel
    - TreeNodeTreeModel extends AbstractTreeModel to support TreeNodes (DefautlMutableTreeNode, etc.)
    - HideableMutableTreeNode which is a DefautlMutableTreeNode subclass which has a visible field (with is/set methods, of course).
    - HideableTreeModel is the hideable model which is a subclass of TreeNodeTreeModel.
    A HideableMutableTreeNode can be set invisible directly, but the tree still needs to be notified to update. So it's best to use the methods in HideableTreeModel which set a node's visibility which notify the tree of changes accordingly. Methods are also provided to check a full path's visibility or ensure a node including all parent nodes are visible.
    A HideableTreeModel can take any TreeNode class, it doesn't have to be all HideableMutableTreeNodes, but only HideableMutableTreeNodes can be made invisible, of course. Any other TreeNode type would just be considered visible.
    Hiding nodes works basically by making the tree think there's less nodes then there are. And to do this, the node counts and child index search just works by looping thru the parent's children. This has potential perfomance drawbacks of course, since one has to loop thru the node's children to get nodes every time. This could be alleviated by not supporting non-hideable nodes changing the internal maintenance of HideableMutableTreeNode contents. But I'll leave that to whoever really needs it. It shouldn't be a problem if there are are a relatively small set of child nodes in any given parent.
    Also, note that the root node in the model cannot be made invisible, cuz it'd be redundant since JTree can be set to hide the root node.
    // *** HideableTreeModel ***
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    * <code>HideableTreeModel</code> is an <code>TreeNodeTreeModel</code>
    * implementation for <code>HideableMutableTreeNode</code> objects.  The
    * model can also take any other <code>javax.swing.tree.TreeNode</code>
    * objects. 
    public class HideableTreeModel extends TreeNodeTreeModel {
          * Creates a new <code>HideableTreeModel</code> object.
          * @param  root  the root node
         public HideableTreeModel(TreeNode root) {
              super(root);
          * Checks if the specified node is visible.  A node can only be
          * hidden if the node is an instance of <code>HideableMutableTreeNode</code>.  <br />
          * <br />
          * Note that this only test the visibility of the specified node, not
          * whether a parent node is visible.  Use <code>isPathToNodeVisible(Object)</code>
          * to check if the full path is visible. 
          * @param  node  the node
          * @param  true if the node is visible, else false
         public boolean isNodeVisible(Object node) {
              if(node != getRoot()) {
                   if(node instanceof HideableMutableTreeNode) {
                        return ((HideableMutableTreeNode)node).isVisible();
              return true;
          * Sets the specified node to be hidden.  A node can only be made hidden
          * if the node is an instance of <code>HideableMutableTreeNode</code>.  <br />
          * <br />
          * Note that this method will notify the tree to reflect any changes to
          * node visibility.  <br />
          * <br />
          * Note that this will not alter the visibility of any nodes in the
          * specified node's path to the root node.  Use
          * <code>ensurePathToNodeVisible(Object)</code> instead to make sure the
          * full path down to that node is visible.  <br />
          * <br />
          * Note that this method will notify the tree to reflect any changes to
          * node visibility. 
          * @param  node  the node
          * @param  v     true for visible, false for hidden
          * @param  true if the node's visibility could actually change, else false
         public boolean setNodeVisible(Object node, boolean v) {
              // can't hide root
              if(node != getRoot()) {
                   if(node instanceof HideableMutableTreeNode) {
                        HideableMutableTreeNode n = (HideableMutableTreeNode)node;
                        // don't fix what ain't broke...
                        if(v != n.isVisible()) {
                             TreeNode parent = n.getParent();
                             if(v) {
                                  // need to get index after showing...
                                  n.setVisible(v);
                                  int index = getIndexOfChild(parent, n);
                                  super.nodeInserted(parent, n, index);
                             } else {
                                  // need to get index before hiding...
                                  int index = getIndexOfChild(parent, n);
                                  n.setVisible(v);
                                  super.nodeRemoved(parent, n, index);
                        return true;
              return false;
          * Checks if the specified node is visible and all nodes above it are
          * visible. 
          * @param  node  the node
          * @param  true if the path is visible, else false
         public boolean isPathToNodeVisible(Object node) {
              Object[] path = getPathToRoot(node);
              for(int i = 0; i < path.length; i++) {
                   if(!isNodeVisible(path)) {
                        return false;
              return true;
         * Sets the specified node and all nodes above it to be visible.
         * Note that this method will notify the tree to reflect any changes to
         * node visibility.
         * @param node the node
         public void ensurePathToNodeVisible(Object node) {
              Object[] path = getPathToRoot(node);
              for(int i = 0; i < path.length; i++) {
                   setNodeVisible(path[i], true);
         * Returns the child of parent at index index in the parent's child array.
         * @param parent the parent node
         * @param index the index
         * @return the child or null if no children
         public Object getChild(Object parent, int index) {
              if(parent instanceof TreeNode) {
                   TreeNode p = (TreeNode)parent;
                   for(int i = 0, j = -1; i < p.getChildCount(); i++) {
                        TreeNode pc = (TreeNode)p.getChildAt(i);
                        if(isNodeVisible(pc)) {
                             j++;
                        if(j == index) {
                             return pc;
              return null;
         * Returns the number of children of parent.
         * @param parent the parent node
         * @return the child count
         public int getChildCount(Object parent) {
              int count = 0;
              if(parent instanceof TreeNode) {
                   TreeNode p = (TreeNode)parent;
                   for(int i = 0; i < p.getChildCount(); i++) {
                        TreeNode pc = (TreeNode)p.getChildAt(i);
                        if(isNodeVisible(pc)) {
                             count++;
              return count;
         * Returns the index of child in parent.
         * @param parent the parent node
         * @param child the child node
         * @return the index of the child node in the parent
         public int getIndexOfChild(Object parent, Object child) {
              int index = -1;
              if(parent instanceof TreeNode && child instanceof TreeNode) {
                   TreeNode p = (TreeNode)parent;
                   TreeNode c = (TreeNode)child;
                   if(isNodeVisible(c)) {
                        index = 0;
                        for(int i = 0; i < p.getChildCount(); i++) {
                             TreeNode pc = (TreeNode)p.getChildAt(i);
                             if(pc.equals(c)) {
                                  return index;
                             if(isNodeVisible(pc)) {
                                  index++;
              return index;
         * Main method for testing.
         * @param args the command-line arguments
         public static void main(String[] args) {
              JFrame f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              HideableMutableTreeNode root = new HideableMutableTreeNode("root");
              root.add(new HideableMutableTreeNode("child_1"));
              final HideableMutableTreeNode c2 = new HideableMutableTreeNode("child_2");
              c2.setVisible(false);
              final HideableMutableTreeNode c2a = new HideableMutableTreeNode("child_2_A");
              c2.add(c2a);
              c2.add(new HideableMutableTreeNode("child_2_B"));
              root.add(c2);
              HideableMutableTreeNode c3 = new HideableMutableTreeNode("child_3");
              HideableMutableTreeNode cC = new HideableMutableTreeNode("child_3_C");
              cC.setVisible(false);
              c3.add(cC);
              c3.add(new HideableMutableTreeNode("child_3_D"));
              root.add(c3);
              root.add(new HideableMutableTreeNode("child_4"));
              root.add(new HideableMutableTreeNode("child_5"));
              DefaultMutableTreeNode c6 = new DefaultMutableTreeNode("child_6");
              c6.add(new DefaultMutableTreeNode("child_6_A"));
              c6.add(new DefaultMutableTreeNode("child_6_B"));
              root.add(c6);
              final HideableTreeModel model = new HideableTreeModel(root);
              JTree tree = new JTree(model);
              f.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
              JButton b = new JButton("toggle");
              b.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        model.setNodeVisible(c2, !model.isNodeVisible(c2));
                        //model.ensurePathToNodeVisible(c2a);
              f.getContentPane().add(b, BorderLayout.SOUTH);
              f.pack();
              f.setSize(300, 500);
              f.show();
    // *** HideableMutableTreeNode ***
    import javax.swing.*;
    import javax.swing.tree.*;
    * <code>HideableMutableTreeNode</code> is a <code>DefaultMutableTreeNode</code>
    * implementation that works with <code>HideableTreeModel</code>.
    public class HideableMutableTreeNode extends DefaultMutableTreeNode {
         * The node is visible flag.
         public boolean visible = true;
         * Creates a tree node that has no parent and no children, but which
         * allows children.
         public HideableMutableTreeNode() {
              super();
         * Creates a tree node with no parent, no children, but which allows
         * children, and initializes it with the specified user object.
         * @param userObject - an Object provided by the user that
         * constitutes the node's data
         public HideableMutableTreeNode(Object userObject) {
              super(userObject);
         * Creates a tree node with no parent, no children, initialized with the
         * specified user object, and that allows children only if specified.
         * @param userObject - an Object provided by the user that
         * constitutes the node's data
         * @param allowsChildren - if true, the node is allowed to have child
         * nodes -- otherwise, it is always a leaf node
         public HideableMutableTreeNode(Object userObject, boolean allowsChildren) {
              super(userObject, allowsChildren);
         * Checks if the node is visible.
         * @return true if the node is visible, else false
         public boolean isVisible() {
              return this.visible;
         * Sets if the node is visible.
         * @param v true if the node is visible, else false
         public void setVisible(boolean v) {
              this.visible = v;
    // *** TreeNodeTreeModel ***
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    * <code>TreeNodeTreeModel</code> is an <code>AbstractTreeModel</code>
    * implementation for <code>javax.swing.tree.TreeNode</code> objects.
    public class TreeNodeTreeModel extends AbstractTreeModel {
         * Creates a new <code>TreeNodeTreeModel</code> object.
         * @param root the root node
         public TreeNodeTreeModel(TreeNode root) {
              super();
              setRoot(root);
         * Returns the parent of the child node.
         * @param node the child node
         * @return the parent or null if root
         public Object getParent(Object node) {
              if(node != getRoot() && (node instanceof TreeNode)) {
                   return ((TreeNode)node).getParent();
              return null;
         * Returns the child of parent at index index in the parent's child array.
         * @param parent the parent node
         * @param index the index
         * @return the child or null if no children
         public Object getChild(Object parent, int index) {
              if(parent instanceof TreeNode) {
                   return ((TreeNode)parent).getChildAt(index);
              return null;
         * Returns the number of children of parent.
         * @param parent the parent node
         * @return the child count
         public int getChildCount(Object parent) {
              if(parent instanceof TreeNode) {
                   return ((TreeNode)parent).getChildCount();
              return 0;
         * Returns the index of child in parent.
         * @param parent the parent node
         * @param child the child node
         * @return the index of the child node in the parent
         public int getIndexOfChild(Object parent, Object child) {
              if(parent instanceof TreeNode && child instanceof TreeNode) {
                   return ((TreeNode)parent).getIndex((TreeNode)child);
              return -1;
         * Returns true if node is a leaf.
         * @param node the node
         * @return true if the node is a leaf
         public boolean isLeaf(Object node) {
              if(node instanceof TreeNode) {
                   return ((TreeNode)node).isLeaf();
              return true;
         * Main method for testing.
         * @param args the command-line arguments
         public static void main(String[] args) {
              JFrame f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
              root.add(new DefaultMutableTreeNode("child_1"));
              DefaultMutableTreeNode c2 = new DefaultMutableTreeNode("child_2");
              c2.add(new DefaultMutableTreeNode("child_2_A"));
              c2.add(new DefaultMutableTreeNode("child_2_B"));
              root.add(c2);
              root.add(new DefaultMutableTreeNode("child_3"));
              root.add(new DefaultMutableTreeNode("child_4"));
              JTree tree = new JTree(new TreeNodeTreeModel(root));
              f.getContentPane().add(new JScrollPane(tree));
              f.pack();
              f.setSize(300, 500);
              f.show();
    // *** AbstractTreeModel ***
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    public abstract class AbstractTreeModel implements TreeModel {
         * The list of tree model listeners.
         private Vector modelListeners = new Vector();
         * The root object of the tree.
         private Object root = null;
         * Basic no-op constructor.
         public AbstractTreeModel() {
         * Gets the root object of the tree.
         * @return the root object
         public Object getRoot() {
              return this.root;
         * Sets the root object of the tree.
         * @param r the root object
         protected void setRoot(Object r) {
              this.root = r;
         * Gets the path to the root node for the specified object.
         * @param node the root node
         * @return the path to the object or <CODE>null</CODE>
         public Object[] getPathToRoot(Object node) {
              return getPathToRoot(node, 0);
         * Gets the path to the root node for the specified object.
         * @param node the root node
         * @param i the current index
         * @return the path to the object or <CODE>null</CODE>
         private Object[] getPathToRoot(Object node, int i) {
              Object anode[];
              if(node == null) {
                   if(i == 0) {
                        return null;
                   anode = new Object[i];
              } else {
                   i++;
                   if(node == getRoot()) {
                        anode = new Object[i];
                   } else {
                        anode = getPathToRoot(getParent(node), i);
                   anode[anode.length - i] = node;
              return anode;
         * Gets the parent object of the specified object. This method is not
         * part of the <code>javax.swing.tree.TreeModel</code> interface, but is
         * required to support the <code>getPathToRoot(Object)</code> method,
         * which is widely used in this class. Therefore, it is important to
         * correctly implement this method.
         * @param obj the object
         * @parma the parent object or null if no parent or invalid object
         protected abstract Object getParent(Object obj);
         * Adds a listener for the <CODE>TreeModelEvent</CODE> posted after the
         * tree changes.
         * @param l the tree model listener
         public void addTreeModelListener(TreeModelListener l) {
              modelListeners.addElement(l);
         * Removes a listener previously added with addTreeModelListener().
         * @param l the tree model listener
         public void removeTreeModelListener(TreeModelListener l) {
              modelListeners.removeElement(l);
         * Forces the tree to reload. This is useful when many changes occur
         * under the root node in the tree structure.
         * <b>NOTE:</b> This will cause the tree to be collapsed. To maintain
         * the expanded nodes, see the <code>getExpandedPaths(JTree)</code>
         * and <code>expandPaths(JTree, ArrayList)</code> methods.
         * @see #getExpandedPaths(JTree)
         * @see #expandPaths(JTree, ArrayList)
         public void reload() {
              reload(getRoot());
         * Forces the tree to repaint. This is useful when many changes occur
         * under a specific node in the tree structure.
         * <b>NOTE:</b> This will cause the tree to be collapsed below the
         * updated node.
         * @param node the node that changed
         public void reload(Object node) {
              if(node != null) {
                   TreePath tp = new TreePath(getPathToRoot(node));
                   fireTreeStructureChanged(new TreeModelEvent(this, tp));
         * Messaged when the user has altered the value for the item identified
         * by <CODE>path</CODE> to <CODE>newValue</CODE>.
         * @param path the path to the changed object
         * @param newValue the new value
         public void valueForPathChanged(TreePath path, Object newValue) {
              nodeChanged(path.getLastPathComponent());
         * Notifies the tree that nodes were inserted. The index is looked up
         * automatically.
         * @param node the parent node
         * @param child the inserted child node
         public void nodeInserted(Object node, Object child) {
              nodeInserted(node, child, -1);
         * Notifies the tree that nodes were inserted.
         * @param node the parent node
         * @param child the inserted child node
         * @param index the index of the child
         public void nodeInserted(Object node, Object child, int index) {
              if(index < 0) {
                   index = getIndexOfChild(node, child);
              if(node != null && child != null && index >= 0) {
                   TreePath tp = new TreePath(getPathToRoot(node));
                   int[] ai = { index };
                   Object[] ac = { child };
                   fireTreeNodesInserted(new TreeModelEvent(this, tp, ai, ac));
         * Notifies the tree that nodes were removed. The index is required
         * since by this point, the object will no longer be in the tree.
         * @param node the parent node
         * @param child the removed child node
         * @param index the index of the child
         public void nodeRemoved(Object node, Object child, int index) {
              if(node != null && child != null && index >= 0) {
                   TreePath tp = new TreePath(getPathToRoot(node));
                   int[] ai = { index };
                   Object[] ac = { child };
                   fireTreeNodesRemoved(new TreeModelEvent(this, tp, ai, ac));
         * Notifies the tree that a node was changed.
         * @param node the changed node
         public void nodeChanged(Object node) {
              if(node != null) {
                   TreePath tp = new TreePath(getPathToRoot(node));
                   fireTreeNodesChanged(new TreeModelEvent(this, tp, null, null));
         * Fires "tree nodes changed" events to all listeners.
         * @param event the tree model event
         protected void fireTreeNodesChanged(TreeModelEvent event) {
              for(int i = 0; i < modelListeners.size(); i++) {
                   ((TreeModelListener)modelListeners.elementAt(i)).treeNodesChanged(event);
         * Fires "tree nodes inserted" events to all listeners.
         * @param event the tree model event
         protected void fireTreeNodesInserted(TreeModelEvent event) {
              for(int i = 0; i < modelListeners.size(); i++) {
                   ((TreeModelListener)modelListeners.elementAt(i)).treeNodesInserted(event);
         * Fires "tree nodes removed" events to all listeners.
         * @param event the tree model event
         protected void fireTreeNodesRemoved(TreeModelEvent event) {
              for(int i = 0; i < modelListeners.size(); i++) {
                   ((TreeModelListener)modelListeners.elementAt(i)).treeNodesRemoved(event);
         * Fires "tree structure changed" events to all listeners.
         * @param event the tree model event
         protected void fireTreeStructureChanged(TreeModelEvent event) {
              for(int i = 0; i < modelListeners.size(); i++) {
                   ((TreeModelListener)modelListeners.elementAt(i)).treeStructureChanged(event);
         * Records the list of currently expanded paths in the specified tree.
         * This method is meant to be called before calling the
         * <code>reload()</code> methods to allow the tree to store the paths.
         * @param tree the tree
         * @param pathlist the list of expanded paths
         public ArrayList getExpandedPaths(JTree tree) {
              ArrayList expandedPaths = new ArrayList();
              addExpandedPaths(tree, tree.getPathForRow(0), expandedPaths);
              return expandedPaths;
         * Adds the expanded descendants of the specifed path in the specified
         * tree to the internal expanded list.
         * @param tree the tree
         * @param path the path
         * @param pathlist the list of expanded paths
         private void addExpandedPaths(JTree tree, TreePath path, ArrayList pathlist) {
              Enumeration enum = tree.getExpandedDescendants(path);
              while(enum.hasMoreElements()) {
                   TreePath tp = (TreePath)enum.nextElement();
                   pathlist.add(tp);
                   addExpandedPaths(tree, tp, pathlist);
         * Re-expands the expanded paths in the specified tree. This method is
         * meant to be called before calling the <code>reload()</code> methods
         * to allow the tree to store the paths.
         * @param tree the tree
         * @param pathlist the list of expanded paths
         public void expandPaths(JTree tree, ArrayList pathlist) {
              for(int i = 0; i < pathlist.size(); i++) {
                   tree.expandPath((TreePath)pathlist.get(i));

    Hey
    I'm not trying to show anyone up here, but having just built a tree model for displaying an XML document in a tree, I thought this seemed like a neat exercise.
    I implemented this very differently from the @OP. I only have one class, HiddenNodeTreeModel. All the hidden node data is stored in the model itself in my class. The advantage of what I've created is it will work with any TreeModel. The disadvantage is that I think it's not going to be very scalable - the additional computing to get the number of child nodes and to adjust indexes is heavy. So if you need a scalable solution definitely don't use this.
    Anyway here you go
    HiddenNodeTreeModel.java
    ======================
    package tjacobs.ui.tree;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Iterator;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JTree;
    import javax.swing.event.TreeModelListener;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeModel;
    import javax.swing.tree.TreePath;
    import tjacobs.ui.WindowUtilities;
    public class HiddenNodeTreeModel implements TreeModel {
         TreeModel mModel;
         ArrayList<Object> mHidden = new ArrayList<Object>();
         public HiddenNodeTreeModel (TreeModel model) {
              mModel = model;
         public void addTreeModelListener(TreeModelListener arg0) {
              mModel.addTreeModelListener(arg0);
         private ArrayList<Integer> getHiddenChildren(Object parent) {
              ArrayList<Integer> spots = new ArrayList<Integer>();
              Iterator _i = mHidden.iterator();
              while (_i.hasNext()) {
                   Object hidden = _i.next();
                   int idx = mModel.getIndexOfChild(parent, hidden);
                   if (idx != -1) {
                        spots.add(idx);
              return spots;
         public Object getChild(Object arg0, int index) {
              ArrayList<Integer> spots = getHiddenChildren(arg0);
              Collections.sort(spots);
              Iterator<Integer> _i = spots.iterator();
              while (_i.hasNext()) {
                   int num = _i.next();
                   if (num <= index) {
                        index++;
              return mModel.getChild(arg0, index);
         public int getChildCount(Object arg0) {
              ArrayList list = getHiddenChildren(arg0);
              System.out.println("size = " + list.size());
              return mModel.getChildCount(arg0) - list.size();
         public int getIndexOfChild(Object arg0, Object arg1) {
              int index = mModel.getIndexOfChild(arg0, arg1);
              ArrayList<Integer> spots = getHiddenChildren(arg0);
              Collections.sort(spots);
              Iterator<Integer> _i = spots.iterator();
              int toSub = 0;
              while (_i.hasNext()) {
                   int num = _i.next();
                   if (num <= index) {
                        toSub++;
              return index - toSub;
         public Object getRoot() {
              // TODO Auto-generated method stub
              return mModel.getRoot();
         public boolean isLeaf(Object arg0) {
              // TODO Auto-generated method stub
              return mModel.isLeaf(arg0);
         public void removeTreeModelListener(TreeModelListener arg0) {
              mModel.removeTreeModelListener(arg0);
         public void valueForPathChanged(TreePath arg0, Object arg1) {
              mModel.valueForPathChanged(arg0, arg1);
         public void hideNode(Object node) {
              if (node instanceof TreePath) {
                   node = ((TreePath)node).getLastPathComponent();
              mHidden.add(node);
         public void showNode(Object node) {
              mHidden.remove(node);
         public void showAll() {
              mHidden.clear();
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              DefaultMutableTreeNode A = new DefaultMutableTreeNode("A");
              DefaultMutableTreeNode B = new DefaultMutableTreeNode("B");
              DefaultMutableTreeNode C = new DefaultMutableTreeNode("C");
              DefaultMutableTreeNode D = new DefaultMutableTreeNode("D");
              DefaultMutableTreeNode E = new DefaultMutableTreeNode("E");
              DefaultMutableTreeNode F = new DefaultMutableTreeNode("F");
              A.add(B);
              B.add(C);
              B.add(D);
              B.add(E);
              E.add(F);
              DefaultTreeModel model = new DefaultTreeModel(A);
              final HiddenNodeTreeModel hmodel = new HiddenNodeTreeModel(model);
              final JTree tree = new JTree(hmodel);
              JFrame jf = new JFrame("HiddenNodeTreeModel Test");
              jf.add(tree);
              JMenuBar bar = new JMenuBar();
              jf.setJMenuBar(bar);
              JMenu menu = new JMenu("Options");
              bar.add(menu);
              final JMenuItem hide = new JMenuItem("Hide");
              final JMenuItem show = new JMenuItem("ShowAll");
              menu.add(hide);
              menu.add(show);
              ActionListener al = new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        if (ae.getSource() == hide) {
                             hmodel.hideNode(tree.getSelectionPath());
                             tree.updateUI();
                        else {
                             hmodel.showAll();
                             tree.updateUI();
              hide.addActionListener(al);
              show.addActionListener(al);
              jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              jf.setBounds(100,100,100,100);
              jf.setVisible(true);
    }

  • Error while running code template mapping between two oracle tables

    Hello All
    Iam getting the following error while running code template mapping between two oracle tables. Using OWB 11gR2 and oracle 11gR2 DB.
    java.sql.SQLException: ORA-20001: The active workspace is not valid as a target for this mapping
    c: at "OWBSYS.WB_RT_MAPAUDIT_UTIL", line 1065
    ORA-06512: at "OWBSYS.WB_RT_MAPAUDIT_UTIL", line 1087
    ORA-06512: at "SOURCE.FILENET_EX_UNIT_3", line 555
    ORA-06512: at line 4                                        
    Job 51 error: java.sql.SQLException: ORA-20001: The active workspace is not valid as a target for this mapping
    ORA-06512: at "OWBSYS.WB_RT_MAPAUDIT_UTIL", line 1065
    ORA-06512: at "OWBSYS.WB_RT_MAPAUDIT_UTIL", line 1087
    ORA-06512: at "SOURCE.FILENET_EX_UNIT_3", line 555
    ORA-06512: at line 4
    Quick help is highly appreciated.

    Dera Dallan
    its only a target user for the workspace where you are deploying the mapping from.
    I have two repositories for two different projects. each repositary has its own workspace.
    ex:-
    Project 1
    Work space bpms_rep_owner
    Repositary owner bpms_rep_owner
    Repositary user bpms_rep_user
    Project 2
    Work space dem_rep_owner
    Repositary owner dem_rep_owner
    Repositary user dem_rep_user
    Reg
    S.Gyazuddin

  • ' Include ... ' tag in a page which use UIX template is not work! Help!

    I've used JDev9.0.4 and UIX.
    I want to use include and template at the same time.
    So I've put a 'globalHeader' and a 'tabBar' in 'Test.uit'.
    And I've made 'TestUIT.uix' which used 'Test.uit' as a template include 'Table.uix'.
    But 'Table.uix' included by 'TestUIT.uix' has been ignored and has not worked!!
    Is this problem oriented from my fault or a bug of jdev904?
    My codes like this.
    -->
    Test.uit
    <?xml version="1.0" encoding="windows-949"?>
    <templateDefinition xmlns="http://xmlns.oracle.com/uix/ui"
    xmlns:ui="http://xmlns.oracle.com/uix/ui"
    xmlns:data="http://xmlns.oracle.com/uix/ui"
    targetNamespace="http://www.example.org/demo/templates"
    localName="oplBaseLayout">
    <content>
    <dataScope xmlns="http://xmlns.oracle.com/uix/ui"
    xmlns:data="http://xmlns.oracle.com/uix/ui">
    <provider>
    </provider>
    <contents>
    <pageLayout>
    <tabs>
    <include node="../Component/MenuBar/TabBar.uix"/>
    </tabs>
    <pageHeader>
    <include node="../Component/MenuBar/GlobalHeader.uix"/>
    </pageHeader>
    <contents>
    </contents>
    </pageLayout>
    </contents>
    </dataScope>
    </content>
    </templateDefinition>
    TestUIT.uix
    <?xml version="1.0" encoding="windows-949"?>
    <page xmlns="http://xmlns.oracle.com/uix/controller"
    xmlns:ui="http://xmlns.oracle.com/uix/ui"
    xmlns:data="http://xmlns.oracle.com/uix/ui"
    xmlns:ctrl="http://xmlns.oracle.com/uix/controller"
    xmlns:html="http://www.w3.org/TR/REC-html40"
    xmlns:bc4j="http://xmlns.oracle.com/uix/bc4j"
    xmlns:myTemplate="http://www.example.org/demo/templates">
    <bc4j:registryDef>
    <bc4j:rootAppModuleDef name="OligoAppModule" definition="View.OplModule"
    releaseMode="stateful">
    <bc4j:viewObjectDef name="Oligo" rangeSize="3"/>
    </bc4j:rootAppModuleDef>
    </bc4j:registryDef>
    <templates xmlns="http://xmlns.oracle.com/uix/ui">
    <templateImport source="Test.uit"/>
    </templates>
    <content>
    <dataScope xmlns="http://xmlns.oracle.com/uix/ui">
    <provider/>
    <contents>
    <document>
    <metaContainer>
    <head title="UITTest"/>
    </metaContainer>
    <contents>
    <body>
    <contents>
    <myTemplate:oplBaseLayout title="UITTest">
    <contents>
    <bc4j:viewObjectScope name="Oligo">
    <contents>
    <include node="Table.uix"/> </contents>
    </bc4j:viewObjectScope>
    </contents>
    </myTemplate:oplBaseLayout>
    </contents>
    </body>
    </contents>
    </document>
    </contents>
    </dataScope>
    </content>
    <handlers/>
    </page>

    Hi -
    But 'Table.uix' included by 'TestUIT.uix' has been
    ignored and has not worked!!So is the problem that you don't see the contents of Table.uix? Are any error messages logged? Do you see the contents of the GlobalHeader.uix and TabBar.uix includes?
    It would be very helpful if you could put together a minimal testcase which reproduces the problem (no BC4J tags) that we could use to test the problem out over here.
    Andy

  • Using a template engine in a portlet, possible?

    Hi there,
    When developing servlets I've always used webmacro as a template engine,
    separating the code (java) from the layout (html). With Portlets it seems
    that people put their html within the java code.
    Are there any template engine solutions available for portlets, besides
    jsp ofcourse. I'm not really familiar with jsp, and also isn't jsp doing the
    same thing, putting java code within the html?
    I read it was possible to use webmacro without a servlet container, so
    perhaps this is the way to go using it with portlets. But are there also
    any integrated solutions.
    Does anybody have any experience separating their code and layout using a
    template engine? eg webmacro, velocity
    How do other developers do this, do you use jsp, or put your html directly
    into your code?
    kind regards
    ido

    Hi Ido,
    If you can do it in a servlet, then you should be able to do it in the portlet too. You need to specify the servlet for the showpage information in your provider.xml file.
    As long as all the HTMl is getting generated upfront (at the Servlet side) then you should not have any issues.
    Let me know if you have issues doing it this way.
    thanks,
    Harsha

  • Java Server execute code on exit

    Hi,
    I want to make a simple server in java and i want it to execute some code (flush files, etc..) when i tell the server to stop.
    I want to be able to do this like a service on linux (calling some script and giving a param stop).
    Something like responding to a given signal whould be nice.
    Did i make myself clear?
    Thanks,
    Ricardo Lopes.

    Or only accept "STOP" from localhost?Yep i thought about that.
    And it came to my mind that an attacker could use ip soffing ???
    I think that my firewall should block that traffic, i believe that there is a rule that says to reject all traffic from localhost than come from an interface different that lo but i'm not sure.
    The commons daemon seems to be off-line i will take a look later.

Maybe you are looking for

  • Can't connect to Wireless Network. Officejet 6500a

    I just bought an Officejet 6500A and can't seem to have it connect to my wireless network via Ethernet. All the cables are connected, however when I try to install using the network connection I keep gettting an error saying no networks are found. I

  • Lumia 520 goes to lockscreen inadvertently

    Sometimes i'll be tapping away on my lumia 520, and the screen goes dark. Then I discover that it had gone to lock screen, even though i hadn't pressed the botton on the side. What's happening here?

  • Migration from Photoshop Elements Windows to MAC

    Hi, I don't know if this question is answered already somewhere in this forum. I started a search without results. Maybe I'm wrong. If so, please apologize. I used Elements for years on my Windows box. Recently I bought an iMac and would like to know

  • Populating a load-status table from SQL*Loader

    Hello, I am using SQL*LDR to load a table and once I'm done with this load I am supposed to populate a status table which will capture the 'SYSDATE', and the total number of rows I loaded in the other table. Can anybody help me? Thanks

  • Asset capitalization in specific ledgers/depreciation areas

    Scenario: Example: Leading Ledger 0L: IFRS- Book depreciation 01 in AA u2013Posting to GL Non Leading Ledger  Z0: US GAAP Depreciation Area 04 in AA- Posting to GL Non leading ledger Z1 :JP GAAP:  No depreciation area in AA ( We donu2019t want to cap