PageRenderTime 35ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/src/example/xml/Main.java

https://gitlab.com/metamorphiccode/guice
Java | 48 lines | 22 code | 7 blank | 19 comment | 3 complexity | e0945bbb53ac47d34694ef3928cecff6 MD5 | raw file
  1. /**
  2. * Copyright (C) 2007 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package example.xml;
  17. import com.google.inject.Guice;
  18. import com.google.inject.AbstractModule;
  19. import com.google.inject.Injector;
  20. import java.net.URL;
  21. /**
  22. *
  23. *
  24. */
  25. public class Main {
  26. public static void main(String[] args) {
  27. final URL xmlUrl = Main.class.getResource("phone.xml");
  28. Injector injector = Guice.createInjector(new AbstractModule() {
  29. protected void configure() {
  30. bind(Contacts.class).to(SimCard.class);
  31. install(new XmlBeanModule(xmlUrl));
  32. }
  33. });
  34. Phone phone = injector.getInstance(Phone.class);
  35. if (phone.getContacts() == null) {
  36. throw new AssertionError();
  37. } else {
  38. System.out.println("It worked!");
  39. }
  40. }
  41. }