You are on page 1of 84

章節 1

What’s Nepenthes?
Nepenthes is a sub-middleware for iOS & macOS App development,which sets the
standards for java back-end and Objective-C front-end development.Nepenthes back-end
is based on Apache Tomcat or other J2EE compatible middleware by extends Nepenthes
library.Nepenthes front-end is mapping to back-end with the support of Nepenthes
framework. Nepenthes simplifies development process and shortens development
lifecycle,it ensures the communication layer safe and solid,let your team focus only on
business logic.
Based on Nepenthes,your organization can develop very complicated enterprise
Apps rapidly,reduce back-end and front-end teams employees nearly to half. Reduce the
communication errors in the development debugging,raise project development speed
dramatically.
Nepenthes is for senior back-end Java developers and senior front-end Objective-C
developers.Before you start to read it,we assume you are very familiar even master in
using Mac,Apache Tomcat,MySQL,SQL Language,Java JSP,Servlet or Objective-C. You
needn’t master Java and Objective-C at the same time,Java developers focus on the back-
end section,Objective-C developers focus on front-end section.
Nepenthes is the fruit of over 20-year Java and over 8-year Objective-C
development experience.The author worked in Borland for 8 years responsible for
enterprise products support:Borland VisiBroker(CORBA middleware) and Borland
Enterprise Server(J2EE middleware).
章節 2

Development Environment
This book is for development practice instead of theory,so we will jump to development
environment configurations.Nepenthes is targeted for iOS & macOS development,you
should have a MacBook or iMac with the latest macOS version updated.Before we
started,confirm you are senior Java or Objective-C developer,Java for back-end,Objective-
C for front-end. Your Mac(refers to MacBook or iMac hereby.) should install the
following software:
macOS(10.11.6)
JDK(1.8.0)
Xcode (7.3.1)
NetBeans(8.0.2)
MySQL(5.6.24)
Tomcat (7.0.55)
Before we started to study Nepenthes,please make sure you have got the above
softwares and installed properly.All the softwares are free to use and install.To keep the
same testing result with this book,we recommended strongly to use the same version
showed in the parentheses. Objective-C front-end developers only need to meet macOS
and Xcode of above requirements list,Java back-end developers need to meet all of them
except Xcode. But for testing convenience,we recommend strongly to install all of them.
By the way,you should be very familiar to Mac usage regardless Java back-end
developers and Objective-C front-end developers.
The environment built with the above six softwares is the complete Nepenthes
development environment. The production OS will not limited to macOS,it also support
Linux and Unix,the deploy methods are same as described in this book.
The author’s production environment is Ubuntu Linux,as for develop and debug
easily,we will lead to to set up a complete development and production environment.
Re:all the above softwares you can download from its official website or from this
book’s official website www.everdow.org We recommend strongly to download
Nepenthes Mac App (https://itunes.apple.com/app/nepenthes/id764623073 ) from Mac
App Store,all the softwares,libraries and frameworks are all included in the Nepenthes
App.
2-1 Nepenthes App - Home
2-2 Nepenthes App - Download
If you have any question to submit,you can raise question in Nepenthes Mac App,we
will response you there. You can also send email to us everdow@gmail.com
2-3 Nepenthes App - Feedback
小節 1

MacOS

2-1-1macOS version check window

macOS is shipped with your Mac,please be sure it is the latest release version.Check your
Mac from top-left Apple logo’s first menu item: About This Mac. If your macOS is not the
lastest version,please update from Mac App Store by clicking the Software
Update…button. Updating to lastest macOS version maybe a long time process but
necessary,so please make sure to be patient with it.To avoid unpredictable errors,please do
not install pre-release version of macOS for developers.
Your Mac’s version should not be the very same as above screenshot,but should be
not be lowed than 10.11.6
Mac’s update is a very large bundle for download and update,before you started to
learning this book,you should take your time to make sure your Mac has updated to the
lasted release version.Please remember DO NOT install macOS pre-release version for
Apple developers,that the not the release version,it maybe lead to unpredictable
errors,which will make you feel confuse when you debugging while learning.
We assue you have been familiar with Mac basic use,this book is for senior
developers,so if you are not familiar with Mac use,please learn it first or go Apple Store’s
local Genius Bar to take some free classed for Mac.
小節 2

Xcode

2-2-1 Xcode Startup Window

Xcode is the Objective-C IDE(Integrated Development Environment),it is free and can be


downloaded from Mac App Store.To avoid unpredictable errors,please make sure you
install Xcode release lastest version,do not install pre-release version for developers.So far
to writing this book,the Xcode release stable version is 7.3.1 Xcode is for Objective-C
front-end developers,Java back-end developers will not use it,but for testing
convenience,we recommend strongly to install it anyway.
Your Xcode version should not be lower than 7.3.1,though it will not occur any
error,but to keep the same development environment,we recommend to updated to the
same version.
Xcode is Apple’s only IDE for developing iOS,macOS and tvOS apps,it supports
Objective-C and Swift languages at the same time. Xcode is very large application,so
before you started learning this,please take your time to download or update Xcode to the
proper version we mentioned above.
If you have never used Xcode,it is not the problem to stop you learning this book.
You only need to follow the examples step by step,after some examples you will learn to
use Xcode’s basic functions.
小節 3

JDK

2-3-1

Open Terminal App from Finder->Applications->Utilities->Terminal. Terminal will be


used frequently,so after it started,right click on Terminal icon located on Dock,select
Options->Keep in Dock.
After Terminal App started,type the command to check if your Mac has installed
JDK(Java Development Kit) latest release version.
Command: java -version
If return as the following,it means your Mac has installed JDK property,otherwise
please install the lastest version. Your return result maybe not very same as the
following,only if the main version is begin with 1.8
java version “1.8.0_45”
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
JDK on Mac is maintained by Apple Inc,so we recommend strongly to install and
update JDK by Mac App Store. Install JDK from other source maybe cause unpredictable
errors and compatible issues.
小節 4

NetBeans

2-4-1 NetBeans Startup Window

NetBeans is a professional Java IDE(Integrated Development Environment),originally


sponsored by SUN Microsystem,now by Oracle.Java development has many
IDEs:NetBeans,Eclipse,etc. NetBeans is for Java back-end developers,you maybe are
familiar with other IDE,but to keep the sample in this book same and easy to debug,we
recommend strongly to use NetBeans while you are learning Nepenthes in this
book.NetBeans is free to use,you can download it from www.netbeans.org
When you download NetBeans from www.netbeans.org,please select the standard
edition,because we will only use NetBeans basic functions,other editions will started very
many unnecessary softwares at the same time and occupied valuable memory and disk
space. We recommend you download NetBeans 8.0.2 but not limited,the version should
not be lower than 8.0.2.
NetBeans is the very first Java IDE since Java invented,NetBeans is sponsored by
SUN Microsystem. It can be seemed the Java IDE industry standard though later showed
JBuilder(Borland Inc.) and Eclipse(IBM Sponsored) and etc.NetBeans can be recognized
Java IDE implementation best practice.
小節 5

MySQL
We use MySQL as the database server,please download free Community Edition from
www.mysql.com. We recommend to download 5.6.24 for x86 64 bit edition. MySQL will
be installed to /usr/local,before starting MySQL server,we will modified its configuration
to support UTF-8 encoding,examples in this book will use UTF-8 as the default encoding
format,UTF-8 is the very popular encoding format which supports almost all the
languages in the world.Please follow the following steps precisely:
Open Terminal;
Exec command: cd /usr/local/mysql with return;
Exec command:open . to open a new Finder located to the current location;
Open my.cnf with TextEdit,add the following content in the very beginning and
save:
[client]
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
After changed MySQL configuration,cd /usr/local/mysql/support-files in Terminal.
mysql.server will responsible for MySQL status,start,stop and restart.
MySQL Status: sudo ./mysql.server status
MySQL Start: sudo ./mysql.server start
MySQL Stop: sudo ./mysql.server stop
MySQL Restart: sudo ./mysql.server restart
sudo means exec the command needs super user privilege. Now please start MySQL
with the command: sudo ./mysql.server start
If the terminal show the following message,it means MySQL has started
successfully:
Starting MySQL
. SUCCESS!
Now in Terminal exec the command: cd /usr/local/mysql/bin
Type the command:./mysql -u root -p
MySQL default password is null,while prompt you to enter password,just enter will
be ok. If terminal show the mysql> that means you have logged in MySQL client
successfully. We will create database with the command: create database
NepenthesDemo; The NepenthesDemo is the example database in this book while testing
with Java or Objective-C.
We assume you are very familiar with MySQL installation and usage,but if you are a
newer to MySQL just following the above steps precisely,you will also get the right
result.Even so,we recommend strongly to learn more information about MySQL on its
official website www.mysql.com
Every time you start your Mac,MySQL will not started automatically,so please
started MySQL before starting to learn Nepenthes. Terminal is the very frequent App used
in this book,so please make sure your have keep it on dock,and know the frequent unix
commands. Unix commands are beyond this book,please search macOS frequent
commands to learn.
MySQL is an open source database,now has already belonged to Oracle,you can
only use the Community Edition for testing,this edition is free to download.You also
should know the frequent MySQL commands and SQL languages fundamental
knowledges. Please to to www.mysql.com to learn MySQL knowledge and commands.
SQL Language is the universal database language,we recommend strongly you to
learn it and should remember the main statements frequently used,there are so many books
about SQL language,you can learn it from any book about it.
小節 6

Tomcat
Nepenthes uses Apache Tomcat as web server to provide JSON service through Servlet.
You can download freely from http://tomcat.apache.org ,we recommend you to download
version 7.0.55 in order to keep same as this books’ environment.Tomcat will be put in
/usr/local as the MySQL located,after downloaded, unzip it to /usr/local and change the
tomcat mode with the following command,you need open a Terminal and cd /usr/local
first. The command appends Apache Tomcat execution permission.
sudo chmod -R +X ./apache-tomcat-7.0.55/
Before we start any configuration of Tomcat,you need copy MySQL JDBC
driver(mysql-connector-java-5.1.20-bin.jar you can download from www.mysql.com) to
/usr/local/lib
Open /usr/local/apache-tomcat-7.0.55/conf/server.xml with Xcode by the following
steps(The italic words stand for commands):
Open Terminal;
cd /usr/local/apache-tomcat-7.0.55/conf/
open .
Double click server.xml
Find the section with the following content,change port from 8080 to 80 in order to
keep same as this book’s testing environment. 80 is the standard web service default port.
<Connector executor=“tomcatThreadPool”
port=“8080” protocol=“HTTP/1.1”
connectionTimeout=“20000”
redirectPort=“8443” />
The revised configuration section is:
<Connector executor=“tomcatThreadPool”
port=“80” protocol=“HTTP/1.1”
connectionTimeout=“20000”
redirectPort=“8443” />
Find section of the following:
<Host name=“localhost” appBase=“webapps”
unpackWARs=“true” autoDeploy=“true”>
under the following section:
<Valve className=“org.apache.catalina.valves.AccessLogValve” directory=“logs”
prefix=“localhost_access_log.” suffix=”.txt”
pattern=”%h %l %u %t &quot;%r&quot; %s %b” />
added the following context to setup NepenethesDemo web component and its
database connection pool,as for the MySQL default password is null,so leave the password
to blank:
<Context path=”/NepenthesDemo” docBase=“NepenthesDemo” debug=“5” reloadable=“true”
crossContext=“true”>
<Resource name=“jdbc/NepenthesDemo” auth=“Container” type=“javax.sql.DataSource”
maxActive=“50” maxIdle=“30” maxWait=“10000”
username=“root” password=”” driverClassName=“com.mysql.jdbc.Driver”
url=“jdbc:mysql://localhost:3306/NepenthesDemo?autoReconnect=true”/>
</Context>

While editing server.xml configuration file,please be very careful not to add or


remove any characters,even a tiny mistake will lead to Tomcat startup fail.
Navigate to /usr/local/apache-tomcat-7.0.55/webapps/ with Finder,do tasks with the
following steps:
Create Folder: NepenthesDemo
Create Folder: NepenthesDemo/WEB-INF
Create Folder: NepenthesDemo/WEB-INF/lib
Copy the following Java library jar files(You can download all of the jar files from
www.everdow.org ) to NepenthesDemo/WEB-INF/lib

nepenthes-3.0.jar
commons-io-1.2.jar
commons-fileupload-1.1.jar
jackson-annotations-2.0.6.jar
jackson-core-2.0.6.jar
jackson-databind-2.0.6.jar
javax.mail.jar
commons-email-1.4.jar
commons-codec-1.10.jar
Create file web.xml with the following content and save to /usr/local/apache-tomcat-
7.0.55/webapps/NepenthesDemo/WEB-INF,this creates DBCP naming to be referenced by
NepenthesDemo JSP and Servlet container.
<?xml version=“1.0” encoding=“ISO-8859-1”?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-
instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
version=“2.4”>
<display-name>Nepenthes Demo</display-name>
<description>Welcome to Nepenthes Demo</description>
<context-param>
<param-name>DBCP</param-name>
<param-value>jdbc/NepenthesDemo</param-value>
</context-param>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/NepenthesDemo</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
So far you installed and configured Tomcat completely only left one jar(nepenthes-
demo-3.0.jar,this contains the back-end core java class files.) file that we will create in the
next chapter.
Navigate to /usr/local/apache-tomcat-7.0.55/bin with Terminal,the following
commands will start and stop Tomcat server.

Start Tomcat: sudo ./startup.sh


Stop Tomcat: sudo ./shutdown.sh
Started Tomcat with the above command,open Safari to test it with the URL:
http://localhost/,if you see the following screenshot,that means you have started Tomcat
correctly.
Tomcat is playing very import role in Nepenthes,it provides web service for JSP and
Servlet,you should be very familiar with it. You can learn all the knowledges from its
official website http://tomcat.apache.org Even you are newer to Tomcat, if you follow all
the steps described in this chapter,you can reach to the destination for testing,but we
recommend strongly to master Apache Tomcat,because it is the core part of back-end
middleware,Nepenthes back-end is based on it. Almost all the commercial J2EE
middleware are also based on Tomcat.
章節 3

Back-End
Nepenthes back-end development has the following four sections:
Mapping Object
Business Logic Object
Service Object
Deployment Configuration
Mapping Object is a Java class mapping to the database table structure,one
property to one field.
Business Logic Object is for operating Mapping Object,it has the following
functions:
Define table creation SQL statements
Define table indexed fields
Create table in database automatically if not exist
Basic operations for database table by Mapping Object:insert,delete,update and
select
Other useful operations:select with pages split,get Mapping Object by its ID,delete
by its ID
Through the operations in Business Logic Object,you can execute almost every kind
of task to the database table by Mapping Object.
Service Object is acting as JSON service for iOS and macOS client based on
Servlet. Its operations are mapping to Business Logic Object operations,transferring from
JSON to Mapping Object and so forth to provide object oriented operations for remote
object invoke.
Deployment Configuration is in the web component’s web.xml,because Service
Object is a Servlet in fact,so we need to add servlet definition and mapping in web.xml in
/usr/local/apache-tomcat-7.0.55/NepenthesDemo/WEB-INF/
小節 1

Mapping Object
Mapping Object is a Java class mapped to a table structure,we will create an example
Mapping Object first.Please follow the steps precisely:
Open NetBeans,select menu File->New Project…

3-1-1
Select Java in Categories,and select Java Class Library in Projects,click Next.
3-1-2
Fill in nepenthes-demo-3.0 in Project Name field,Project Location we select the
current user’s Desktop,or you can navigate to the folder you preferred. And then click
Finish button.
3-1-3
In the opened project of nepenthes-demo-3.0,select Libraries,right click,select Add
Jar/Folder…
3-1-4
In the poped Add Jar/Folder window,locate to /usr/local/apache-tomcat-
7.0.55/webapps/NepenthesDemo/lib,you have copied the necessary jar files in the Chapter
2,if nothing exists,please go back to operate
3-1-5
select nepenthes-3.0.jar, select Absolute Path in the left Reference as panel,and
click Choose button
3-1-6
Repeat the above step to add servlet-api.jar in /usr/local/apache-tomcat-
7.0.55/lib/,now the Project panel should looks like the following screenshot.

3-1-7
Now close the Libraries node under nepenthes-demo-3.0 project,open Source
Packages node.

3-1-8
Right click Source Packages,select New->Java Package…

3-1-9
Input com.yourcompany.schema in Package Name field and click Finish button.
3-1-10
Repeat the above steps to create another two packages:

com.yourcompany.bl
com.yourcompany.service
Now the Project panel should looks like:
3-1-11
Right click com.yourcompany.schema package,select New->Java Class…

3-1-12
Input UserSchema in Class Name field and click Finish button.Every Mapping
Object must have Schema suffix,that’s mandatory for Nepenthes. Schema is one of the
Nepenthes’ conserved keywords,and the class name should follow Java naming
conventions.

3-1-13
Edit UserSchema.java,make sure it has the following content,the first property ID
maps to User table automatic increment field,Nepenthes use ID to identify a unique table
record,that is also the mandatary design protocol for every Mapping Object,you can guess
other properties meanings from their names.
3-1-14
Select menu Run->Compile File or hit F9 to compile the Mapping
Object:UserSchema.java If compiled without any error,that means you have create it
successfully.
Nepenthes back-end Mapping Object support the following java type to SQL type
mapping,these mapped types can meet almost all of your daily usage even for enterprise-
class applications.

Java Type SQL Type

int INT,TINYINT
double DECIMAL

String DATE

String DATETIME

String TEXT

String CHAR,VARCHAR
小節 2

Business Logic Object


We will create a Business Logic Object, BLUser.java,it always has prefix BL,and that’s
mandatory. Open the project we created in last chapter,and follow the steps listed
precisely.
Right click on package com.yourcompany.bl node,select New->New Class…

3-2-1
Input BLUser in Class Name field,and click Finish button.
3-2-2
Edit BLUser.java as the following contents. BLGeneral is the parent Business Logic
class,it defines all the required methods.When you extend BLGeneral class,you only need
to define two variable createSQL and indexSQL,invoke parent two methods in the
constructor.The variable createSQL is to create table automatically if not exist,as for the
default field ID will be created automatically,you only need to define other fields as
needed.The value of createSQL is SQL language statements,you should very familiar with
the standard SQL language.The variable indexSQL defines fields that will be indexed,the
value should have one field at least. The methods in the constructor:super(con) pass the
Connection to its parent class,super.init(createSQL,indexSQL) passes the two variables
define in this class,just super will make it effect,create table automatically if not exist,and
indexed the specified fields.
3-2-2
BLGeneral class defines the following methods used frequently,you can invoke the
following methods directly from BLUser class without define them:
public boolean insert(Object schema) - Pass parameter UserSchema instance and
execute insert operation,returns true if successful,otherwise returns false.The parameter’s
ID property can be assigned to 0 or ignored assignment.
public boolean update(Object schema) - Pass parameter UserSchema instance and
execute update operation,returns true if successful,otherwise returns false. The parameter’s
ID property must be assigned with its relative value,the method depends on ID value to
locate the record.
public boolean delete(int id) - Delete record by the ID value passed in. If deleted
successfully,returns true otherwise return false;
public boolean delete(String whereClause) - Delete records by the conditional
clause,the value of the whereClause parameter is the SQL condition statement after
WHERE keyword.Such as: Age>22
public int getCount(String whereClause) - Get records count by the conditional
clause passed in,the value of the whereClause is the SQL conditional statement after
WHERE keyword. The method returns int value;
public List select(String whereClause) - Select records by the condition clause
passed in,the value of the whereClause is the SQL conditional statement after WHERE
keyword.The method returns List contains Objects,you need to cast it to UserSchema
before accessing its properties.
List select(String whereClause, int index, int step) - The method has the same
function as List select(String whereClause),the only difference is this method is for page
split display,index parameter means the cursor location,step parameter menas the records
count per page.
public Object getSchema(int id) - Get record and transferred it to Object
automatically by id parameter, you need to cast it to UserSchema before accessing its
properties.
Until now your project tree should looks like the following screenshot:
3-2-4
小節 3

Service Object
Service Object provides JSON web service through Servlet,make sure you have open the
project we have created,follow the steps precisely.
Right click one package com.yourcompany.service and select NEW->Java Class…

3-3-1
Input UserService in Class Name field,and click Finish button.
3-3-2
Edit UserService.java and make it has the following contents. UserService extends
ServiceServlet class,only need to override its init() method.You only need to override the
parent class’s two variables:schema and blGeneral.
3-3-3
ServiceServlet class has the following methods pre-defined,you will not invoke
them directly,the methods is for iOS and macOS client framework remote invoke.
public void insert(HttpServletRequest request, PrintWriter out)
public void delete(HttpServletRequest request, PrintWriter out)
public void update(HttpServletRequest request, PrintWriter out)
public void select(HttpServletRequest request, PrintWriter out)
public void getCount(HttpServletRequest request, PrintWriter out)
小節 4

Build And Deploy


Until now your project tree should looks like the following screenshot:

3-4-1
We have created all the Java class files for the back-end,you need to the following tasks to
build and deploy.
Right click on the project node,select Build menu item,if built successfully without
any errors or warning,you have completed all the back-end sources development.
3-4-2
Change to File panel in the Project window,and open folder dist,right click on
nepenthes-demo-3.0.jar and select Tools->Show in Finder,this will open a new Finder
window located to nepenthes-demo-3.0.jar,copy the file to /usr/local/apache-tomcat-
7.0.55/webapps/NepenthesDemo/WEB-INF/lib/

3-4-3
小節 5

Deployment Configuration
Because Back-end provides JSON web service by Servlet,the last step for back-end is
web.xml deployment configuration. The file should be located at /usr/local/apache-tomcat-
7.0.55/webapps/NepenthesDemo/WEB-INF/ create the file with NetBeans,its contents
should contains all the contents in the following screenshot.

3-5-1
We will explain every section’s meaning and functions.
Display Name:The web component’s name and description.

3-5-2
DBCP Naming:make sure Servlet can accessing the defined DBCP(DataBase
Connection Pool)
3-5-3
Service Password:The password for Service Objects.

3-5-4
Servlet Mapping:Service Object is extended to Servlet,every Servlet need to be
defined the mapping in web.xml

3-5-5
So far,you have completed all the tasks for back-end. We only provide one table
with its suit of java class files.You can define tables as many you like,the procedures are
same.Based on such development process,you can create complicated large enterprise
application services easily. Now you only have one task to do,start Tomcat.
Open Terminal
cd /usr/local/apache-tomcat-7.0.55/bin
sudo ./startup.sh
Now your back-end UserService has been enabled for remote invoke. Back-end
development based on Nepenthes is so easy without loosing any stability and robust.
章節 4

Front-End
Nepenthes front-end development has the following sections:
JSON Object
BLSync Object
Config File
JSON Object is a Object-C object mapped to back-end Mapping Object,only have
one significant difference:all the properties are the same type:NSString
BLSync Object is to operate with back-end Service Object,back-end Service Object
is only for BLSync Objects.
Config File is a plist file to set Protocol,Host,Port,Context,these elements consists of
back-end server configurations.
Above three object files will be resident in the same project being developed.In
order to group them,you should put JSON Object files in Json group,BLSync Object files
in BLSync group.
JSON Object,BLSync Object and Config file consists of the Nepenthes front-end
core communicated with the back-end Java Service Object.These files should be
developed by front-end Objective-C developers with Xcode.
Next we will walk you through a simple complete example for iOS and
macOS,please follow the steps precisely without losing even a little bit.
小節 1

IOS Client
Before we continue to this chapter,you should be clear that front-end is for Objective-C
developers,you should have installed the latest release version of Xcode,and have
downloaded the suitable Nepenthes framework. If you’re ready for all these conditions,we
will continue. Otherwise please go back to Chapter 2 for review.Please follow the steps
precisely without loosing any bit.Before continue the next operations please be sure you
have connected your iOS device with Mac.We assume you have basic knowledge
Objective-C and Cocoa Touch development even to master the language.
Open Xcode,select Create a new Xcode project in the left panel.

4-1-1
Choose iOS->Application category,select Single View Application,and click Next
button.
4-1-2
Fill in NepenthesClient in the Project Name field,your Organization in
Organization Name field,com.yourcompany in Organization Identifier field,select
Objective-C in Language Popup Menu,select Universal in Devices Popup Menu,leave
the three checkboxes unchecked,click Next button.
4-1-3
Select the location you want to save the project,we select Desktop to create the
project.
4-1-4
Now your created project should looks like the following screenshot.
4-1-5
Drag your downloaded Nepenthes framework for Generic iOS Device to the
project,check Copy items if need in Destination row,select Create groups in Added
folders,check NepenthesClient in Add to targets.

4-1-6
Open yellow NepenthesClient node under NepenthesClient blue project node,right
click on yellow NepenthesClient node,select New File…
4-1-7
Select iOS->Source,choose Cocoa Touch Class and click Next button.
4-1-8
Fill UserJson in Class field,input or select AbstractJson in Subclass of,select
Objective-C in Language,and click Next button.
4-1-9
There will popup a default location for the source to be created,you only need to
click the Create button.
4-1-10
Your Xcode should looks like the following screenshot.

4-1-11
Edit UserJson.h file to make it has the following contents.
4-1-12
Edit UserJson.m to make it has the following contents.
4-1-13
Repeat above steps to create BLSyncUser Objective-C class,please be sure the Class
name is BLSyncUser and Subclass of BLSyncAbstract.
4-1-14
Edit BLSyncUser.h to make it has the following contents.
-(BOOL)insert:(UserJson *)json - Remote invoke back-end UserService’s insert
operation,json is the UserJson instance;
-(BOOL)delete:(NSString *)whereClause - Remote invoke back-end UserService’s
delete operation,whereClause is the conditional statements after WHERE keyword. If the
whereClause contains %,you need to replace it with ~
-(BOOL)deleteByID:(NSString *)ID - Remote invoke back-end UserService delete
operation,delete the specified record with the ID.
-(BOOL)update:(UserJson *)json - Remote invoke back-end UserService update
operation,the passed in object json’s ID property should be assigned with ID value without
leaving blank.
-(NSInteger)getCount:(NSString *)whereClause - Remote invoke back-end
UserService getCount operation to get the count that meets the condition specified with
whereClause. If the whereClause contains %,you need to replace it with ~
-(NSArray *)select:(NSString *)whereClause - Remove invoke back-end
UserService select operation and returned array of UserJson collections. If the
whereClause contains %,you need to replace it with ~
-(NSArray *)select:(NSString *)whereClause index:(NSString *)index step:
(NSString *)step - The operation is same as the above select method,only one difference
this is for page split operation,index is the current cursor,step is the records count per
page. If the whereClause contains %,you need to replace it with ~
-(UserJson *)getJson:(NSString *)ID - Get UserJson object by its ID value.

4-1-15
Edit BLSyncUser.m to make it has the following contents,we define the
implementations for the header file defined above.
4-1-16
Right click on yellow NepenthesClient node under blue NepenthesClient project
node,select New…,select iOS->Resource,choose Property List,and click Next button.
4-1-17
Input Config in Save as field,make sure NepenthesClient group selected,Targets-
>NepenthesClient checked and click Next button.
4-1-18
Edit Config.plist to make it has the following contents

Protocol: http or https


Host:server domain name or IP address
Port: tomcat connector port
Context: web component name
ServicePassword: define in web.xml
4-1-19
If you test the example via http,you need to add the following to info.plist

4-1-20
Edit ViewController.h to make it has the following contents.In face,you only need to
import two headers: UserJson.h and BLSyncUser.h

4-1-21
Edit ViewController.m to make viewDidLoad function has the following contents. In
the following contents,we test all the functions defined in BLSyncUser,in the real
development you only need one or two of them to operate in one ViewController,here we
listed all the functions and comments them,it is mean when you test each function,you
need to uncomment the specified block and comment other unneeded sections.
4-1-22
Before you run the project,make sure you have started MySQL and Tomcat
successfully.
So far, you have reached to the end of iOS client core development,you can added as
many UIs as necessary. Based on this chapter’s development process and procedure,you
can build very complicated enterprise iOS Apps as you wish.Of cause every fron-end
object implementation must mapped to back-end java implementation.
小節 2

MacOS Client
Now we will create a macOS client example for invoke remote UserService,in this chapter
you need to be familiar with Objective-C too.Follow the steps precisely:
Open Xcode,select Create a new Xcode Project.

4-2-1
Select OS X->Application,choose Cocoa Application and click Next button.
4-2-2
Fill in NepenthesClient in Product Name field,your company in Organization
field,com.yourcompany in Organization Identifier field,select Objective-C in Language
popup menu,check Use StoryBoards and leave others unchecked,click Next button.
4-2-3
Choose the location you wish to save the project,click Create button.
4-2-4
Drag Nepenthes framework for macOS to the project,and make sure you have the
same selections as the following screenshot and click Finish button.

4-2-5
Right click yellow NepenthesClient node under blue NepenthesClient node,select
New File…
4-2-6
Select OS X->Source,choose Cocoa Class,click Next button.

4-2-7
Fill UserJson in Class field,AbstractJson in Subclass of field,select Objective-C in
Language popup menu,click Next button.
4-2-8
Leave it to the default location and click Create button.
4-2-9
Edit UserJson.h to make sure it has the following contents.

4-2-10
Edit UserJson.m to make sure it has the following contents.
4-2-11
Repeat the above step to create BLSyncUser class,Subclass of BLSyncAbstract.

4-2-12
Edit BLSyncUser.h to make it has the following contents.Every operation’s meaning
has been explained in the iOS Client Chapter 4-1,please review it.
4-2-13
Edit BLSyncUser.m to make it has the following contents.

4-2-14
Edit ViewController.h to make it has the following contents.

4-2-15
Edit ViewController.m to make it has the following contents in viewDidLoad.
4-2-16
Add Config Property List file,and to make it has the following values

4-2-17
If you use http protocol,you need to add the following content in Info.plist

4-2-18
Now Build the project,if no errors,you can run it.Before you run the project,please
make sure you have started MySQL and Tomcat successfully.
4-2-20
ViewController.m contains all the available operation for UserJson via
BLSyncUser,they will invoke the back-end UserService automatically,when you build and
run,please make sure test only one operation one time,comment and uncomment the
relative sections,all the sections have been marked,you can easily read it.
Now you have reached the end of macOS client example,this example only contains
one User Object,such kind of development process can make you build very complicated
enterprise macOS App.
章節 5

App List
Apps developed on Nepenthes back-end and front-end,there are two categories for iOS
and macOS. If you developed App based on Nepenthes,please email to
everdow@gmail.com ,we will add your App to the list here.
iOS

只為精緻生活https://itunes.apple.com/app/zhi-
wei-jing-zhi-sheng-huo/id489393686
macOS

Nepenthes
https://itunes.apple.com/app/nepenthes/id764623073

EverdowPSI
https://itunes.apple.com/app/everdowpsi/id1061097588

Comburet
https://itunes.apple.com/app/comburet/id898726236

You might also like