diff options
Diffstat (limited to '')
-rw-r--r-- | sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java | 73 | ||||
-rw-r--r-- | sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/resources/countries.txt (renamed from sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/countries.txt) | 0 | ||||
-rw-r--r-- | sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite | 2 |
3 files changed, 38 insertions, 37 deletions
diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java b/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java index 736f919a12..65ac77723e 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java @@ -20,8 +20,8 @@ package org.apache.tuscany.sca.sample.comet; import java.io.BufferedReader; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; @@ -39,44 +39,45 @@ import org.oasisopen.sca.annotation.Service; @Service(CountryRepository.class) public class CountryRepositoryImpl implements CountryRepository { - @Context - protected ComponentContext context; + @Context + protected ComponentContext context; - private String fileName; - private List<Country> countries; + private String fileName; + private List<Country> countries; - @Constructor - public CountryRepositoryImpl(@Property(name = "fileName") String fileName) { - this.fileName = fileName; - countries = new ArrayList<Country>(); - } + @Constructor + public CountryRepositoryImpl(@Property(name = "fileName") String fileName) { + this.fileName = fileName; + countries = new ArrayList<Country>(); + } - @Init - public void start() { - try { - BufferedReader reader = new BufferedReader(new FileReader(fileName)); - String line; - while ((line = reader.readLine()) != null) { - Country c = new Country(); - c.setName(line); - countries.add(c); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Init + public void start() { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader() + .getResourceAsStream(fileName))); + String line; + while ((line = reader.readLine()) != null) { + Country c = new Country(); + c.setName(line); + countries.add(c); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } - @Override - public List<Country> getStartingWith(String text) { - List<Country> result = new ArrayList<Country>(); - for (Country c : countries) { - if (c.getName().toLowerCase().startsWith(text.toLowerCase())) { - result.add(c); - } - } - return result; - } + @Override + public List<Country> getStartingWith(String text) { + List<Country> result = new ArrayList<Country>(); + for (Country c : countries) { + if (c.getName().toLowerCase().startsWith(text.toLowerCase())) { + result.add(c); + } + } + return result; + } } diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/countries.txt b/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/resources/countries.txt index 271bbd5dd1..271bbd5dd1 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/countries.txt +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/resources/countries.txt diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite b/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite index e065902cb0..f7cee35452 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite @@ -35,7 +35,7 @@ <component name="CountryRepositoryComponent"> <implementation.java class="org.apache.tuscany.sca.sample.comet.CountryRepositoryImpl" /> - <property name="fileName">/home/fmoga/coding/apache-tuscany/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/countries.txt</property> + <property name="fileName">countries.txt</property> </component> </composite>
\ No newline at end of file |