|
Torsten has given you some excellent suggestions but I would just add this link[^] to help with the design aspects.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I am attempting to generate a compile-time error if a subclass does not define a specific static field with a type subclassed from a defined Class field in the annotation. For example:
import java.lang.annotation.*;
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
@Inherited
public @interface RequiredStaticField {
public String name();
public Class<?> type();
}
@RequiredStaticField(name="StaticField", type=Number.class)
public class MyClass {
private static Integer StaticField;
}
The classes above should validate and compile. However, I am having trouble determining if "Integer" is a subtype of "Number" in my AbstractProcessor implementation...
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.Types;
@SupportedAnnotationTypes("NAMESPACE.RequiredStaticField");
public class RequiredStaticFieldProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment environment) {
Set<? extends Element> elementsWithAnnotation =
environment.getElementsAnnotatedWith(RequiredStaticField.class);
for (Element elementWithAnnotation : elementsWithAnnotation) {
boolean isFound = false;
RequiredStaticMethod annotation = elementWithAnnotation
.getAnnotation(RequiredStaticMethod.class);
for (Element member : elementWithAnnotation.getEnclosedElements()) {
?>
// of member.asType(), or I need to iterate through the superclasses
// of member.asType(), or I need to convert annotation.type()
// to a TypeMirror object. Any Ideas?
isFound = Types.isSubType(member.asType(), annotation.type());
if (isFound) {
break;
} else {
// Display error about declaring with invalid type
}
}
if (!isFound) {
// Display error about missing field
}
}
return true;
}
}
I just can't figure out how to write a test to determine if a TypeMirror object is a subclass of a Class object. Thanks for any help,
Sounds like somebody's got a case of the Mondays
-Jeff
modified 15-Nov-11 20:33pm.
|
|
|
|
|
Figured it out: you can't access an annotation field of type Class<?> at compile-time. Attempting to do so results in a MirroredTypeException. Instead, pass the class in as a string containing the fully-qualified name of the type, and use the following code to get the TypeMirror for that type:
MyAnnotation annotation = elementWithAnnotation.getAnnotation(MyAnnotation.class);
Element typeDeclaration = processingEnv.getElementUtils().getTypeElement(annotation.type());
if (typeDeclaration == null) {
} else {
} Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I need to transfer file between client and server by using tcp socket as this code :
1- sender side ( server ):
spackage sender;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.util.Scanner;
public class Sender
{
private static ServerSocket serverSocket;
public static void main(String[] args)
{
System.out.println("Opening port...\n");
try
{
serverSocket = new ServerSocket(3000);
}
catch(IOException ioEx)
{
System.out.println("Unable to attach to port!");
System.exit(1);
}
try
{
Socket link = serverSocket.accept();
ObjectOutputStream outStream = new ObjectOutputStream(link.getOutputStream());
FileInputStream fileIn = new FileInputStream("image.GIF");
long fileLen = (new File("image.GIF")).length();
int intFileLen = (int)fileLen;
byte[] byteArray = new byte[intFileLen];
fileIn.read(byteArray);
fileIn.close();
outStream.writeObject(byteArray);
}
catch(IOException e)
{
System.out.println("error...");
}
}
}
2- receiver side (Client):
package reciever;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Reciever
{
public static void main(String[] args) throws Exception
{
try
{
Socket link = new Socket("localhost",3000);
ObjectInputStream inStream = new ObjectInputStream(link.getInputStream());
byte[] byteArray = (byte[])inStream.readObject();
FileOutputStream outStream = new FileOutputStream("image.GIF");
outStream.write(byteArray);
link.close();
}
catch(IOException e)
{
System.out.println("error...");
}
}
}
and the image.GIF file found at the sender side but this code make error , I need solution for this problem as soon as , please .
|
|
|
|
|
lolostar wrote: I need solution for this problem as soon as
some suggestions:
1. start sooner
2. don't throw away the information exceptions are offering
3. explain what the problem is (use case, symptoms, ...)
|
|
|
|
|
It's time to play Guess The Problem.
Is it:
A - my code doesn't compile
B - it throws an exception at runtime
C - nothing happens when I run it
D - it triggers global thermonuclear war and the start of a new ice age
Press the button on your handset now, and let's see what the studio audience thinks...
|
|
|
|
|
Sir! Sir! Pick me Sir!
Is it global thermonuclear war?
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
the problem appear when the receiver receive file from the sender .
|
|
|
|
|
yes
|
|
|
|
|
But why is it still a secret?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
[mode=igor]
Shall I fire up the labotomy drill marther?
[/mode]
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
I think the salient information is that the programs build and run, but an error occurs. Is this correct?
If yes, then WHAT IS THE EXCEPTION?
Going by your garbled post, you think the file image.gif exists, but it can't be loaded by the sender. Correct?
What folder is the file in? Where is sender.jar in relation to it?
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
yes , the program is running but the error occur at the receiver side because the exception occurred when the receiver try to receive the transmitted file from the sender .
the image.gif found in the sender package and because the transmitted process complete successfully so I don't think the problem in the image file .
|
|
|
|
|
Here is a very basic suggestion which should help you. I would not recommend this in a real production application, but for your situation I think you may find it helpful.
Replace this section of code:
catch(IOException e)
{
System.out.println("error...");
}
with this:
catch (IOException e)
{
e.printStackTrace();
}
This will give you more information which will hopefully give you an idea of what is going wrong.
|
|
|
|
|
I may be wrong in the analysis of the problem but on the server code you are creating 2 handles of files simultaneously without closing one. Wont this be a problem.
|
|
|
|
|
Well, I'm working on an application that works as a server for a Ship Management System. And my boss had an idea to limit client number based on license. After brief discussion we agreed to with a licensing system where we distribute a license file that must be put in app dir that contain a definition regarding how many clients are allowed.
Now regarding that file, I'm thinking of creating a class that contains the info then serialize it. and distribute that file to client and read the file from my application. My questions are, what encryption should I use? Are there any better solution?
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
use dongles. Dongles @ Wikipedia[^]
With dongles you can control who uses the Software and how much copies are used.
The dongle should be handled as a chip card, a USB-Dongle opens a gate to get viruses and all kinds of other stuff onto the ship.
Also think of obfuscation -> encryption of the code.
regards Torsten
I never finish anyth...
|
|
|
|
|
Thanks for the info on Dongle, it's a nice read (though I highly doubt my boss would agree with this one).
TorstenH. wrote: Also think of obfuscation -> encryption of the code.
Sup, will do.
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
Create a hash of the relevant license data, encrypt it on your computer with your private key, and add that to the license file.
The application shipped to the customer contains the public key. The application reads the license file, creates the hash as you did on your local computer, decrypts the stored encrypted hash value and compares it with its computed hash value. If it's ok, the license file is ok, otherwise the application would refuse to run.
I.e. you use an encryption method with a public and a private key.
|
|
|
|
|
Ah, Thanks for the heads up.
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
I want to print restaurant bill directly to printer when user click button "Print Bill" without display content is printed. My project is JSP/Servlet web appplication.So, solution can write in java or javascript. Can you help me ? Thanks so much.
Sorry, I don't know post this question in which topic Java or Web development.
|
|
|
|
|
|
I'm writing copy to clipboard and paste from clipboard in jlist by myself .
I don't know why I can't use 'ctrl C' key to do it in jlist . With other key is ok (For example : 'ctrl M'... .
I know jlist support DnD .
AnyIdea ?
Thanks !!
|
|
|
|
|
|
Hello All,
I'm trying to validate two input text boxes and am running into a snag. I'm using a while loop that runs while either one of the inputs is 'false'. The problem is that it doesn't stop and allow for a user to correct the first input if its bad and goes on to check the next input.
I could do this before when I just checked one input at time and called the validate method twice. Trying to do both in one method is proving to be a pain. Any ideas?
Here's my validate method:
private boolean validateInput(String input1, String input2)
{
Boolean[] inputValidArray = {false , false};
String[] inputArray = {input1, input2};
JTextField[] textFieldArray = {jTextField1, jTextField2};
float numberToValidate = 0;
int counter = 0;
String errorMessage = "";
while (!inputValidArray[0] || !inputValidArray[1])
{
try
{
if (!(inputArray[counter].isEmpty() || inputArray[counter] == null))
{
numberToValidate = Float.valueOf(inputArray[counter]);
inputValidArray[counter] = true;
}
else
{
errorMessage = "This field can not be left blank!\n" +
" Please enter a valid number!\n" +
" (example: 123.45 or -123.45)";
Create_Error_Message_Dialog_Box(errorMessage);
textFieldArray[counter].requestFocusInWindow();
}
}
catch (NumberFormatException nfe)
{
errorMessage = inputArray[counter] + " is not a valid number!\n" +
"Please enter a valid number!\n" +
"(example: 123.45 or -123.45)";
Create_Error_Message_Dialog_Box(errorMessage);
textFieldArray[counter].requestFocusInWindow();
textFieldArray[counter].selectAll();
}
counter += 1;
}
return (inputValidArray[0] && inputValidArray[1]);
}
modified 6-Nov-11 7:08am.
|
|
|
|