incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject svn commit: r899972 [2/2] - in /incubator/aries/trunk/samples: ./ blueprint-sample-idverifier/ blueprint-sample-idverifier/blueprint-sample-idverifier-api/ blueprint-sample-idverifier/blueprint-sample-idverifier-api/src/ blueprint-sample-idverifier/blu...
Date Sat, 16 Jan 2010 15:20:48 GMT
Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/java/org/apache/aries/samples/blueprint/idverifier/client/RandomIDChoice.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/java/org/apache/aries/samples/blueprint/idverifier/client/RandomIDChoice.java?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/java/org/apache/aries/samples/blueprint/idverifier/client/RandomIDChoice.java
(added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/java/org/apache/aries/samples/blueprint/idverifier/client/RandomIDChoice.java
Sat Jan 16 15:20:44 2010
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.aries.samples.blueprint.idverifier.client;
+
+import java.util.Random;
+
+/**
+ * @author forrestxm
+ *
+ */
+public class RandomIDChoice {
+	private static String[] idarray = {
+		"310115197011076874",
+		"310115197011277844",
+		"110108197710016853",
+		"11010819541001366X"
+	};
+	
+	public RandomIDChoice(){
+		super();
+	}
+	
+	public String getRandomID(){
+		Random randomintgenerator = new Random();
+		int randomint = randomintgenerator.nextInt(1000);
+		int remain = randomint % idarray.length;
+		if (remain < 0 || remain > idarray.length - 1) {
+			remain = randomintgenerator.nextInt(1000) % idarray.length;
+		}
+		return idarray[remain];
+	}
+
+}

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/java/org/apache/aries/samples/blueprint/idverifier/client/VerifierServiceReferenceListener.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/java/org/apache/aries/samples/blueprint/idverifier/client/VerifierServiceReferenceListener.java?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/java/org/apache/aries/samples/blueprint/idverifier/client/VerifierServiceReferenceListener.java
(added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/java/org/apache/aries/samples/blueprint/idverifier/client/VerifierServiceReferenceListener.java
Sat Jan 16 15:20:44 2010
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.aries.samples.blueprint.idverifier.client;
+
+import java.util.Map;
+import java.util.Set;
+
+
+import org.apache.aries.samples.blueprint.idverifier.api.PersonIDVerifier;
+import org.apache.aries.samples.blueprint.idverifier.server.PersonIDVerifierSimpleImpl;
+import org.apache.aries.samples.blueprint.idverifier.server.PersonIDVerifierComplexImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @author forrestxm
+ *
+ */
+public class VerifierServiceReferenceListener {
+	public void bind(ServiceReference svcref) {
+		System.out.println("**********" + this.getClass().getSimpleName() + " bind method via ServiceReference!*********");
+		// Get specific PersonIDVerifier implementation class
+		Bundle svcproviderbundle = svcref.getBundle();
+		BundleContext svcproviderbundlectx = svcproviderbundle.getBundleContext();
+		Object svcbean = svcproviderbundlectx.getService(svcref);
+		String svcbeanname = null;
+		if (svcbean instanceof PersonIDVerifierSimpleImpl) {
+			svcbeanname = ((PersonIDVerifierSimpleImpl)svcbean).getClass().getCanonicalName();
+		} else if (svcbean instanceof PersonIDVerifierComplexImpl){
+			svcbeanname = ((PersonIDVerifierComplexImpl)svcbean).getClass().getCanonicalName();
+		}
+		System.out.println("Bundle " + svcproviderbundle.getSymbolicName() + " provides this service
implemented by " + svcbeanname);
+		// Print service users information
+		System.out.println("**********Start of printing service's users**********");
+		Bundle[] usingbundles = svcref.getUsingBundles();
+		if (usingbundles != null) {
+			int len = usingbundles.length;
+			System.out.println("The service has " + len + " users!");
+			System.out.println("They are:");
+			for (int i = 0; i < len; i++) {
+				System.out.println(usingbundles[i].getSymbolicName());
+			}
+			System.out.println("All users are printed out!");
+		}
+		System.out.println("**********End of printing service's users**********");
+		
+	}
+
+	public void bind(PersonIDVerifier svc) {
+		System.out.println("**********This is service object proxy bind method!***********");
+	}
+	
+	public void unbind(ServiceReference svcref) {
+		System.out.println("**********" + this.getClass().getSimpleName() + " unbind method via
ServiceReference!*********");
+		// Get specific PersonIDVerifier implementation class
+		Bundle svcproviderbundle = svcref.getBundle();
+		BundleContext svcproviderbundlectx = svcproviderbundle.getBundleContext();
+		Object svcbean = svcproviderbundlectx.getService(svcref);
+		String svcbeanname = null;
+		if (svcbean instanceof PersonIDVerifierSimpleImpl) {
+			svcbeanname = ((PersonIDVerifierSimpleImpl)svcbean).getClass().getCanonicalName();
+		} else if (svcbean instanceof PersonIDVerifierComplexImpl){
+			svcbeanname = ((PersonIDVerifierComplexImpl)svcbean).getClass().getCanonicalName();
+		}
+		System.out.println("Bundle " + svcproviderbundle.getSymbolicName() + " provides this service
implemented by " + svcbeanname);
+		// Print service users information
+		System.out.println("**********Start of printing service's users**********");
+		Bundle[] usingbundles = svcref.getUsingBundles();
+		if (usingbundles != null) {
+			int len = usingbundles.length;
+			System.out.println("The service has " + len + " users!");
+			System.out.println("They are:");
+			for (int i = 0; i < len; i++) {
+				System.out.println(usingbundles[i].getSymbolicName());
+			}
+			System.out.println("All users are printed out!");
+		}
+		System.out.println("**********End of printing service's users**********");
+		
+	}
+
+	public void unbind(PersonIDVerifier svc, Map props) {
+		System.out.println("**********This is service object proxy unbind method!***********");
+		System.out.println("**********Start of printing service properties***********");
+		System.out.println("Service properties are:");
+		Set keys = props.keySet();
+		for (Object obj : keys) {
+			Object valueobj = props.get(obj);
+			System.out.println(obj + "=" + valueobj);
+		}
+		System.out.println("**********End of printing service properties***********");
+	}
+
+}

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-client.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-client.xml?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-client.xml
(added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-client/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-client.xml
Sat Jan 16 15:20:44 2010
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+	<!--
+		Licensed to the Apache Software Foundation (ASF) under one or more
+		contributor license agreements. See the NOTICE file distributed with
+		this work for additional information regarding copyright ownership.
+		The ASF licenses this file to You 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.
+	-->
+<blueprint default-activation="eager" default-availability="optional"
+	default-timeout="300000" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+	<description>Apache Aries Blueprint Sample - ID Verifier Client</description>
+	<type-converters>
+		<bean activation="eager"
+			class="org.apache.aries.samples.blueprint.idverifier.client.IDConverter"
+			id="idconverterbean" scope="singleton">
+			<description>ID Converter Bean</description>
+			<property name="verifier" ref="verifierservicereference" />
+		</bean>
+	</type-converters>
+
+	<reference id="verifierservicereference"
+		interface="org.apache.aries.samples.blueprint.idverifier.api.PersonIDVerifier"
+		availability="mandatory">
+		<reference-listener bind-method="bind" unbind-method="unbind">
+              	<bean class="org.apache.aries.samples.blueprint.idverifier.client.VerifierServiceReferenceListener"/>
+        </reference-listener>
+	</reference>	
+
+	<bean id="personbankbean"
+		class="org.apache.aries.samples.blueprint.idverifier.client.PersonBankBean"
+		scope="singleton" activation="eager" init-method="startUp">
+		<description>Personal Bank Bean</description>
+		
+		<!--<argument value="11010819541001366X" />-->
+		<argument index="0">
+			<bean class="org.apache.aries.samples.blueprint.idverifier.client.RandomIDChoice"></bean>
+		</argument>
+		
+		<property name="bankinfobeanid">
+			<idref component-id="bankinfo" />
+		</property>
+
+		<property name="svcreg4cro">
+			<service auto-export="disabled"
+				ranking="100">
+				<description>Inlined service about querying credit records.</description>
+				<interfaces>
+					<value>org.apache.aries.samples.blueprint.idverifier.api.CreditRecordOperation</value>
+				</interfaces>
+				<service-properties>
+					<entry key="mode" value="formal">						
+					</entry>
+				</service-properties>
+				<registration-listener 
+					registration-method="reg" unregistration-method="unreg">
+					<bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditQueryRegistrationListener">
+						<description>Inlined service registration bean</description>						
+					</bean>
+				</registration-listener>
+				<bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecordOperationImpl">
+					<description>Inlined bean for CreditRecordOperation interface implementation</description>
+					<argument index="0">
+						<description>inlined bean for CreditRecordStore</description>
+						<bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecordStore">
+							<argument index="0">
+								<set>
+									<bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecordFactory"
+										factory-method="staticCreateBean">
+										<argument>
+											<value>310115197011076874:003:2009-12-30:good:4rd donation to charity.</value>
+										</argument>
+									</bean>
+									<bean factory-ref="creditrecordfactory"	factory-method="dynamicCreateBean">
+              							<argument>
+											<value>310115197011076874:004:2009-12-18:good:3rd donation to charity.</value>
+										</argument>
+        							</bean>
+									<bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">
+										<argument>
+											<value>310115197011277844:001:2009-12-29:good:Donation to charity</value>
+										</argument>
+									</bean>
+									<bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">
+										<argument>
+											<value>310115197011277844:002:2009-12-01:bad:No pay to bill.</value>
+										</argument>
+									</bean>
+									<bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">
+										<argument>
+											<value>110108197710016853:002:2009-12-02:good:Paied the bill.</value>
+										</argument>
+									</bean>
+									<bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">
+										<argument>
+											<value>110108197710016853:001:1977-10-01:good:I'm born.</value>
+										</argument>
+									</bean>
+									<bean class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecord">
+										<argument>
+											<value>11010819541001366X:001:1954-10-01:good:I'm born.</value>
+										</argument>
+									</bean>
+								</set>
+							</argument>
+						</bean>
+					</argument>
+				</bean>
+			</service>
+		</property>
+		<property name="bpcontainer" ref="blueprintContainer"/>
+		<property name="bpbundlecontext" ref="blueprintBundleContext"/>
+	</bean>
+
+	<bean id="bankinfo"
+		class="org.apache.aries.samples.blueprint.idverifier.client.BankInfo">
+		<property name="bankname" value="Bank of China" />
+		<property name="bankaddress">
+			<value type="java.lang.String">333, Huai Hai Zhong Road, Lu Wan District, Shanghai,
China</value>
+		</property>
+		<property name="banklegalpersonname" value="Wang San"></property>
+		<property name="bankregistrationnumber" value="1000000000012345"></property>
+	</bean>
+	
+	<bean id="creditrecordfactory" class="org.apache.aries.samples.blueprint.idverifier.client.CreditRecordFactory"

+		destroy-method="creationStatistics">
+		<argument value="CreditRecord"/>
+	</bean>
+
+</blueprint>

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/pom.xml?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/pom.xml
(added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/pom.xml
Sat Jan 16 15:20:44 2010
@@ -0,0 +1,65 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.aries.samples</groupId>
+    	<artifactId>blueprint-sample-idverifier</artifactId>
+    	<version>1.0.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>org.apache.aries.samples.blueprint.idverifier.server</artifactId>
+    <name>Apache Aries Blueprint Sample - ID Verifier Server</name>
+    <packaging>bundle</packaging>
+    <description>
+         Example blueprint application to demo inlined managers definitions.
+    </description>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                       
+<!--
+                        <Bundle-Blueprint>/test.xml</Bundle-Blueprint>
+-->
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.eclipse</groupId>
+            <artifactId>osgi</artifactId>
+            <scope>provided</scope>
+        </dependency>
+       <dependency>
+           <groupId>org.apache.aries.blueprint</groupId>
+           <artifactId>org.apache.aries.blueprint.api</artifactId>
+       </dependency>
+       <dependency>
+            <groupId>org.apache.aries.samples</groupId>
+            <artifactId>org.apache.aries.samples.blueprint.idverifier.api</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
+    </dependencies>
+</project>

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/ComplexVerifierRegistrationListener.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/ComplexVerifierRegistrationListener.java?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/ComplexVerifierRegistrationListener.java
(added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/ComplexVerifierRegistrationListener.java
Sat Jan 16 15:20:44 2010
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.aries.samples.blueprint.idverifier.server;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author forrestxm
+ *
+ */
+public class ComplexVerifierRegistrationListener {
+	
+	public void reg(PersonIDVerifierComplexImpl svcobject, Map props){
+		//svcobject.doAfterReg();
+		System.out.println("********Registered bean "+svcobject.getClass().getName()+" as a service**********");
+		System.out.println("********Print service properties**************");
+		Set keyset = props.keySet();
+		Iterator iter = keyset.iterator();
+		while(iter.hasNext()){
+			Object keyobj = iter.next();
+			Object valueobj = props.get(keyobj);
+			System.out.println(keyobj + "=" + valueobj);			
+		}
+		
+	}
+	public void unreg(PersonIDVerifierComplexImpl svcobject, Map props){
+		System.out.println("********Unregistering service bean "+svcobject.getClass().getName()+"**********");
+	}
+
+}

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/PersonIDVerifierComplexImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/PersonIDVerifierComplexImpl.java?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/PersonIDVerifierComplexImpl.java
(added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/PersonIDVerifierComplexImpl.java
Sat Jan 16 15:20:44 2010
@@ -0,0 +1,151 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.aries.samples.blueprint.idverifier.server;
+
+/**
+ * @author forrestxm
+ *
+ */
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.aries.samples.blueprint.idverifier.api.PersonIDVerifier;
+
+public class PersonIDVerifierComplexImpl extends PersonIDVerifierSimpleImpl
+		implements PersonIDVerifier {
+	private String datepattern;
+	private Map<String, String> definedAreacode;
+	private int[] coefficient;
+
+	@Override
+	public boolean verify() {
+		boolean b = false;
+		b = super.isValidID() && super.isValidSuffix()
+				&& this.isValidBirth() && this.isValidArea()
+				&& this.isValidCheckCode();
+		return b;
+	}
+	
+	@Override
+	boolean isValidBirth(){		
+		String birthdate = toDateFormat(getBirthcode(), "-");
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+		try {
+			Date birthday = sdf.parse(birthdate);
+			SimpleDateFormat sdf_usecustom = new SimpleDateFormat(datepattern);
+			this.setBirth_str(sdf_usecustom.format(birthday));
+			return true;
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		return false;		
+	}
+
+	@Override
+	boolean isValidArea() {
+		boolean b = false;
+		if (super.isValidArea()	&& definedAreacode.containsValue(getAreacode())) {
+			b = true;
+			Set<String> keys = definedAreacode.keySet();			
+			for (String key:keys){
+				String value = definedAreacode.get(key);
+				if (value.equals(getAreacode())){
+					super.setArea_str(key);
+					break;
+				}
+			}			
+		}
+		return b;
+	}
+
+	public boolean isValidCheckCode() {
+		boolean b = false;
+		
+		int[] codes = this.Char2Number(id.substring(0, 17));
+		String[] validcheckcodes = { "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2" };
+		int sum = 0;
+		for (int i = 0; i < 17; i++) {
+			sum = sum + codes[i] * coefficient[i];
+		}
+
+		int remain = sum % 11;
+		String checkcode = id.substring(17);		
+		
+		b = validcheckcodes[remain].equals(checkcode);
+		return b;
+	}
+
+	private int[] Char2Number(String id) {
+		int[] numbers = new int[17];
+		for (int i = 0; i < 17; i++) {
+			numbers[i] = Integer.parseInt(new Character(id.charAt(i)).toString());
+		}
+		return numbers;
+	}
+
+	/**
+	 * @return the datepattern
+	 */
+	public String getDatepattern() {
+		return datepattern;
+	}
+
+	/**
+	 * @param datepattern
+	 *            the datepattern to set
+	 */
+	public void setDatepattern(String datepattern) {
+		this.datepattern = datepattern;
+	}	
+
+	/**
+	 * @return the definedAreacode
+	 */
+	public Map<String, String> getDefinedAreacode() {
+		return definedAreacode;
+	}
+
+	/**
+	 * @param definedAreacode
+	 *            the definedAreacode to set
+	 */
+	public void setDefinedAreacode(Map<String, String> definedAreacode) {
+		this.definedAreacode = definedAreacode;
+	}
+
+	/**
+	 * @return the coefficient
+	 */
+	public int[] getCoefficient() {
+		return coefficient;
+	}
+
+	/**
+	 * @param coefficient
+	 *            the coefficient to set
+	 */
+	public void setCoefficient(int[] coefficient) {
+		this.coefficient = coefficient;
+	}
+
+}

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/PersonIDVerifierSimpleImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/PersonIDVerifierSimpleImpl.java?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/PersonIDVerifierSimpleImpl.java
(added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/PersonIDVerifierSimpleImpl.java
Sat Jan 16 15:20:44 2010
@@ -0,0 +1,229 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+/**
+ * @author forrestxm
+ *
+ */
+package org.apache.aries.samples.blueprint.idverifier.server;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.aries.samples.blueprint.idverifier.api.PersonIDVerifier;
+
+public class PersonIDVerifierSimpleImpl implements PersonIDVerifier {
+	String areacode;
+	String birthcode;
+	String suffixcode;
+	
+	String id;
+	
+	String area_str;
+	String birth_str;
+	String gender_str;
+	
+	static final String GENDER_MAN = "man";
+	static final String GENDER_WOMAN = "woman";
+	
+	/**
+	 * @return the area_str
+	 */
+	public String getArea_str() {
+		return area_str;
+	}
+
+	/**
+	 * @param areaStr the area_str to set
+	 */
+	public void setArea_str(String areaStr) {
+		area_str = areaStr;
+	}
+
+	/**
+	 * @return the birth_str
+	 */
+	public String getBirth_str() {
+		return birth_str;
+	}
+
+	/**
+	 * @param birthStr the birth_str to set
+	 */
+	public void setBirth_str(String birthStr) {
+		birth_str = birthStr;
+	}
+
+	/**
+	 * @return the gender_str
+	 */
+	public String getGender_str() {
+		return gender_str;
+	}
+
+	/**
+	 * @param genderStr the gender_str to set
+	 */
+	public void setGender_str(String genderStr) {
+		gender_str = genderStr;
+	}
+
+	/**
+	 * @return the areacode
+	 */
+	public String getAreacode() {
+		return areacode;
+	}
+
+	/**
+	 * @param areacode the areacode to set
+	 */
+	public void setAreacode(String areacode) {
+		this.areacode = areacode;
+	}
+
+	/**
+	 * @return the birthcode
+	 */
+	public String getBirthcode() {
+		return birthcode;
+	}
+
+	/**
+	 * @param birthcode the birthcode to set
+	 */
+	public void setBirthcode(String birthcode) {
+		this.birthcode = birthcode;
+	}
+
+	/**
+	 * @return the suffixcode
+	 */
+	public String getSuffixcode() {
+		return suffixcode;
+	}
+
+	/**
+	 * @param suffixcode the suffixcode to set
+	 */
+	public void setSuffixcode(String suffixcode) {
+		this.suffixcode = suffixcode;
+	}
+
+	/**
+	 * @return the id
+	 */
+	public String getId() {
+		return id;
+	}
+	
+	public void setId(String id) {
+		this.id = id;
+
+	}	
+
+	public String getArea() {
+		
+		return this.getArea_str();
+	}
+
+	public String getBirthday() {
+		
+		return this.getBirth_str();
+	}
+
+	public String getGender() {		
+		return this.getGender_str();
+	}
+
+	
+
+	public boolean verify() {
+		boolean b = false;
+		b = isValidID() && isValidArea() && isValidBirth() && isValidSuffix();
+		return b;
+	}
+	
+	boolean isValidID(){
+		boolean b = false;
+		if (this.id.length() == 18) {
+			b = true;
+			this.setAreacode(this.id.substring(0, 6));
+			this.setBirthcode(this.id.substring(6, 14));
+			this.setSuffixcode(this.id.substring(14));
+		}
+		return b;
+	}
+	
+	boolean isValidArea(){
+		boolean b = false;
+		Pattern p = Pattern.compile("\\d{6}");
+		Matcher m = p.matcher(getAreacode());
+		if (m.matches()){
+			this.setArea_str(getAreacode());
+			b = true;
+		}
+		return b;
+	}
+	
+	boolean isValidBirth() {
+		String birthdate = toDateFormat(getBirthcode(), "-");
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+		try {
+			this.setBirth_str(sdf.format(sdf.parse(birthdate)));
+			return true;
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		return false;
+	}
+	
+	boolean isValidSuffix() {
+		boolean b = false;
+		Pattern p = Pattern.compile("\\d{3}[\\dX]");
+		Matcher m = p.matcher(getSuffixcode());
+		if(m.matches()){
+			b = true;
+			setGender(getSuffixcode());
+		}
+		return b;
+	}
+
+	String toDateFormat(String s, String delimiter) {
+		StringBuffer sb = new StringBuffer();
+		sb.append(s.substring(0, 4));
+		sb.append(delimiter);
+		sb.append(s.substring(4, 6));
+		sb.append(delimiter);
+		sb.append(s.substring(6));
+		return sb.toString();
+	}
+	
+	private void setGender(String s){
+		int gender = Integer.parseInt(new Character(s.charAt(2)).toString());
+		int remain = gender % 2;
+		if (remain == 0 ){
+			this.setGender_str(GENDER_WOMAN);
+		} else {
+			this.setGender_str(GENDER_MAN);
+		}
+	}
+
+}

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/SimpleVerifierRegistrationListener.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/SimpleVerifierRegistrationListener.java?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/SimpleVerifierRegistrationListener.java
(added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/java/org/apache/aries/samples/blueprint/idverifier/server/SimpleVerifierRegistrationListener.java
Sat Jan 16 15:20:44 2010
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.aries.samples.blueprint.idverifier.server;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author forrestxm
+ *
+ */
+public class SimpleVerifierRegistrationListener {
+	
+	public void reg(PersonIDVerifierSimpleImpl svcobject, Map props){
+		//svcobject.doAfterReg();
+		System.out.println("********Registered bean "+svcobject.getClass().getName()+" as a service**********");
+		System.out.println("********Print service properties**************");
+		Set keyset = props.keySet();
+		Iterator iter = keyset.iterator();
+		while(iter.hasNext()){
+			Object keyobj = iter.next();
+			Object valueobj = props.get(keyobj);
+			System.out.println(keyobj + "=" + valueobj);			
+		}
+		
+	}
+	public void unreg(PersonIDVerifierSimpleImpl svcobject, Map props){
+		System.out.println("********Unregistering service bean "+svcobject.getClass().getName()+"**********");
+	}
+
+}

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-server.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-server.xml?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-server.xml
(added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/blueprint-sample-idverifier-server/src/main/resources/OSGI-INF/blueprint/blueprint-sample-idverifier-server.xml
Sat Jan 16 15:20:44 2010
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+	<!--
+		Licensed to the Apache Software Foundation (ASF) under one or more
+		contributor license agreements. See the NOTICE file distributed with
+		this work for additional information regarding copyright ownership.
+		The ASF licenses this file to You 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.
+	-->
+<blueprint default-activation="eager" default-availability="mandatory"
+	default-timeout="300000" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+	<description>Apache Aries Blueprint Sample - Complex Server</description>
+
+	<bean id="simpleverifier"
+		class="org.apache.aries.samples.blueprint.idverifier.server.PersonIDVerifierSimpleImpl">
+		<description>ID Verifier Simple Implementation</description>
+	</bean>
+
+	<service id="simpleverifierservice" ref="simpleverifier"
+		interface="org.apache.aries.samples.blueprint.idverifier.api.PersonIDVerifier"
+		ranking="100">
+		<description>ID Verifier Simple Service</description>
+		<service-properties>
+			<entry key="mode" value="simple" />
+		</service-properties>
+		<registration-listener registration-method="reg" unregistration-method="unreg">
+			<bean class="org.apache.aries.samples.blueprint.idverifier.server.SimpleVerifierRegistrationListener"/>
+		</registration-listener>
+	</service>
+
+	<bean id="complexverifier"
+		class="org.apache.aries.samples.blueprint.idverifier.server.PersonIDVerifierComplexImpl"
+		activation="lazy">
+		<description>ID Verifier Complex Implementation</description>
+		<property name="definedAreacode">
+			<map key-type="java.lang.String" value-type="java.lang.String">
+				<entry key="pudong" value="310115" />
+				<entry key="putuo" value="310107" />
+				<entry key="beijinghaidian" value="110108"/>
+			</map>
+		</property>
+		<property name="coefficient">
+			<array value-type="int">
+				<value>7</value>
+				<value>9</value>
+				<value>10</value>
+				<value>5</value>
+				<value>8</value>
+				<value>4</value>
+				<value>2</value>
+				<value>1</value>
+				<value>6</value>
+				<value>3</value>
+				<value>7</value>
+				<value>9</value>
+				<value>10</value>
+				<value>5</value>
+				<value>8</value>
+				<value>4</value>
+				<value>2</value>
+			</array>
+		</property>
+		<property name="datepattern" value="yyyy/MM/dd"/>
+	</bean>
+	
+	<service id="complexverifierservice" 
+		auto-export="disabled" 
+		ranking="200" 
+		ref="complexverifier">
+		<description>ID Verifier Complex Service</description>
+		<interfaces>
+			<value>org.apache.aries.samples.blueprint.idverifier.api.PersonIDVerifier</value>
		
+		</interfaces>
+		<service-properties>
+			<entry key="mode" value="complex" />
+		</service-properties>
+		<registration-listener registration-method="reg" unregistration-method="unreg">
+			<bean class="org.apache.aries.samples.blueprint.idverifier.server.ComplexVerifierRegistrationListener"/>
+		</registration-listener>		
+	</service>	
+</blueprint>

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/pom.xml?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/pom.xml (added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/pom.xml Sat Jan 16 15:20:44
2010
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.aries.samples</groupId>
+        <artifactId>samples</artifactId>
+        <version>1.0.0-incubating-SNAPSHOT</version>
+    </parent>
+    
+    <groupId>org.apache.aries.samples</groupId>
+    <version>1.0.0-incubating-SNAPSHOT</version>
+    <artifactId>blueprint-sample-idverifier</artifactId>
+    <name>Apache Aries Blueprint Sample - ID Verifier</name>
+    <packaging>pom</packaging>
+
+    <repositories>
+       <!--  <repository>
+            <id>apache.snapshots</id>
+            <name>Apache Snapshots Repository</name>
+            <url>https://repository.apache.org/content/groups/snapshots-group</url>
+            <layout>default</layout>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>daily</updatePolicy>
+                <checksumPolicy>ignore</checksumPolicy>
+            </snapshots>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+        </repository>
+        -->
+    </repositories>
+  
+    <build>
+        <pluginManagement>
+            <plugins>    
+                <plugin>
+                   <groupId>org.apache.maven.plugins</groupId>
+                   <artifactId>maven-compiler-plugin</artifactId>
+                   <configuration>
+                       <source>1.5</source>
+                       <target>1.5</target>
+                   </configuration>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+
+    <dependencyManagement>
+    <dependencies>
+        
+            <dependency>
+                <groupId>org.eclipse</groupId>
+                <artifactId>osgi</artifactId>
+                <version>3.5.0.v20090520</version>
+            </dependency>
+       
+       <dependency>
+                <groupId>org.apache.aries.blueprint</groupId>
+                <artifactId>org.apache.aries.blueprint.api</artifactId>
+                <version>${pom.version}</version>
+            </dependency>
+
+	
+    </dependencies>
+	</dependencyManagement>
+
+    <modules>
+        <module>blueprint-sample-idverifier-api</module>
+        <module>blueprint-sample-idverifier-server</module>
+	<module>blueprint-sample-idverifier-client</module>
+<module>blueprint-sample-idverifier-assembly</module>
+    </modules>
+
+</project>

Added: incubator/aries/trunk/samples/blueprint-sample-idverifier/readme.txt
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blueprint-sample-idverifier/readme.txt?rev=899972&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blueprint-sample-idverifier/readme.txt (added)
+++ incubator/aries/trunk/samples/blueprint-sample-idverifier/readme.txt Sat Jan 16 15:20:44
2010
@@ -0,0 +1,42 @@
+################################################################################
+# Copyright 2010 
+# 
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You 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.
+################################################################################
+
+Apache Aries Samples
+----------------------------------------------------------------------
+
+This sample demonstrates blueprint inlined managers usage.
+
+This README uses the following aliases to describe directories.  These aliases should be
replaced with your actual directory paths.
+   %SAMPLE_HOME% refers to the root directory where Aries samples are extracted.
+   
+
+BUILD
+-----
+1. cd %SAMPLE_HOME%/blueprint-sample-idverifier
+2. maven clean install
+   
+
+RUN
+---
+1. cd %SAMPLE_HOME%/blueprint-sample-idverifier/blueprint-sample-idverifier-assembly/target
+2. run.bat|.sh
+
+MEMO
+----
+After the sample is running, you can connect to it via JConsole to check the sample bundles
via blueprint MBeans.

Modified: incubator/aries/trunk/samples/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/pom.xml?rev=899972&r1=899971&r2=899972&view=diff
==============================================================================
--- incubator/aries/trunk/samples/pom.xml (original)
+++ incubator/aries/trunk/samples/pom.xml Sat Jan 16 15:20:44 2010
@@ -43,6 +43,7 @@
     <modules>
         <module>helloworld-samples</module>
         <module>blog-sample</module>
+        <module>blueprint-sample-idverifier</module>
     </modules>
 
 </project>



Mime
View raw message