felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r383799 - in /incubator/felix/trunk: ./ org.apache.felix.examples.dictionaryclient/ org.apache.felix.examples.dictionaryclient/src/main/java/org/apache/felix/examples/dictionaryclient/ org.apache.felix.examples.dictionaryclient/src/main/jav...
Date Tue, 07 Mar 2006 06:35:09 GMT
Author: akarasulu
Date: Mon Mar  6 22:35:08 2006
New Revision: 383799

URL: http://svn.apache.org/viewcvs?rev=383799&view=rev
Log:
adding forth example labeled example 3 

Added:
    incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/
      - copied from r383795, incubator/felix/trunk/org.apache.felix.examples.frenchdictionary/
    incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/src/main/java/org/apache/felix/examples/dictionaryclient/
    incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/src/main/java/org/apache/felix/examples/dictionaryclient/Activator.java
Removed:
    incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/src/main/java/org/apache/felix/examples/frenchdictionary/
Modified:
    incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/pom.xml
    incubator/felix/trunk/pom.xml

Modified: incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/pom.xml?rev=383799&r1=383795&r2=383799&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/pom.xml (original)
+++ incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/pom.xml Mon Mar  6 22:35:08
2006
@@ -6,8 +6,8 @@
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <packaging>osgi-bundle</packaging>
-  <name>Apache Felix Examples: French Dictionary Service</name>
-  <artifactId>org.apache.felix.examples.frenchdictionary</artifactId>
+  <name>Apache Felix Examples: Dictionary Client</name>
+  <artifactId>org.apache.felix.examples.dictionaryclient</artifactId>
   <dependencies>
     <dependency>
       <groupId>${pom.groupId}</groupId>
@@ -31,13 +31,13 @@
         <extensions>true</extensions>
         <configuration>
           <osgiManifest>
-            <bundleName>French Dictionary Example</bundleName>
+            <bundleName>Dictionary Client Example</bundleName>
             <bundleVendor>Apache Software Foundation</bundleVendor>
             <bundleDescription>
-              A bundle that registers a French dictionary service.
+              A bundle using the dictionary service if it finds it at startup.
             </bundleDescription>
             <bundleActivator>
-              org.apache.felix.examples.frenchdictionary.Activator
+              org.apache.felix.examples.dictionaryclient.Activator
             </bundleActivator>
             <importPackage>
               org.apache.felix.examples.dictionaryservice

Added: incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/src/main/java/org/apache/felix/examples/dictionaryclient/Activator.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/src/main/java/org/apache/felix/examples/dictionaryclient/Activator.java?rev=383799&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/src/main/java/org/apache/felix/examples/dictionaryclient/Activator.java
(added)
+++ incubator/felix/trunk/org.apache.felix.examples.dictionaryclient/src/main/java/org/apache/felix/examples/dictionaryclient/Activator.java
Mon Mar  6 22:35:08 2006
@@ -0,0 +1,119 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.examples.dictionaryclient;
+
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import org.apache.felix.examples.dictionaryservice.DictionaryService;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+
+/**
+ * This class implements a bundle that uses a dictionary service to check for
+ * the proper spelling of a word by check for its existence in the dictionary.
+ * This bundle uses the first service that it finds and does not monitor the
+ * dynamic availability of the service (i.e., it does not listen for the arrival
+ * or departure of dictionary services). When starting this bundle, the thread
+ * calling the start() method is used to read words from standard input. You can
+ * stop checking words by entering an empty line, but to start checking words
+ * again you must stop and then restart the bundle.
+ * 
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class Activator implements BundleActivator
+{
+    /**
+     * Implements BundleActivator.start(). Queries for all available dictionary
+     * services. If none are found it simply prints a message and returns,
+     * otherwise it reads words from standard input and checks for their
+     * existence from the first dictionary that it finds. (NOTE: It is very bad
+     * practice to use the calling thread to perform a lengthy process like
+     * this; this is only done for the purpose of the tutorial.)
+     * 
+     * @param context the framework context for the bundle.
+     */
+    public void start( BundleContext context ) throws Exception
+    {
+        // Query for all service references matching any language.
+        ServiceReference[] refs = context.getServiceReferences( DictionaryService.class.getName(),
"(Language=*)" );
+
+        if ( refs != null )
+        {
+            try
+            {
+                System.out.println( "Enter a blank line to exit." );
+                BufferedReader in = new BufferedReader( new InputStreamReader( System.in
) );
+                String word = "";
+
+                // Loop endlessly.
+                while ( true )
+                {
+                    // Ask the user to enter a word.
+                    System.out.print( "Enter word: " );
+                    word = in.readLine();
+
+                    // If the user entered a blank line, then
+                    // exit the loop.
+                    if ( word.length() == 0 )
+                    {
+                        break;
+                    }
+
+                    // First, get a dictionary service and then check
+                    // if the word is correct.
+                    DictionaryService dictionary = ( DictionaryService ) context.getService(
refs[0] );
+                    if ( dictionary.checkWord( word ) )
+                    {
+                        System.out.println( "Correct." );
+                    }
+                    else
+                    {
+                        System.out.println( "Incorrect." );
+                    }
+
+                    // Unget the dictionary service.
+                    context.ungetService( refs[0] );
+                }
+            }
+            catch ( IOException ex )
+            {
+            }
+        }
+        else
+        {
+            System.out.println( "Couldn't find any dictionary service..." );
+        }
+    }
+
+
+    /**
+     * Implements BundleActivator.stop(). Does nothing since the framework will
+     * automatically unget any used services.
+     * 
+     * @param context the framework context for the bundle.
+     */
+    public void stop( BundleContext context )
+    {
+        // NOTE: The service is automatically released.
+    }
+}

Modified: incubator/felix/trunk/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/pom.xml?rev=383799&r1=383798&r2=383799&view=diff
==============================================================================
--- incubator/felix/trunk/pom.xml (original)
+++ incubator/felix/trunk/pom.xml Mon Mar  6 22:35:08 2006
@@ -17,6 +17,7 @@
     <module>org.apache.felix.examples.eventlistener</module>
     <module>org.apache.felix.examples.dictionaryservice</module>
     <module>org.apache.felix.examples.frenchdictionary</module>
+    <module>org.apache.felix.examples.dictionaryclient</module>
   </modules>
 
   <repositories>



Mime
View raw message