A wealthy New Jersey shore enclave's attempt to opt out of a protective sand dune plan in an area devastated by Superstorm Sandy was turned down by a judge Wednesday, while a decision to allow a similar project to proceed in another part of the state was upheld by a federal appeals court.