What Signet said.
Also, if you ware using the Command Based structure with Java you can set the limit switch up to act as a button to fire a command.
Code:
final DigitalInput limitSwitch = new DigitalInput(1);
Button limitSwitchButton = new Button() {
public boolean get() {
return limitSwitch.get();
}
};
limitSwitchButton.whenPressed(new SomethingCommand());