前回はサンプルコードを用いて、Curl ORBの動きを説明していきました。今回は、実際にコードを記述して、開発する手順を説明していきたいと思います。
はじめに
前回はサンプルコードを用いて、Curl ORBの動きを説明していきました。今回は、実際にコードを記述して、開発する手順を説明していきたいと思います。
Javaコードの作成(1)
前回説明したEclipseプロジェクトに新規サービスを追加していきます。まずはサービスクラスとデータクラスを作成します。サービスクラスは実際にCurlから呼び出すクラスとなり、データクラスはそのやりとりをするデータのクラスとなります。具体的には、メソッドの引数や戻り値となるクラスです。引数や戻り値にサポートしている型(プリミティブ、String、配列、List、Map、BigInteger、BigDecimal、Date、Timestamp、RecordSetなど)を定義する場合は、データクラスを作らなくてもよいです(Curl ORBでサポートされる方はこちらを参照ください)。
ここではまず、demoパッケージを作成し、その配下にデータクラスProductを作ります。EclipseのProject Explorerからcurl-orb-serverを選択し、New→Packageを選択し、demoパッケージを作成します。新しいパッケージをSpringで管理できるように、以下のように<context:component-scan base-package="demo"/>を1行追加します。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="sample"/>
<context:component-scan base-package="demo"/>
</beans>
次に、demoパッケージを右クリックし、New→Classを選択します。

上記画面で、NameにProductを入力し、Interfaceにjava.io.Serializableを選択すると空のProductクラスが作成されますので、以下のようにフィールドとgetter/setterを追加します。
package demo;
import java.io.Serializable;
public class Product implements Serializable {
private static final long serialVersionUID = 7071029986547765264L;
private String id;
private String name;
private int price;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
この記事は参考になりましたか?
- CurlデベロッパーセンターPick Up連載記事一覧
- この記事の著者
-
岡田 一志(オカダ ヒトシ)
大企業向けSI開発、IT基盤設計/構築やiDC設立プロジェクトの企画/開発/運用など幅広く活躍し、2006年にCurlに参画する。米Curl社(マサチューセッツ)にてCurl Core RTEの設計・開発に従事した後、現在は株式会社カールにて、Innovation Centerのオペレーションおよび...
※プロフィールは、執筆時点、または直近の記事の寄稿時点での内容です
【AD】本記事の内容は記事掲載開始時点のものです 企画・制作 株式会社翔泳社
この記事は参考になりましたか?
この記事をシェア
