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 '
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();
}
}
}
I have a JUnit 4 test suite with BeforeClass and AfterClass methods that make a setup/teardown for the following test classes.
What I need is to run the test classes also by them selves, but for that I need a setup/teardown scenario (BeforeClass and AfterClass or something like that) for each test class. The thing is that when I run the suite I do not want to execute the setup/teardown before and after each test class, I only want to execute the setup/teardown from the test suite (once).
Is it possible ? Thanks in advance.
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 have a listener class that accepts GUI change events in one method.
The incoming event objects have a superclass of a type of GUI Event, the behaviour should depend on the dynamic type of the incoming variable.
I wanted to do do lots of methods like:
handleGUIEvent(EventChangedX event)
handleGUIEvent(EventChangedY event)
I am using a single event listener and receiving objects of various types but the behaviour should be different for each. What would you do?
I do not want to use a switch statement as this would get unmaintainable.
Hi,
I have the following code to display
<display:table name="sessionScope.userList" id="userList" export="false" pagesize="1">
<display:column title="Select" style="width: 90px;">
<input type="checkbox" name="optionSelected" value=""/>
</display:column>
<display:column property="userName" sortable="false" title="UserName" paramId="userName" style="width: 150px; text-align:center" href="#"/>
</display:table>
On click of the checkbox i need to get the corresponding row value that is the username how would i get that?
I'm currenty developing for blackberry and just bumped into this problem as i was trying to download an image from a server. The servlet which the device communicates with is working correctly, as I have made a number of tests for it. But it gives me the
413 HTTP error ("Request entity too large").
I figure i will just get the bytes, uhm, portion by portion. How can i accomplish this?
This is the code of the servlet (the doGet() method):
try {
ImageIcon imageIcon = new ImageIcon("c:\\Users\\dcalderon\\prueba.png");
Image image = imageIcon.getImage();
PngEncoder pngEncoder = new PngEncoder(image, true);
output.write(pngEncoder.pngEncode());
} finally {
output.close();
}
Thanks. It's worth mentioning that I am developing both the client-side and the server-side.
On my page, there are 2 links with the same anchor text.
I am using HtmlUnit to get the link by the anchor text.
The call to:
page.getAnchorByText("1");
Seems to always get the first occurrance, is there a way to get the 2nd occurance if there are 2 links?
We have an application which communicates via REST requests made by clients.
The REST requests contain "region name" and a "ID" as parameters
So, a request would look something like this (for a DELETE)
http://host:port/regionnameID
These REST requests between regions in a federation are properly URL encoded
I find that these request fail if the region name has a slash ("/") in it.
Then, the request would look like so
http://host:port/region/nameID
This is due to incorrect interpretation of the Rest URL by HttpRequesthandler when there is a '/' in the region name.
Now, we have no control over clients sending REST request with "/" in the Region name.
Is there any method / configuration / workaround that can be done to prevent the HttpRequestHandler from returning 404
I'm trying to crop a photo to use in a Live Wallpaper but I'm getting a FileNotFoundException when the crop activity tries to save my new cropped image. This is the code I'm using:
File file = new File(getFilesDir(), "wallpaper.jpg");
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setData(uri);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
intent.putExtra("outputX", metrics.widthPixels * 2);
intent.putExtra("outputY", metrics.heightPixels);
intent.putExtra("aspectX", metrics.widthPixels * 2);
intent.putExtra("aspectY", metrics.heightPixels);
intent.putExtra("scale", true);
intent.putExtra("noFaceDetection", true);
intent.putExtra("output", Uri.parse("file:/" + file.getAbsolutePath()));
startActivityForResult(intent, REQUEST_CROP_IMAGE);
The wallpaper.jpg file seems to exist on DDMS file explorer so I'm not sure what I'm doing wrong. Any advice is greatly appreciated.
Using JPA 2.0. It seems that by default (no explicit fetch), @OneToOne(fetch = FetchType.EAGER) fields are fetched in 1 + N queries, where N is the number of results containing an Entity that defines the relationship to a distinct related entity. Using the Criteria API, I might try to avoid that as follows:
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<MyEntity> query = builder.createQuery(MyEntity.class);
Root<MyEntity> root = query.from(MyEntity.class);
Join<MyEntity, RelatedEntity> join = root.join("relatedEntity");
root.fetch("relatedEntity");
query.select(root).where(builder.equals(join.get("id"), 3));
The above should ideally be equivalent to the following:
SELECT m FROM MyEntity m JOIN FETCH myEntity.relatedEntity r WHERE r.id = 3
However, the criteria query results in the root table needlessly being joined to the related entity table twice; once for the fetch, and once for the where predicate. The resulting SQL looks something like this:
SELECT myentity.id, myentity.attribute, relatedentity2.id, relatedentity2.attribute
FROM my_entity myentity
INNER JOIN related_entity relatedentity1 ON myentity.related_id = relatedentity1.id
INNER JOIN related_entity relatedentity2 ON myentity.related_id = relatedentity2.id
WHERE relatedentity1.id = 3
Alas, if I only do the fetch, then I don't have an expression to use in the where clause.
Am I missing something, or is this a limitation of the Criteria API? If it's the latter, is this being remedied in JPA 2.1 or are there any vendor-specific enhancements?
Otherwise, it seems better to just give up compile-time type checking (I realize my example doesn't use the metamodel) and use dynamic JPQL TypedQueries.
What is the difference between this method declaration:
public static <E extends Number> List<E> process(List<E> nums){
and
public static List<Number> process(List<Number> nums){
Where would you use the former?
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 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.
I want to learn how to create distributed application environments and web services using spring, aspectj, hibernate, etc. rather than EJBs.
Can anyone recommend a book or set of books that can help me (a single all-in-one book would be preferable)?
Also, any advice regarding learning/creating distributed app environments and web services is appreciated.
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 am writting a customized component which need to use the little triangle icon of sortable JTable header. Maybe it's not really a icon file but a graphics painted by some class.
I build all my web projects at work using RAD/Eclipse, and I'm interested to know where do you guys normally store your test's *.class files.
All my web projects have 2 source folders: "src" for source and "test" for testcases. The generated *.class files for both source folders are currently placed under WebContent/WEB-INF/classes folder.
I want to separate the test *.class files from the src *.class files for 2 reasons:-
There's no point to store them in WebContent/WEB-INF/classes and deploy them in production.
Sonar and some other static code analysis tools don't produce an accurate static code analysis because it takes account of my crappy yet correct testcase code.
So, right now, I have the following output folders:-
"src" source folder compiles to WebContent/WEB-INF/classes folder.
"test" source folder compiles to target/test-classes folder.
Now, I'm getting this warning from RAD:-
Broken single-root rule: A project may not contain more than one output folder.
So, it seems like Eclipse-based IDEs prefer one project = one output folder, yet it provides an option for me to set up a custom output folder for my additional source folder from the "build path" dialog, and then it barks at me.
I know I can just disable this warning myself, but I want to know how you guys handle this.
Thanks.
I am having a form built up in netbeans and want to add or remove a component with an actionperformed event of a button or a combobox is it possible?
if yes, how?
If I am making a proxy factory, can I just make the outgoing request saying Proxy::HTTP (there's a similar enum for SOCKS) and the SOCKS5 proxy server should automatically detect and handle that correctly, right?
i would need to know the past 7 days record. i want to wrote a query for that in where condition. i have very basic knowledge in sqlite. Please help me for this query.
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've got a Class that uses reflection a lot, so I wrote a method to help out:
private <T> T callMethod(String methodName, Class[] parameterTypes, Object[] args) {
try {
Class c = mVar.getClass();
Method m = c.getMethod(methodName, (Class[]) parameterTypes);
return (T) m.invoke(mVar, args);
}
// Insert exception catching here [...]
}
This worked well for any method that had parameters, however I had to explicitly cast parameterTypes to Class[] in order for this to work for methods with no parameters (e.g., callMethod('funName', null, null);). I've been trying to figure out why this is the case.
It seems to me that if parameterTypes, when null, had no concept of what type it is (Class[]), then I'd need to cast it for getMethod(). But if that's the case, why is getMethod() able to tell the difference between null, and (Class[]) null when the method is invoked?
Basically I'm trying to make a little app for watching offline content. So there's a moment where the user selects to download the contents (and the app should download about 300 small files and images).
I'd like to show the user how does the process go if he enters the proper activity. Showing a list of all the files, telling what has been already downloaded, in progress or waiting for download.
My problem is that I really don't know what approach to take for achieve this. Since the download should last until finished I imagine the solution is an Service, but whats best? an IntentService, a Bound Service or an Standard Service calling a startService() for each download? And how can I keep my objects updated for displaying them later? should I use a database or objects in memory?
Thanks