Skip to content

Commit

Permalink
added P Namespace tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
mozammel committed Nov 18, 2014
1 parent 1bf2eac commit 3ba14b3
Show file tree
Hide file tree
Showing 13 changed files with 354 additions and 0 deletions.
26 changes: 26 additions & 0 deletions springtutorial12/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
29 changes: 29 additions & 0 deletions springtutorial12/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>springtutorial04</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions springtutorial12/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
5 changes: 5 additions & 0 deletions springtutorial12/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
4 changes: 4 additions & 0 deletions springtutorial12/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
16 changes: 16 additions & 0 deletions springtutorial12/.springBeans
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[3.6.2.201410090854-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/java/com/livingoncodes/spring/springtutorial/beans/beans.xml</config>
</configs>
<autoconfigs>
</autoconfigs>
<configSets>
</configSets>
</beansProjectDescription>
40 changes: 40 additions & 0 deletions springtutorial12/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.livingoncodes.spring</groupId>
<artifactId>springtutorial04</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>springtutorial04</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.11.RELEASE</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.livingoncodes.spring.springtutorial;

public class Address {

private String street;
private String postcode;

public Address() {
}


public void init() {
System.out.println("Address created" + this);
}

public void destroy() {
System.out.println("Address destroyed");
}

public Address(String street, String postcode) {
this.street = street;
this.postcode = postcode;
}

public String getStreet() {
return street;
}

public void setStreet(String street) {
this.street = street;
}

public String getPostcode() {
return postcode;
}

public void setPostcode(String postcode) {
this.postcode = postcode;
}

@Override
public String toString() {
return "Address [street=" + street + ", postcode=" + postcode + "]";
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.livingoncodes.spring.springtutorial;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{

ApplicationContext context = new ClassPathXmlApplicationContext("com/livingoncodes/spring/springtutorial/beans/beans.xml");


Patient patient = (Patient) context.getBean("patient");

Address address2 = (Address) context.getBean("address2");

System.out.println(patient);

System.out.println(address2);

((ClassPathXmlApplicationContext) context).close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.livingoncodes.spring.springtutorial;

public class Patient {

private int id;
private String name;

private int nationalId;

private Address address;

public Patient() {

}

public static Patient getInstance(int id, String name) {
System.out.println("Creating patient using factory method");
return new Patient(id, name);
}

public void onCreate() {
System.out.println("Patient created: " + this);
}

public void onDestroy() {
System.out.println("Patient destroyed");
}

public Patient(int id, String name) {
this.id = id;
this.name = name;
}

public Address getAddress() {
return address;
}

public void setAddress(Address address) {
this.address = address;
}

public int getNationalId() {
return nationalId;
}

public void setNationalId(int nationalId) {
this.nationalId = nationalId;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Patient [id=" + id + ", name=" + name + ", nationalId="
+ nationalId + ", address=" + address + "]";
}

public void speak() {
System.out.println("Help me!");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.livingoncodes.spring.springtutorial;

public class PatientFactory {
public Patient createPatient(int id, String name) {
System.out.println("Using factory class to create Patient");
return new Patient(id, name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
default-init-method="init" default-destroy-method="destroy"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


<bean id="patient"
class="com.livingoncodes.spring.springtutorial.Patient"
scope="singleton" init-method="onCreate" destroy-method="onDestroy"
factory-method="getInstance">
<constructor-arg value="5" name="id"></constructor-arg>
<constructor-arg value="Tom" name="name"></constructor-arg>
<property name="nationalId">
<value>12345</value>
</property>
<property name="address" ref="address"></property>
</bean>

<bean id="address" class="com.livingoncodes.spring.springtutorial.Address">
<constructor-arg name="street" value="Panthapath"></constructor-arg>
<constructor-arg name="postcode" value="1200"></constructor-arg>
</bean>

<bean id="address2" class="com.livingoncodes.spring.springtutorial.Address" p:street="Green Road" p:postcode="1210">

</bean>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.livingoncodes.spring.springtutorial04;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}

/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}

/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}

0 comments on commit 3ba14b3

Please sign in to comment.