comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * JTree-object - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/63aa95fb10c9d312 * ntohl, ntohs, etc - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bf612dd1448af95c * The use of listeners. - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2a547891c4625c30 * need to do session.setAttribute() after updating the session? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/63a78373d5d97071 * Getting Hostname in Java - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5a92b7b25ef233 * grabbing search engine queries - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a2982e579c419d74 * JDom Element query - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a80ed59b50371834 * Overriding Methods - 5 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/96c976ed93574cf5 * wondering why my array of strings (String[]) is not upcastable to Object ? _clb_ - 4 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e18b125925e3150f * XAResource implementation besides of DB and JMS - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/77247fc4362c3d3c * [jsp]: getProperty - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6230ddcfe0818100 * Problem with Java XML charset - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3e965f2263343304 * Delete tilde with ANT - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ffefc6088f080ac6 * Runtime.exec - no access to ports ? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/129ba54a793c2382 ============================================================================== TOPIC: JTree-object http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/63aa95fb10c9d312 ============================================================================== == 1 of 1 == Date: Mon, Dec 27 2004 6:01 pm From: Chris Smith Jacob <[EMAIL PROTECTED]> wrote: > > How can I get a view of "My computer", "C:", "D:" and so on to JTree? Like > > in Windows explorer? > > Check the "filesystem" module of http://geosoft.no/software > To put all entries from a disk drive into a JTree, do: I took a look at that code, noticed that it doesn't do the Right Thing, and modified it so that it does. If anyone's interested, I've included the modified classes, FileSystemTreeModel and FileSystemTreeRenderer, plus a test application that uses them. Basically the problem is that there's a difference between the visible filesystem and the logical filesystem. The java.io.File class gives you the logical filesystem by default. However, if you want (in the OP's words) "Like in Windows Explorer" then you need the visible one. The way to do that in Java is using javax.swing.filechooser.FileSystemView. As an added bonus, this also gives you the ability to show more appropriate visual representations of the nodes, as my renderer class does. So here's the test application, and the modified tree model and renderer: --- Test.java ---------------------------------------------------------- import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTree; import com.mindiq.util.FileSystemTreeModel; import com.mindiq.util.FileSystemTreeRenderer; public class Test { public static void main(String[] args) { FileSystemTreeModel model = new FileSystemTreeModel(); FileSystemTreeRenderer renderer = new FileSystemTreeRenderer(); JTree tree = new JTree(model); tree.setCellRenderer(renderer); tree.setRootVisible(false); tree.setShowsRootHandles(true); JFrame testFrame = new JFrame(); testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); testFrame.getContentPane().add(new JScrollPane(tree)); testFrame.pack(); testFrame.setVisible(true); } } --- FileSystemTreeModel.java ------------------------------------------- /* * (C) 2004 - Geotechnical Software Services This code is free * software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your * option) any later version. This code is distributed in the hope * that it will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU Lesser General Public License for more * details. You should have received a copy of the GNU Lesser General * Public License along with this program; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Some modifications (C) 2004, Chris Smith */ package com.mindiq.util; import java.io.File; import java.text.Collator; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.TreeSet; import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import javax.swing.filechooser.FileSystemView; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; /** * A TreeModel implementation for a disk directory structure. Typical * usage: * * <pre> * FileSystemTreeModel model = new FileSystemTreeModel(); * FileSystemTreeRenderer renderer = new FileSystemTreeRenderer(); * JTree tree = new JTree (model); * tree.setCellRenderer(renderer); * tree.setRootVisible(false); * tree.setShowsRootHandles(true); * </pre> * * @author <a href="mailto:[EMAIL PROTECTED]">Jacob Dreyer </a> * @author <a href="mailto:[EMAIL PROTECTED]">Chris Smith </a> */ public class FileSystemTreeModel implements TreeModel { /* * Define a better ordering for sorting files. */ private Comparator<File> sortComparator = new Comparator<File>() { public int compare(File a, File b) { Collator collator = Collator.getInstance(); if (a.isDirectory() && b.isFile()) return -1; else if (a.isFile() && b.isDirectory()) return +1; int result = collator.compare(a.getName(), b.getName()); if (result != 0) return result; result = collator.compare( a.getAbsolutePath(), b.getAbsolutePath()); return result; } }; private Collection<TreeModelListener> listeners; private Object falseRoot = new Object(); private File[] roots; private FileSystemView fsv; private boolean hiddenVisible; private HashMap<File, List<File>> sortedChildren; private HashMap<File, Long> lastModifiedTimes; /** * Create a tree model using the specified file system view and * the specified roots. This results in displaying a subset of * the actual filesystem. There need not be any specific * relationship between the roots specified. * * @param fsv The FileSystemView implementation * @param roots Root files */ public FileSystemTreeModel(FileSystemView fsv, File[] roots) { this.fsv = fsv; this.roots = roots; listeners = new ArrayList<TreeModelListener>(); sortedChildren = new HashMap<File, List<File>>(); lastModifiedTimes = new HashMap<File, Long>(); } /** * Create a tree model using the specified file system view. * * @param fsv The FileSystemView implementation */ public FileSystemTreeModel(FileSystemView fsv) { this(fsv, fsv.getRoots()); } /** * Create a tree model using the default file system view for this * platform. */ public FileSystemTreeModel() { this(FileSystemView.getFileSystemView()); } public Object getRoot() { return falseRoot; } public Object getChild(Object parent, int index) { if (parent == falseRoot) { return roots[index]; } else { List children = (List) sortedChildren.get(parent); return children == null ? null : children.get(index); } } public int getChildCount(Object parent) { if (parent == falseRoot) { return roots.length; } else { File file = (File) parent; if (!fsv.isTraversable(file)) return 0; File[] children = fsv.getFiles(file, !hiddenVisible); int nChildren = children == null ? 0 : children.length; long lastModified = file.lastModified(); boolean isFirstTime = lastModifiedTimes.get(file) == null; boolean isChanged = false; if (!isFirstTime) { Long modified = (Long) lastModifiedTimes.get(file); long diff = Math.abs(modified.longValue() - lastModified); // MS/Win or Samba HACK. Check this! isChanged = diff > 4000; } // Sort and register children info if (isFirstTime || isChanged) { lastModifiedTimes.put(file, new Long(lastModified)); TreeSet<File> sorted = new TreeSet<File>(sortComparator); for (int i = 0; i < nChildren; i++) { sorted.add(children[i]); } sortedChildren.put(file, new ArrayList<File>(sorted)); } // Notify listeners (visual tree typically) if changes if (isChanged) { TreeModelEvent event = new TreeModelEvent( this, getTreePath(file)); fireTreeStructureChanged(event); } return nChildren; } } private Object[] getTreePath(Object obj) { List<Object> path = new ArrayList<Object>(); while (obj != falseRoot) { path.add(obj); obj = fsv.getParentDirectory((File) obj); } path.add(falseRoot); int nElements = path.size(); Object[] treePath = new Object[nElements]; for (int i = 0; i < nElements; i++) { treePath[i] = path.get(nElements - i - 1); } return treePath; } public boolean isLeaf(Object node) { if (node == falseRoot) return false; else return !fsv.isTraversable((File) node); } public void valueForPathChanged(TreePath path, Object newValue) { } public int getIndexOfChild(Object parent, Object child) { List children = (List) sortedChildren.get(parent); return children.indexOf(child); } public void addTreeModelListener(TreeModelListener listener) { if (listener != null && !listeners.contains(listener)) listeners.add(listener); } public void removeTreeModelListener(TreeModelListener listener) { if (listener != null) listeners.remove(listener); } public void fireTreeNodesChanged(TreeModelEvent event) { for (Iterator i = listeners.iterator(); i.hasNext();) { TreeModelListener listener = (TreeModelListener) i.next(); listener.treeNodesChanged(event); } } public void fireTreeNodesInserted(TreeModelEvent event) { for (Iterator i = listeners.iterator(); i.hasNext();) { TreeModelListener listener = (TreeModelListener) i.next(); listener.treeNodesInserted(event); } } public void fireTreeNodesRemoved(TreeModelEvent event) { for (Iterator i = listeners.iterator(); i.hasNext();) { TreeModelListener listener = (TreeModelListener) i.next(); listener.treeNodesRemoved(event); } } public void fireTreeStructureChanged(TreeModelEvent event) { for (Iterator i = listeners.iterator(); i.hasNext();) { TreeModelListener listener = (TreeModelListener) i.next(); listener.treeStructureChanged(event); } } } --- FileSystemTreeRenderer.java ---------------------------------------- package com.mindiq.util; import java.awt.Component; import java.io.File; import javax.swing.JTree; import javax.swing.filechooser.FileSystemView; import javax.swing.tree.DefaultTreeCellRenderer; public class FileSystemTreeRenderer extends DefaultTreeCellRenderer { private FileSystemView fsv; public FileSystemTreeRenderer(FileSystemView fsv) { this.fsv = fsv; } public FileSystemTreeRenderer() { this(FileSystemView.getFileSystemView()); } public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (!(value instanceof File)) { return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); } super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus); setText(fsv.getSystemDisplayName((File) value)); setIcon(fsv.getSystemIcon((File) value)); return this; } } -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: ntohl, ntohs, etc http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bf612dd1448af95c ============================================================================== == 1 of 2 == Date: Mon, Dec 27 2004 8:05 pm From: "JohnP" are there any classes in java.net or javax that provide the ntohx functionality. Thanks for your help john == 2 of 2 == Date: Mon, Dec 27 2004 6:23 pm From: Chris Smith JohnP <[EMAIL PROTECTED]> wrote: > are there any classes in java.net or javax that provide the ntohx > functionality. No, because it is not needed. There is no way to observe the host byte order in Java, and all API functions that depend on byte ordering specify which they use (generally network byte order). When you write socket code, you'll typically write binary data using either a java.io.DataOutputStream or some view of java.nio.ByteBuffer, and these will give you the conversion you need. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: The use of listeners. http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2a547891c4625c30 ============================================================================== == 1 of 1 == Date: Mon, Dec 27 2004 6:09 pm From: Chris Smith Arun <[EMAIL PROTECTED]> wrote: > For example, a listener that is called when a JTree node is selected is > called BuildTreeSelectionListener (implementing treeselectionlistener). > > Then i use buildTree.addSelectionListener(new > BuildTreeSelectionListener). > > What i dont get is this... > > BuildTreeSelectionListener is called, and gets the node that has just > been selected. I now want this class to reference a method > onNodeSelection in my gui class (SwingMainView). > > To do this, i have to set that method to static, then call > SwingMainView.onNodeSelection(). To me this doesnt seem like good code? You're right; that's not good code. You should give the listener a reference to the actual object it needs to interact with, like this: public class BuildTreeSelectionListener implements TreeSelectionListener { private SwingMainView mainView; public BuildTreeSelectionListener(SwingMainView view) { this.mainView = view; } public void valueChanged(TreeSelectionEvent e) { mainView.doSomething(); } } Also, it's worth mentioning that inner classes have an implicit reference to their corresponding outer class, so if you're using inner classes (whether named or anonymous) this is no longer necessary. For example from within SwingMainView, you could write: buildTree.addSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { /* * The following is an implicit call to the outer class, * using the implicit outer class reference. */ doSomething(); } }); As a standard disclaimer, inner classes introduce circular dependencies and can interfere with reuse; generally they should only be used when there won't be any significant logic in the listener class itself. > On a totally different point, has anyone got a good resource for the > proper use of keyword 'super'. I cannot find one. Use of super isn't sophisticated enough to warrant its own resources. What do you want to know about it? Also, which of that keyword's two uses do you want to know about: calling methods, or constructor chaining? -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: need to do session.setAttribute() after updating the session? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/63a78373d5d97071 ============================================================================== == 1 of 2 == Date: Mon, Dec 27 2004 5:35 pm From: [EMAIL PROTECTED] There are 2 jsp pages. In page1.jsp, it will keep the session sa, and it can go to page2.jsp If page2.jsp will modify the session, do we need to set the session again, to make the session updated? i.e. do we need this: session.setAttribute("sa", sa); page1.jsp ========== session.setAttribute("sa", sa); page2.jsp ========= sa = (ServiceAddressModel)session.getAttribute("sa"); sa.setName("joe"); session.setAttribute("sa", sa); //do we need this?? please advise. thanks!! == 2 of 2 == Date: Mon, Dec 27 2004 11:25 pm From: "Ryan Stewart" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > There are 2 jsp pages. In page1.jsp, it will keep the session sa, and > it can go to page2.jsp > If page2.jsp will modify the session, do we need to set the session > again, to make the session > updated? i.e. do we need this: session.setAttribute("sa", sa); > > page1.jsp > ========== > > session.setAttribute("sa", sa); > > > page2.jsp > ========= > sa = (ServiceAddressModel)session.getAttribute("sa"); > sa.setName("joe"); > session.setAttribute("sa", sa); //do we need this?? > please advise. thanks!! > No you do not. Do you understand the concept of object references or pointers? This line: session.setAttribute("sa", sa); stores a reference to an object in the session. This line: sa = (ServiceAddressModel)session.getAttribute("sa"); gets that same reference out of the session. However all three references (sa in page1, the one in the session, and sa in page2) point to the same object. For example: ArrayList a = new ArrayList(); ArrayList b = a; ArrayList c = b; a.add("foo"); How many elements does a have in it? What about b? And c? The correct answer to all three is "one element". This is because a, b, and c are three different reference variables that refer to the same ArrayList. ============================================================================== TOPIC: Getting Hostname in Java http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5a92b7b25ef233 ============================================================================== == 1 of 1 == Date: Mon, Dec 27 2004 5:42 pm From: [EMAIL PROTECTED] (hiwa) You can use methods of java.net.InetAddress class or java.net.NetworkInterface class. ============================================================================== TOPIC: grabbing search engine queries http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a2982e579c419d74 ============================================================================== == 1 of 1 == Date: Mon, Dec 27 2004 6:06 pm From: "Ruel Loehr" Hey Gang, Here is what I am trying to do: I am a programmer by day, and an artist by night. Now I am trying to combine my crafts. I have been working on a painting: http://photos1.blogger.com/img/60/1387/320/Picture%20021.jpg It is kind of a big comic with 2 word balloons. I want to install an led screen in each balloon, and have it stream real time search engine queries over the wireless in my house. Pretty cool eh? My first task is to write a program to capture search queries. I have seen the finished product here: http://www.dogpile.com/info.dogpl/searchspy/results.htm?fci=1?filter=0&qcat=web So i know it can be done. My question: Does anyone know of an API out there somewhere, or of a search engine expert who might have more info on how to do this programatically? Thanks! Ruel Loehr http://ruelloehr.blogspot.com ============================================================================== TOPIC: JDom Element query http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a80ed59b50371834 ============================================================================== == 1 of 1 == Date: Mon, Dec 27 2004 6:45 pm From: [EMAIL PROTECTED] I am using a JTree to output an XML file through dom. What i want to do is as i create every node, i want to save the corresponding element to that node (using setUserObject - so its hidden in the node). I can do this fine. The trouble is when i want to output the tree back to a DOM. When i try to add the element from each node in the tree, i get an error saying the element has already got a parent. I see no way of removing a parent from each element, and have tried just adding the root element but that hasnt worked. Does anyone know how i can remove a parent from an element, so i can add this element to another parent element?? ============================================================================== TOPIC: Overriding Methods http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/96c976ed93574cf5 ============================================================================== == 1 of 5 == Date: Mon, Dec 27 2004 6:48 pm From: [EMAIL PROTECTED] The curious thing about Java is when I override a method in a derived class, the overridden method is called in the base class. I'm hoping this is somehow my mistake, as I'm new to Java and I cannot imagine why anyone would do this, but it seems like the behaviour I'm witnessing. That's a misfeature in my mind, because the base class cannot expect to use methods from a derived class (especially before said class has been constructed) and have them function as expected. My dilema is this: I called an accessor method in the constructor of my base class to set a value. I created a derived class that overrides this method to add an upper-bounds check. When I call the base class constructor using super() the upper bound member is not yet initialized, and is the default 0. The base class then calls the overridden method to set the value, the upper bound is zero and the value is clipped to 0 regardless of what it was. This is obviously not the desired behaviour! Is my interpretation of what's happening correct? If so what's the 'Java' way of dealing with it? Thanks, -Dan == 2 of 5 == Date: Mon, Dec 27 2004 8:45 pm From: "Adam Maass" <[EMAIL PROTECTED]> wrote: > The curious thing about Java is when I override a method in a derived > class, the overridden method is called in the base class. This is correct. > > That's a misfeature in my mind, because the base class cannot expect to > use methods from a derived class (especially before said class has been > constructed) and have them function as expected. Why not? If the derived class specializes the behavior of a method, then this exactly what you would expect. > > My dilema is this: > > I called an accessor method in the constructor of my base class to set > a value. I created a derived class that overrides this method to add an > upper-bounds check. When I call the base class constructor using > super() the upper bound member is not yet initialized, and is the > default 0. The base class then calls the overridden method to set the > value, the upper bound is zero and the value is clipped to 0 regardless > of what it was. This is obviously not the desired behaviour! This is one of the "gotchas" in Java programming. You don't want to call non-private, non-private instance methods from the constructor of the base class for the very reason that these methods are always virtual, and you could end up executing code in the derived class before the derived class' constructor has finished executing. > > Is my interpretation of what's happening correct? If so what's the > 'Java' way of dealing with it? In this case, maybe you want to promote bounds-checking to the superclass. Or: You call another constructor in the base class that does not call the overridden method; once the bound has been set in your derived class, you call the method from that constructor. -- Adam Maass == 3 of 5 == Date: Mon, Dec 27 2004 11:43 pm From: Chris Smith <[EMAIL PROTECTED]> wrote: > The curious thing about Java is when I override a method in a derived > class, the overridden method is called in the base class. I'm hoping > this is somehow my mistake, as I'm new to Java and I cannot imagine why > anyone would do this, but it seems like the behaviour I'm witnessing. > > That's a misfeature in my mind I'd suggest that your mind is the one in error here, since what you're complaining about one of the most fundamental aspects of object-oriented programming. It's called polymorphism, and without it you aren't writing OO software. > I called an accessor method in the constructor of my base class to set > a value. Yep. You should be very careful about calling methods from a constructor, unless they are private, final, or static. By "very careful" I mean don't ever do it, unless you're willing to write a very long essay on why that's what you want. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation == 4 of 5 == Date: Mon, Dec 27 2004 11:44 pm From: [EMAIL PROTECTED] Adam Maass: Thanks for the tip, I will remember to be careful what methods I call from the constructor. It's just unpredictable unless they are private, static, or final. Thanks for setting me straight on this. -Dan Chris Smith wrote: > I'd suggest that your mind is the one in error here, since what you're > complaining about one of the most fundamental aspects of object-oriented > programming. It's called polymorphism, and without it you aren't > writing OO software. Mr Smith: It's noteworthy that C++ doesn't have this problem, you can call public methods from the constructor as long as they are not declared virtual. That's a much better system in my humble opinion. Is my mind in error or do you not think that you can write OO software in C++? == 5 of 5 == Date: Tues, Dec 28 2004 1:01 am From: Chris Smith <[EMAIL PROTECTED]> wrote: > Mr Smith: It's noteworthy that C++ doesn't have this problem, you can > call public methods from the constructor as long as they are not > declared virtual. That's a much better system in my humble opinion. Is > my mind in error or do you not think that you can write OO software in > C++? You obviously meant something different from what you said. I was responding to "The curious thing about Java is when I override a method in a derived class, the overridden method is called in the base class." If you aren't distressed by polymorphism and merely want to control it, then see the final keyword, which I mentioned in my earlier reply. It's essentially the opposite of C++'s virtual, except it prevents that confusing scenario where you have one method hiding another by the same name. As for the remaining minor difference between C++ and Java, it's really quite moot; both languages do things in a way that can have extremely surprising side-effects. Either way, it becomes necessary to be very careful about what you do from a constructor. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: wondering why my array of strings (String[]) is not upcastable to Object ? _clb_ http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e18b125925e3150f ============================================================================== == 1 of 4 == Date: Mon, Dec 27 2004 7:20 pm From: [EMAIL PROTECTED] Hi ! I wonder if one of you nice java experts could help me with a real quick question. I am unable to get the code in 'FAILS TO COMPILE' (in the function below to work... well actually i have simple workaround... But this really started to annoy me. There's probably some subtle Java point i'm missing (or worse... maybe there's an eclipse bug?). anyway... if someone could tell me what the root of the problem might be, I'd be most grateful. CODE: void bizzare() { String[] sfoo = { "boo", "zoo"}; Object o = sfoo; // String[] can be assigned to an Object final Object[][] good = { {"foo", sfoo }, {"bar", sfoo } }; // FAILS TO COMPILE.. not sure why // final Object[][] expected = { // {"foo", (Object){ "boo", "zoo"} },// Casting fails // {"bar", { "boo", "zoo"} } // so does not casting. // }; // } FINALLY... my work-around: void workAround() { final Object[][] good = { {"foo", new String[] { "boo", "zoo"} }, {"bar", new String[] { "boo", "zoo"} } }; } thanks in advance for any advice / help you can spare.... / chris == 2 of 4 == Date: Mon, Dec 27 2004 7:36 pm From: [EMAIL PROTECTED] Is the syntax error you are getting an indication that { was expected and then that there was an illegal initializer for Object. I think the problem lies in the use of an initializer list. If a list creates a String array, it is automatically an Object. I can't find a specific statement about this, but in my experience the only time I'm able to use an initializer list is the first time I create a reference to a new array. == 3 of 4 == Date: Mon, Dec 27 2004 7:42 pm From: [EMAIL PROTECTED] You might also consider creating an anonymous array new String[]{....} == 4 of 4 == Date: Mon, Dec 27 2004 11:20 pm From: "Ryan Stewart" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi ! > > I wonder if one of you nice java experts could help me with a real > quick question. > > I am unable to get the code in 'FAILS TO COMPILE' (in the function > below to work... well actually i have simple workaround... But this > really started to annoy me. There's probably some subtle Java point > i'm missing (or worse... maybe there's an eclipse bug?). > anyway... if someone could tell me what the root of the problem might > be, I'd be most grateful. > > CODE: > > void bizzare() > { > String[] sfoo = { "boo", "zoo"}; > Object o = sfoo; // String[] can be assigned to an Object > > final Object[][] good = { > {"foo", sfoo }, > {"bar", sfoo } > > }; > > // FAILS TO COMPILE.. not sure why > // final Object[][] expected = { > // {"foo", (Object){ "boo", "zoo"} },// Casting fails > // {"bar", { "boo", "zoo"} } // so does not casting. > // }; > // > } > Nothing very bizarre about it. Would you expect the following to work? Object o = {"a", "b"}; If so, why? If not, then you are correct, and you have your answer. In the code that doesn't compile, you're declaring an array of Object arrays? In the initializer, you have two open braces followed by "foo". That means the Object in the first position of the first object array (i.e. expected[0][0]) is the String "foo" which is an Object, so that works. Then you attempt to place the following into expected[0][1]: {"boo", "zoo"}. However, the type of expected[0][1] is Object, and {"boo", "zoo"} is not a valid initializer for Object, which might be what your compiler was telling you. You may *only* use the special array initializer when initializing an explicitly declared array. The fact that an array is an Object is irrelevant. ============================================================================== TOPIC: XAResource implementation besides of DB and JMS http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/77247fc4362c3d3c ============================================================================== == 1 of 1 == Date: Mon, Dec 27 2004 7:44 pm From: "Li Ma" Hi All, When I read article about JTA, the most commonly used XAResource implementation is for either DB or JMS. I'm wondering if there's any other type of XAResource is really meaningful or useful to be cretaed at all. If you have experience making any XAResource besides of DB and JMS, would you please share your knowledge. It would be great if you can tell what kind of XAResource you have created and where it is used( from both business and coding point of view ). It will be even better if you can share idea about how the new XAResource is implemented. Thanks! ============================================================================== TOPIC: [jsp]: getProperty http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6230ddcfe0818100 ============================================================================== == 1 of 1 == Date: Mon, Dec 27 2004 11:48 pm From: "Ryan Stewart" "Marcus Reiter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Okay, finally this works: > > <%@ page language="java" %> > <jsp:useBean id="myBean" class="myPackage.MyBean" scope="application"/> > <jsp:setProperty name="myBean" property="myIndex" value="10"/> > <jsp:getProperty name="myBean" property="myVector"/> > > However, this vector is quite complicated - > it contains several Beans, each of them represents an entry of my > database, > so it contains about 10 values I would like to print out. > > How can that be done? > > So far it just prints out the objects, which is just nonsense of course. > I thought I maybe could just acesss that dynamically created vector and > use > it as if it was a Bean again > and try to acess the Beans inside it with another getProperty method - > something like that worked in Struts. ( Which I can't use in this case). > > That's what I did to access my values, but it doesn't work: > > <jsp:useBean id="myOtherBean" class="myPackage.MyOtherBean" > scope="application"/> > <jsp:getProperty name="myVector" property="myOtherBean"/> If you didn't just mix this line up then I think I see what you were trying to do with it, but that isn't how it works. "name" is the name of the bean to look in. It must mach the id of your useBean tag. "property" is the property of the specified bean to retrieve. > <jsp:getProperty name="myOtherBean" property="myStringValues"/> > > Any ideas? > > Thanks a lot, as always! > Try JSTL. It would be something like <c:forEach var="bean" items="${myBean.myVector}"> <c:out value="${bean.property1}" /> <c:out value="${bean.property2}" /> ... </c:forEach> Otherwise I'm not sure there's a solution using just jsp tags. I'm no expert on those, though. I have very little experience with them. ============================================================================== TOPIC: Problem with Java XML charset http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3e965f2263343304 ============================================================================== == 1 of 1 == Date: Tues, Dec 28 2004 8:10 am From: "Erik A. Brandstadmoen" I'm having problems building a DOM document with java using a ny other character set than utf-8. The code snippet at the further down produces the following output. Why? I explicitly produce an XML document using iso8859-1 charset, so why does Java suddenly think I want utf-8 instead? Is there any way to tell the DocumentBuilder classes that I want to work with a character set different from utf-8? I haven't been able to figure out. Thanks in advance. Erik B. $ java TestXMLEncoding Result: <?xml version="1.0" encoding="utf-8"?><definisjonsark/> $ Hvorfor og hvor og hva er det som forandrer tegnsettet? Erik. Code : import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.StringWriter; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.xml.sax.SAXException; /* * Created on Dec 23, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author mfreab * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class TestXMLEncoding { public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException { TestXMLEncoding test = new TestXMLEncoding(); test.testXML(); } public TestXMLEncoding() { } public void testXML() throws IOException, SAXException, ParserConfigurationException { Document xmlDocument = null; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //factory.setValidating(true); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); System.out.println("Result: " + this.getAsString(xmlDocument)); } private String getAsString(Document doc) { String retVal = null; try { // Prepare the DOM docuemnt for writing Source source = new DOMSource(doc); // Prepare the result string StringWriter w = new StringWriter(); Result result = new StreamResult(w); // Write the DOM document to file Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source,result); retVal = w.getBuffer().toString(); } catch (TransformerConfigurationException tce) { tce.printStackTrace(); } catch (TransformerException te) { te.printStackTrace(); } return retVal; } } ============================================================================== TOPIC: Delete tilde with ANT http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ffefc6088f080ac6 ============================================================================== == 1 of 1 == Date: Mon, Dec 27 2004 11:47 pm From: "Berlin Brown" Is there a way to delete the tilde that emacs puts at the ends of its file from a n ANT delete, fileset task Something along the lines of: <fileset> <include filename="**/*.~" /> </fileset> Actually emacs does a number to the file with CVS use: filename.~1.1~ I think I could use the ant regex, but I want to avoid having to include a new library. ============================================================================== TOPIC: Runtime.exec - no access to ports ? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/129ba54a793c2382 ============================================================================== == 1 of 1 == Date: Tues, Dec 28 2004 12:07 am From: Andrew Thompson On Mon, 27 Dec 2004 23:27:26 GMT, Darek Danielewski wrote: > Am I missing something in the permissions? If you are, you should be getting a great deal of information in the StackTrace.. <http://www.physci.org/codes/javafaq.jsp#stacktrace> Submitting an SSCCE will probably produce more definitive suggestions. <http://www.physci.org/codes/sscce.jsp> HTH -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.LensEscapes.com/ Images that escape the mundane ============================================================================== You received this message because you are subscribed to the Google Groups "comp.lang.java.programmer" group. To post to this group, send email to [EMAIL PROTECTED] or visit http://groups-beta.google.com/group/comp.lang.java.programmer To unsubscribe from this group, send email to [EMAIL PROTECTED] To change the way you get mail from this group, visit: http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe To report abuse, send email explaining the problem to [EMAIL PROTECTED] ============================================================================== Google Groups: http://groups-beta.google.com
