How do I use XMLStreamWriter to write exactly what I put in? For instance, if I create script tag and fill it with javascript I don't want all my single quotes coming out as '
hello i am a student and i am doing my senior project it is about developing an application in j2me for scanning a barcode and extract the number of the barcode in a message to be send.
please i search the net but i cant found something usefull i am new at j2me if someone could help me with sourch code and how to create it i will be very thankfull my email is [email protected]
thanks in advanced
I was writing two implementations of a linked list for an assignment, a doubly linked list and a circular doubly linked list. Now as the class representing a Link within the linked list is the same in both implementations, I want to use it in both.
Now I wonder which approach would be better:
Implement the Link class as a package private static member class in the first implementation and then use this class in the second implementation or make the Link class a package private class.
Hi.
I'm testing a Swing GUI application using the UISpec4J testing framework. I'm testing validation code on a JTextField, but the framework does not support focus-change events, as it runs the application in a headless fashion.
The text field has a DocumentEvent attached to it that activates the validation code. I'm trying to figure out how to dispatch the document event manually to activate the validation code. Trying to dispatch focus or mouse events manually haven't been working for me.
Thanks for any help!
I'm looking to create a new app from scratch and will probably use Spring MVC and possibly Spring Web Flow. The projects created by Spring Roo use Spring MVC and optionally Web Flow. What are some good alternatives for view technology, or is JSP with spring and jstl taglibs and jquery the way to go?
I am trying to send a zipfile from my android application to our server and I keep getting a 411 length required error.
Here is the code that I am using to do that.
HttpPost post = new HttpPost("http://www.xyz.org/upload.json");
post.setHeader(C.constants.HTTP_CONTENT_TYPE, "application/octet-stream");
try {
FileInputStream fis = new FileInputStream("/data/data/org.myapp.appname/app_content.zip");
InputStreamEntity reqEntity = new InputStreamEntity(fis, -1);
post.setEntity(reqEntity);
String response = doPost(post);
Log.v(tag, "response from server " + response);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
What am I doing wrong here and may I also know how I can add more parameters with this post to send them to the server.
I jsut learned that
A class may be declared with the
modifier public, in which case that
class is visible to all classes
everywhere. If a class has no modifier
(the default, also known as
package-private), it is visible only
within its own package.
This is a clear statement. But this information interfere with my understanding of importing of packages (which easily can be wrong). I thought that importing a package I make classes from the imported package visible to the importing class.
So, how does it work? Are public classes visible to all classes everywhere under condition that the package containing the public class is imported? Or there is not such a condition? What about the package-private classes? They are invisible no mater if the containing package was imported or not?
ADDED:
It seems to me that I got 2 answers which are marked as good (up-voted) and which contradict eachother.
Hello. I am no newb on OO programming, but I am faced with a puzzling situation. I have been given a program to work on and extend, but the previous developers didn't seem that comfortable with OO, it seems they either had a C background or an unclear understanding of OO. Now, I don't suggest I am a better developer, I just think that I can spot some common OO errors. The difficult task is how to amend them.
In my case, I see a lot of this:
if (ret == 1) {
out.print("yadda yadda");
} else if (ret == 2) {
out.print("yadda yadda");
} else if (ret == 3) {
out.print("yadda yadda");
} else if (ret == 0) {
out.print("yadda yadda");
} else if (ret == 5) {
out.print("yadda yadda");
} else if (ret == 6) {
out.print("yadda yadda");
} else if (ret == 7) {
out.print("yadda yadda");
}
ret is a value returned by a function, in which all Exceptions are swallowed, and in the catch blocks, the above values are returned explicitly. Oftentimes, the Exceptions are simply swallowed, with empty catch blocks.
It's obvious that swalllowing exceptions is wrong OO design. My question concerns the use of return values. I believe that too is wrong, however I think that using Exceptions for control flow is equally wrong, and I can't think of anything to replace the above in a correct, OO manner.
Your input, please?
When updating an employee with id = 1 for example, what is the best way to delete all previous records in the table certificate for this employee_id and insert the new ones?.
create table EMPLOYEE (
id INT NOT NULL auto_increment,
first_name VARCHAR(20) default NULL,
last_name VARCHAR(20) default NULL,
salary INT default NULL,
PRIMARY KEY (id)
);
create table CERTIFICATE (
id INT NOT NULL auto_increment,
certificate_name VARCHAR(30) default NULL,
employee_id INT default NULL,
PRIMARY KEY (id)
);
Hibernate mapping
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Employee" table="EMPLOYEE">
<id name="id" type="int" column="id">
<generator class="sequence">
<param name="sequence">employee_seq</param>
</generator>
</id>
<set name="certificates" lazy="false" cascade="all">
<key column="employee_id" not-null="true"/>
<one-to-many class="Certificate"/>
</set>
<property name="firstName" column="first_name"/>
<property name="lastName" column="last_name"/>
<property name="salary" column="salary"/>
</class>
<class name="Certificate" table="CERTIFICATE">
<id name="id" type="int" column="id">
<param name="sequence">certificate_seq</param>
</id>
<property name="employee_id" column="employee_id" insert="false" update="false"/>
<property name="name" column="certificate_name"/>
</class>
</hibernate-mapping>
Hi,
Im wondering if it is possible to get data from property which is map cotaining pairs Key-StringArray (Map) in BeanUtils library. I just simply need to access one of array elements by calling propertyName=string[0]. Current version (1.8.3) does not support indexed properties. If you look into their code you will find in class PropertyUtilsBean in method getPropertyOfMapBean:
if (resolver.isIndexed(propertyName) || resolver.isMapped(propertyName)) {
throw new IllegalArgumentException(
"Indexed or mapped properties are not supported on"
+ " objects of type Map: " + propertyName);
}
way too bad:-( Have any of you any tip how to do it somehow differently?
Hi,
I'm getting a Null ArrayList in a program i'm developing. For testing purposes I created this really small example that still has the same problem. I already tried diferent Primary Keys, but the problem persists.
Any ideas or suggestions?
1-Employee class
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Employee {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String key;
@Persistent
private ArrayList<String> nicks;
public Employee(ArrayList<String> nicks) {
this.setNicks(nicks);
}
public String getKey() {
return key;
}
public void setNicks(ArrayList<String> nicks) {
this.nicks = nicks;
}
public ArrayList<String> getNicks() {
return nicks;
}
}
2-EmployeeService
public class BookServiceImpl extends RemoteServiceServlet implements
EmployeeService {
public void addEmployee(){
ArrayList<String> nicks = new ArrayList<String>();
nicks.add("name1");
nicks.add("name2");
Employee employee = new Employee(nicks);
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.makePersistent(employee);
} finally {
pm.close();
}
}
/**
* @return
* @throws NotLoggedInException
* @gwt.typeArgs <Employee>
*/
public Collection<Employee> getEmployees() {
PersistenceManager pm = getPersistenceManager();
try {
Query q = pm.newQuery("SELECT FROM " + Employee.class.getName());
Collection<Employee> list =
pm.detachCopyAll((Collection<Employee>)q.execute());
return list;
} finally {
pm.close();
}
}
}
Using axis1 it is possible to log incoming/outgoing soap messages by adding logging on HTTPSender in log4j.properties. After migrating to axis2 (version 1.4.1) I have a hard time figuring out how to accomplish the same kind of logging. I have tried to add logging on the axis2 package and org.apache.commons.httpclient but no logging is provided.
Any ideas?
TIA
What would happen if an exception is thrown during the execution of finalize()?
Is the stack unwind like normally? Does it continue finalize() and ignore the exception? Does it stop finalize() and continue GC the object? Or something else?
I'm not looking for guidelines of using finalize() there are plently of pages explaining that.
I've got a number of tasks/servlets that are hitting the HardDeadlineExceededError which is leaving everything hanging in an 'still executing' state.
The work being done can easily exceed the 29 second threshold.
I try to catch the DeadlineExceededException and base Exception in order to save the exit
state but neither of these exception handlers are being caught...
Is there a way to determine which tasks are in the queue or currently executing?
Are there any other strategies for dealing with this situation?
Suppose I decide to call acknowledgment() on a JMS message several times. Say the first call fails (for non-permanent reason). Does the success of the second (or any subsequent) call guarantee that the message is now acknowledged? Is the exact behavior of acknowledgement() specified anywhere?
I'm using Hibernate3.2+Websphere6.0+struts1.3..
After deploying ,application works fine.
After some idle time ,i will get this type of error repeatedly,am not able to login at all.
Im not using any connection pooling. i feel after idle time its not able to connect to the database again..if i restart the server everything works fine for some time...after that same story.. please help me out
I have a wizard with several screens where user has to fill his/her details for further processing. At the second screen I have a radio group with three radio buttons that enable additional elements. To proceed, user has to choose one of them. When user selects third button, single-selection JTree filled in with data enables and user has to select an option from it. Then user has to press "Next" to get to next screen. The option he\she had selected is stored as a TreePath. So far so good.
My problem is the following. If the user wants to come back from the following screen to the screen with a JTree, I want to provide him\her with the JTree expanded to the option that had been selected and to highlight the option. However, whatsoever I try to do for that (any combinations of expandPath, scrollPathToVisible, addSelectionPath, makeVisible) always provides me with a collapsed tree. I try to expand both leaves and nodes. My code looks like this:
rbProcessJTree.setSelected(isProcessJTree());
if (null != getSelectedTablePath()){
trTables.addSelectionPath(getSelectedTablePath());
trTables.expandPath(getSelectedTablePath());
trTables.scrollPathToVisible(getSelectedTablePath());
}
When setSelected() is called, state change listener is invoked that enables JTree. The model is loaded during the form initialization.
Each time I switch between screens, I save the input data from previous screen and dispose it. Then, when I need to open previous screen back, I save data from the following screen, dispose it, load data to this screen and show it. So each time the screen is generating from scratch.
Could you please explain, what sequence of operations has to be done to get JTree expanded in a newly created form,with data model loaded and selection path provided?
I have tried to write an Android application with an activity that should be launched from a different application. It is not a content provider, just an app with a gui that should not be listed among the installed applications. I have tried the code examples here and it seems to be quite easy to launch existing providers and so on, but I fail to figure out how to just write a "hidden" app and launch it from a different one.
The basic use case is:
App A is a normal apk launchable from the application list.
App B is a different apk with known package and activity names, but is is not visible or launchable from the application list.
App A launches app B using the package and class names (or perhaps a URI constructed from these?).
I fail in the third step. Is it possible to do this?
I'm building an application where space is at a premium. I'd really like to use JAXB's unmarshalling capabilities, but including the whole library is out of the question. Has anyone paired it down so that only the bits needed for unmarshalling are included?
Hi.
For some reason I need to enter my integer values to database as string, then I want to run a query on them and compare those integers as strings. Is there any way to beautify integer numbers (between 1 and 1 US billion as an example) so I can compare them as strings?
Thanks in advance.
I am looking for a way to ensure that my text field (JTextField, JFormattedTextField) is returning a double or int rather than a string when I call .getText(). What is the best way to do this (if possible)?
Thanks!
badPanda :D
I'm working on a Serpinski triangle program that asks the user for the levels of triangles to draw. In the interests of idiot-proofing my program, I put this in:
Scanner input= new Scanner(System.in);
System.out.println(msg);
try {
level= input.nextInt();
} catch (Exception e) {
System.out.print(warning);
//restart main method
}
Is it possible, if the user punches in a letter or symbol, to restart the main method after the exception has been caught?