Recently in JAVA Category

像专业人员一样开发 Ajax 应用程序

| No Comments | No TrackBacks

IntelliJ IDEA 8 Milestone 1

| No Comments | No TrackBacks
IntelliJ IDEA 8 keeps up with the ever-growing demand for technologies, frameworks and languages support while broadening the possibilities for developing rich, complex solutions that adapt to todays fast-paced environment.
seam_pages.jpg

Features:

# Greater Performance
# JBoss Seam
# Debuggers for JavaScript and Flex
# Flex Code Editing
# Struts 2
# Spring 2.5
# Support for SQL-92 and MySQL
# FreeMarker and Velocity
# GWT 1.5
# REST WebServices
# Core Java Development
# HTML/JSP

Download - http://www.jetbrains.com/idea/nextversion/


IntelliJ IDEA 8: Beyond Java

| No Comments | No TrackBacks
On August 22, Dmitry Jemerov, development lead at JetBrains, provided answers to InfoQ's questions regarding the latest release of IntelliJ IDEA.

The stand out changes that can be found in IntelliJ IDEA 8 are listed on the JetBrains site, such as:
  • Improved Performance
  • Debuggers for JavaScript and Flex
  • Flex Code Editing
  • Updated Integration for Spring 2.5
  • Improved Groovy and Grails support
  • Support for Scala and Python
The list contains other items and additional information not included above.  Next, the answers to some of InfoQ's questions are provided.

InfoQ: What are the stand out changes made for IntelliJ IDEA 8, besides the release notes page?
Dmitry Jemerov: Internally, the biggest change was a refactoring to extract a common foundation out of IntelliJ IDEA, which allows us to build other products on the same code base. The IntelliJ IDEA platform is already used by MPS, and we have a number of not yet announced products in the pipeline which are also built on the same platform.

InfoQ: What level of Flex integration is provided?  Is it comparable to Java?
DJ: For Flex, we are focusing only on code editing support (a visual designer for MXML is completely out of scope for us for the time being).  Of course, the Java support has been in development much longer and is currently far more advanced, but the Flex support is following along the same lines. Some of the recently introduced features for Flex are auto-import and optimize imports, generation of constructors and accessors, and so on.

A debugger for Flex has also been added in version 8, and we're also working on seamless compilation support (so that you no longer have to use Ant tasks for compiling your project, as you did with IDEA 7).

InfoQ: What level of Python and Scala support are available?
DJ: First of all, I'd like to note that neither Python nor Scala will be bundled with the final release of IntelliJ IDEA 8. The plugins are in development, but by the time the final version of IDEA 8 is released, they'll be available in beta quality as separate downloads from the plugin manager. (The Scala plugin is actually already available: http://plugins.intellij.net/plugin/?id=1347 )

Once again, we're following the same basic sequence of steps as for other languages we support. For Scala, the main challenge is to provide a full implementation of the type system, which is necessary for full code completion. That's where we're focusing our efforts at the moment.  Other than that, most of the common language support features are already in: syntax and error highlighting, formatter, structure view, auto-import, implement/override and so on.

Python is a dynamic language, which brings a significantly different set of challenges, but the feature set will end up quite similar. A debugger is also planned for Python.

InfoQ: Any plans on making the IntelliJFX plugin a first class citzen within the IDE (such as Java, Groovy, etc)?
DJ: We're taking a "wait and see" approach for the moment. From our point of view, Flex is a much stronger contender on the RIA platform market compared to JavaFX for now, and, given that our resources are limited, that's where we're focusing our efforts. But it's definitely possible that JavaFX will be supported in IDEA 9 provided that it sees sufficient adoption.

InfoQ: IntelliJ IDEA 8 brings integraton with Microsoft's Team Foundation Server, are there plans to assist in the development of the Atlassian plugin and provide first class integration with their products?
DJ: Actually Atlassian has allocated much more resources for the development of the IntelliJ IDEA plugin than we could ever hope to, so I don't think that any additional investment is required from our side. We do keep in touch with the developers of the plugin and provide advice and help regarding the usage of the IntelliJ IDEA APIs.

InfoQ: Will IntelliJ provide plugins or support for project management techniques (i.e. agile, rup, xp, etc)?  Some plugins for Eclipse (as an example) provide tracking sprints, creating stories, displaying progress charts, etc.
DJ: We do not think that an IDE plugin should be a primary interface for such a tool. An IDE is primarily a tool for working with the source code of the project, and the sprints and stories have a very loose relationship to the code. Even if we do start working on a project management tool at some later time, most likely it will be primarily a Web-based tool rather than a plugin for IntelliJ IDEA.

InfoQ: When can users expect IntelliJ IDEA 8 to be out of testing and final?
DJ: The final release of IntelliJ IDEA 8 is planned for end of fall 2008.

InfoQ: Will existing users be able to download the IntelliJ IDEA 8 installer and simply upgrade?
DJ: IntelliJ IDEA 8 will not be a free upgrade (the users will need to pay the usual upgrade fee or evaluate the new version for 30 days), but the installation procedure for the new version will be as easy as ever.

InfoQ: What can users expect in the future for IntelliJ IDEA?
DJ: We can't announce any definite plans for versions beyond IDEA 8 yet. One thing that can definitely be expected is full support for Java EE 6. Of course, the new language features of Java SE 7 will also be supported, as soon as it's clear enough which of the JSRs being discussed are going into the release and which are left out.

Other than that, you can be sure that the usual stuff will be there - more languages supported, more frameworks, new refactorings and inspections, and so on.

Conclusion
JetBrains continues to focus on providing an IDE that ranks at the top of the list for developers who not only work with Java but Groovy, Python, JavaScript, Flex, Scala and others.  Some things to keep an eye out for include better support for JavaFX, and possibly a web based tool for project management related tasks.  For additional information regarding IntelliJ IDEA 8 take a look here. (InfoQ)

ofbiz简介

| No Comments | No TrackBacks

ofbiz( http://sourceforge.net/projects/ofbiz/ ) 是Open For Business的简称。ofbiz是一个基于J2EE标准的开源企业应用工具。

由 于 framework 的开发情况非常好, 使ofbiz目前已具有了一个非常优秀的 framework. 业务模块的开发已进行了一段时间. 目前正在开发的业务模块包括 e-Commerce,Catalog,Party,Order,Work Effort, 计划开发的业务模块还包括 Financials, Sales Force Automation, Marketing Automation, Service & Call Center, HR & Payroll, Inventory & Warehouse, Shipping & Delivery, Manufacturing.

ofbiz 的 commonapp 包已提供了接近 500 个业务对象, 这些业务对象是通过 XML 格式进行的建模, 涉及到 Common, Accounting, Human Resource, Order, Party, Product, Shipment, Work Effort, Workflow等领域.

ofbiz 广泛遵循了现有的标准, 包括XML,SOAP,HTML,Java,J2EE,RuleML,WfMC,BPML,ECCMA/UNSPSC,ebXML,GAAP/FASB,OMG,ArapXML,qbXML等.

通过 XML 这种自然语言来定义过程,规则,和数据.

两大核心组件(Service Engine和Entity Engine)使obfiz的framework成为目前最有效和易用的 framework, 给企业应用系统的开发带来了极大的方便.

通过 Workflow Engine 和 Message Flow Engine 来管理业务过程.

能通过 SOAP, RMI, EJB Session Bean 等技术来调用 Service Engine 提供的服务, 这使得多年来业界为之努力的业务与技术的分离梦想成真.

Entity Engine 提供了简单有效的数据建模方式, 通过简单的XML文件来描述实体, 不需要写任何代码就能实现实体的创建,存储,删除,查找,排序, 再也不需要编写和维护数据持久化代码, 通过 JDBC 支持任意种类的数据库.

目 前的一些持久化技术, 例如 JDO, CMP Entity EJB, JDBC DAO, Embedded JDBC等, 都未能较好地解决数据持久化问题, 或则即使解决了, 也极大地降底了程序的可维护性. 而 obfiz 的 Entity Engine 在这一点上就做得非常好, 对实体的维护非常方便, 只需要维护 XML 表述的实体模型文件就全部搞定了.

我们知道一般的对象持久化技术(或称为O-R Map技术)首先需要编写数据库的建表脚本进行建表, 然后编写有大量累赘的get/set方法的实体对象, 然后编写 O-R Map 配置文件..., 如果对象模型需要修改, 则又...

ofbiz 的持久化技术的最主要的亮点在于极大地减轻了程序的维护工作量. ofbiz 的业务实体是通过 XML 进行建模, 实体模型的定义在 $OFBIZ_HOME/commonapp/entitydev/ 目录下. 有了实体模型后, 不需要编写任何 SQL 脚本, entity engine 将自动建立数据库表和纪录, 也不需要编写任何实体代码. 当需要对实体做修改时, 只需修改实体模型就行了, entity engine 会自动对数据库进行检查, 也不需要对实体代码进行任何修改, 因为根本就没有实体代码. 可以看看 ecommerce 包, 看看 ecommerce 是怎样应用 entity engine 来进行实体对象的增删改.

http://timesnet.blogchina.com/3325144.html

Ofbiz概况
OFBiz是一个非常著名的开源项目,提供了创建基于最新J2EE/XML规范和技术标准,构建大中型企业级、跨平台、跨数据库、跨应用服务器的多层、分布式电子商务类WEB应用系统的框架。
OFBiz最主要的特点是OFBiz提供了一整套的开发基于Java的web应用程序的组件和工具。包括实体引擎, 服务引擎, 消息引擎, 工作流引擎, 规则引擎等。

系统组成与层次结构

几大引擎

实体引擎, 服务引擎, 消息引擎, 工作流引擎, 规则引擎等;
其中所有最底层的是实体引擎和服务引擎,工作流引擎是基于这两个引擎之上的。

几大应用

下面按应用名称和目录进行排列:
内容管理 content
用户管理 PartyMgr
市场管理 Marketing
编目管理 catalog
设备管理 facility
订单管理 ordermgr(使用了工作流引擎)
帐户管理 accounting
人力资源管理 workeffort
系统管理 webtools

工作流模块特点分析

根据ofbiz开发者在网上的反馈,ofbiz的工作流引擎能满足大多数的用户提出的功能需求;性能也不错。但它的用户群主要来自其他模块。

根据研究和代码分析,ofbiz的代码比较复杂。因为对于想用 ofbiz来开发工作流的开发者来说,它不仅仅是一个纯工作流引擎,它还是一个开发平台和工具集,它的各个模块交叉较多(比如启动流程不是调用工作流引擎的接口,而是调用entity engine和service engine的接口),代码量大。

复杂性的另一个表现是ofbiz的呈现层使用了大量自己定义的TagLib,业务逻辑层的采用自己独立的页面流转控制逻辑,持久层用实体引擎来实现,都不是采用通用的方法。

完整版数据库有500多张表,limit版(自己搭建的用于工作流的版本)数据库有170多张表。

ofbiz的工作流引擎已经有用户使用,而且其他模块已经在很多行业投入应用;但它的工作流引擎还是处于阿尔法版本。

外部资源

*[ofbiz官方网站|http://ofbiz.sourceforge.net]
*[HongSoft工作流研究|http://blog.csdn.net/hongbo781202]

Ofbiz 入门教程(转)

| No Comments | No TrackBacks
1.Ofbiz 介绍:

Ofbiz(http://www.ofbiz.org) 是 Open Source 的商务软件系统,充分利用了各优秀的的Open Source 项目,
像 Tomcat, Ant, BeanShell, Jboss 等,构建了一个强大的系统平台,Ofbiz 已经完成了大部分商务类软件系统
都需要的部件,像用户认证、工作流、商务规则处理等,Ofbiz 的核心技术在于 Entity Engine,其他的组件基本都
是基于它的。简单来说 Entity Engine 的主要功能是将数据库表创建、对象与数据表的映射、对象的查询等做了强大
封装,你可以在一个简单的 XML 文件中定义数据库表结构,Ofbiz 会自动帮你在数据库建表,并动态生成映射对象,
你在程序中可以只考虑对 Object 的处理,Ofbiz 会自动通过事务逻辑更新到数据库中。Ofbiz 宣称的优点之一是用
很少的 Code 完成复杂的处理。

2.Ofbiz 下载与安装

首先要安装 J2SDK1.4,到 http://java.sun.com 上下载,安装后设定 JAVA_HOME 环境变量为 J2SDK 的安装目录。

访问网站 http://www.ofbiz.org,上面有下载的连接,请选择 Complete 包,因为这个包中已经包含了运行 Ofbiz
的所有东西,下载下来解开后就可以运行了。

解开 Ofbiz 包到一个目录下,假设是 "C:\ofbiz",该目录下将会有 catalina 和 ofbiz 两个目录, catalina
目录是 Tomcat 的目录,Ofbiz 对其配置做了修改,ofbiz 目录是 Ofbiz 的程序代码目录。在命令行状态下进入
"c:\ofbiz\catalina\bin" 目录,运行" ofbiz run"命令,就可以启动 Ofbiz,启动后你可以用浏览器访问
"http://localhost:8080/ecommerce",这可以访问 Ofbiz 的电子商务模块,通过页面上面的连接你可以访问到
其他模块。


3.Ofbiz Schema 的创建

Ofbiz 应用入门:

以一个实例说明,假设我们需要建一个客户资料表,起名为 StudyCustomer,各个段分别如下:
StudyCustomer {
customerId Integer,
customerName String,
customerNote String,
}

我们来实现基本的数据操作---增/删/改/查询,具体步骤如下:


1.在 XML 文件中定义数据 Schema:
需要用到三个文件,一个是我们要建的项目的 entitymodel_xxx.xml 和 entityengine.xml,还有
entitygroup.xml,
entitymodel_xxx.xml 是需要我们自己创建的,假设我们起名为 entitymodel_study.xml,放在
"c:\ofbiz\ofbiz\commonapp\entitydef"目录下,
entityengine.xml 是 Ofbiz 已经有的,放在 "c:\ofbiz\commonapp\etc"目录下,用来包含我们
定义的 entitymodel 文件。
entitygroup.xml 也是 Ofbiz 已经有的,跟 engityengine.xml 在同一目录下,我们需要把我们的
Schema 定义加入到该文件中

entitymodel_study.xml 文件的定义格式如下:
<!--================================================================================-->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE entitymodel PUBLIC "-//OFBiz//DTD Entity Model//EN"

"http://www.ofbiz.org/dtds/entitymodel.dtd">

<entitymodel>
<title>Entity of an Open For Business Project Component</title>
<description>None</description>
<copyright>Copyright (c) 2002 The Open For Business Project - www.ofbiz.org</copyright>
<author>None</author>
<version>1.0</version>

<!-- ========================================================= -->
<!-- ======================== Data Model ===================== -->
<!-- The modules in this file are as follows: -->
<!-- - org.ofbiz.commonapp.study -->
<!-- ========================================================= -->


<!-- ========================================================= -->
<!-- org.ofbiz.commonapp.study -->
<!-- ========================================================= -->

<entity entity-name="StudyCustomer"
package-name="org.ofbiz.commonapp.study"
title="Study Customer Entity">
<field name="customerId" type="id-ne"></field>
<field name="customerName" type="long-varchar"></field>
<field name="customerNote" type="long-varchar"></field>
<prim-key field="customerId"/>
</entity>
</entitymodel>

<!--================================================================================-->

这个 XML 文件中的 Tag 基本是看得明白的,只是 field 的 type 是 Ofbiz 已经预定义好的,这
是为了保证数据库间的迁移。

在 entityengine.xml 加入我们刚才定义的文件,加入一行在合适的位置:
<resource loader="mainfile" location="entitymodel_study.xml"/>
具体放的位置我们可以通过查看 entityengine.xml 找到,里面已经有加好的其他文件。

在 entitygroup.xml 加入我们的 Schema 定义,在后面加入一行
<entity-group group="org.ofbiz.commonapp" entity="StudyCustomer" />

这样我们就定义好了 Schema,现在把 c:\ofbiz\commonapp\etc\entityengine.xml 拷贝到
c:\ofbiz\catalina\shared\classes 目录下,这点要切记,我以前就因为没有拷贝,最后 Schema
怎么也创建不了。

重新启动 Ofbiz,访问 URL: http://localhost:8080/webtools,点击右上方的 "Login" 链接,
用 admin/ofbiz 登录,登录进入后选择链接"Check/Update Database",这时会出现 Check 的 Form,
该表单可以只检验 Schema 是否改变,默认的 GroupName 是"org.ofbiz.commonapp",这个不需要变,
点击"Check Only"按钮,Ofbiz 会检验变动情况,显示出一个完整的列表,你可以查一下是否有我们刚建的
"StudyCustomer",如果没有,可能是我们前面定义的有些问题,检查一下再重新做。

在检查到以后,可以再选择"Check and Add Missing",这是 Ofbiz 很强大的一个功能,你在 XML 中新
增了表,或在某个表中新增了段,它会自动映射到数据库中,避免我们去直接操作数据库。

现在已经完成了 StudyCustomer Schema 的创建,如果想检验一下是否有表创建,我们可以用编辑器打开
c:\ofbiz\data\ofbiz.script ,在里面查询 CREATE TABLE StudyCustomer 的字样,如果前面没有
问题,我们可以找到的。



4.如何使用已经定义的 Schema

如何使用已经定义的 Schema

Ofbiz 遵循 MVC 的设计模式,在 View 端,即 JSP 端主要使用 Ofbiz 定义的 Tag 来显示或
提取数据,Control 是一个 Controller Servlet,我们在 Controller Servlet 的 URI mapping
配置文件中定义各 URL 应该指向什么程序,这样,通过这个 mapping 配置文件,可以保证我们各个页面
及具体处理程序之间的独立性,例我们可以通过修改这个配置文件就可以改变某个 Form 的 Post Action
的 URL,而不需要修改实际的 HTML 或 JSP 代码。

Ofbiz 中定义了 Regions 的概念,即将一个 HTML 页面分成几个区域,像 Top, Left, Right, Main
等,通过这些 Regions 我们可以方便的组合 UI 界面,并且可以方便改变各部分所处的位置,如我们可以
把菜单很容易的从上方移到下方,只需要改变一个配置文件。Regions 类似于 HTML 中的 Frame,但它是
通过一个页面来组合界面,Frame 是通过几个页面显示在不同的帧中,Frame 的控制比较复杂,而且需要
改变相关的程序。

在 Ofbiz 中,我们可以直接在 JSP 中操作 Schema 定义的 Object,即我们刚定义的 StudyCustomer,
示例如下:


<%@ taglib uri="ofbizTags" prefix="ofbiz" %>

<%@ page import="java.util.*" %>
<%@ page import="org.ofbiz.core.util.*, org.ofbiz.core.pseudotag.*" %>
<%@ page import="org.ofbiz.core.entity.*" %>

<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<jsp:useBean id="security" type="org.ofbiz.core.security.Security" scope="request" />

<%if(security.hasEntityPermission("PARTYMGR", "_VIEW", session)) {%>

<%
try {
delegator.create("StudyCustomer",
UtilMisc.toMap("customerId","1","customerName","Cust1","customerNote","Customer Note 1"));

Iterator custs =

UtilMisc.toIterator(delegator.findAll("StudyCustomer",UtilMisc.toList("customerId","customerName","customerNote")));

while(custs.hasNext())
{
GenericValue cust = (GenericValue)custs.next();
out.println(cust.getString("customerId"));
out.println(cust.getString("customerName"));
out.println(cust.getString("customerNote"));
}
} catch(Exception e)
{
out.println(e.getMessage());
}
%>
<%}else{%>
<h3>You do not have permission to view this page. ("PARTYMGR_VIEW" or "PARTYMGR_ADMIN" needed)</h3>
<%}%>


这段程序挺容易理解,先是通过 delegator 创建一个 Object,该 Object 将会由 Ofbiz 自动同步到
数据库中。然后通过 delegator 的 findAll 取到所有已保存的 Object,最后通过一个 Iterator 对象
显示出来。

这个程序起名为 testofbiz.jsp,为简单起见,我们放到 Ofbiz 已有的一个 Webapp 的目录下,放到
c:\ofbiz\ofbiz\partymgr\webapp\party 目录下。然后我们需要修改两个配置文件:controller.xml
和 regions.xml,这两个文件就是我们上面提到的 mapping 和 regions 配置文件。

这两个文件都在:c:\ofbiz\ofbiz\partymgr\webapp\WEB-INF 下,在 controller.xml 中加入下面

<request-map uri="testofbiz">
<description>Test Ofbiz</description>
<security https="false" auth="false"/>
<response name="success" type="view" value="testofbiz"/>
</request-map>

<view-map name="testofbiz" type="region"/>

加入位置请参照 controller.xml 中已经有的配置。在 regions.xml 中加入:
<define id='testofbiz' region='MAIN_REGION'>
<put section='title'>Test Ofbiz</put>
<put section='content' content='/party/testofbiz.jsp'/>
</define>
具体加入位置请参考已有的配置。

配置完后,重新启动 ofbiz,然后访问 URL:
http://localhost:8080/partymgr/control/testofbiz

由于我们在 testofbiz.jsp 程序中使用了 Ofbiz 的安全控制机制,系统会提示现在没有访问
权限,需要登录,点击右边的"Login" 用 admin/ofbiz 登录后会看到我们程序 testofbiz.jsp
的运行结果。如果需要增加新记录,请修改

UtilMisc.toMap("customerId","1","customerName","Cust1","customerNote","Customer Note 1"));

中的各个段的值,然后再访问 http://localhost:8080/partymgr/control/testofbiz,如果不修改
而直接访问那个 URL 时,系统会提示 Primary key 冲突。


5.按照显示与逻辑分离的原则使用 Schema:

上篇讲了如何在 JSP 中使用创建的 Schema 对象,这次我们来讲述一下如何把程序
逻辑放到 JavaBeans 中,把显示处理放到 JSP 中,并使用 controller.xml 将两
部分整合起来。

首先我们来创建一个 JavaBeans,来完成Add/Get/Delete/Update Schema 对象
的操作,程序文件名为 TestOfbiz.java,放置在
c:\ofbiz\ofbiz\testOfbiz\com\geeyo\ofbiz 目录下, 具体程序如下:

>=================================================================
package com.geeyo.ofbiz;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.net.*;
import org.ofbiz.core.util.*;
import org.ofbiz.core.entity.*;
import org.ofbiz.core.service.*;
import org.ofbiz.core.security.*;
import org.ofbiz.core.stats.*;

public class TestOfbiz
{
public static void main(String[] args)
throws Exception
{
GenericDelegator delegator = GenericDelegator.getGenericDelegator("default");
delegator.create("StudyCustomer",UtilMisc.toMap("customerId","3","customerName","Kane3","customerNote","This is test customer.3"));

Iterator custs = UtilMisc.toIterator(delegator.findAll("StudyCustomer",UtilMisc.toList("customerId","customerName","customerNote")));

while(custs.hasNext())
{
GenericValue cust = (GenericValue)custs.next();
System.out.println(cust.getString("customerId"));
System.out.println(cust.getString("customerName"));
System.out.println(cust.getString("customerNote"));
}
}

public static String createNewRecord(HttpServletRequest request, HttpServletResponse response)
throws Exception
{
Map paras = UtilMisc.getParameterMap(request);

GenericDelegator delegator = GenericDelegator.getGenericDelegator("default");
delegator.create("StudyCustomer",paras);

return "success";
}

public static String lookAllRecords(HttpServletRequest request, HttpServletResponse response)
throws Exception
{
GenericDelegator delegator = GenericDelegator.getGenericDelegator("default");
Iterator custs = UtilMisc.toIterator(delegator.findAll("StudyCustomer",UtilMisc.toList("customerId","customerName","customerNote")));

Collection col = new ArrayList();

while(custs.hasNext())
{
GenericValue cust = (GenericValue)custs.next();
col.add(cust);

}

request.getSession().setAttribute("search_results",col);

return "success";
}

public static String findRecord(HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String id = (String)request.getParameter("customerId");

GenericDelegator delegator = GenericDelegator.getGenericDelegator("default");

try {
GenericValue cust = delegator.findByPrimaryKey("StudyCustomer",UtilMisc.toMap("customerId",id));

request.getSession().setAttribute("edit_cust",cust);
} catch (GenericEntityException gee) {
Debug.logWarning(gee);
}

return "success";
}

public static String updateRecord(HttpServletRequest request, HttpServletResponse response)
throws Exception
{
Map paras = UtilMisc.getParameterMap(request);

GenericDelegator delegator = GenericDelegator.getGenericDelegator("default");
GenericValue cust = delegator.findByPrimaryKey("StudyCustomer",UtilMisc.toMap("customerId",paras.get("customerId")));
cust.setNonPKFields(paras);
cust.store();

request.getSession().setAttribute("edit_cust",cust);

return "success";
}

public static String removeRecord(HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String strId = request.getParameter("id");
GenericDelegator delegator = GenericDelegator.getGenericDelegator("default");
GenericValue cust = delegator.findByPrimaryKey("StudyCustomer",UtilMisc.toMap("customerId",strId));
cust.remove();

return "success";
}

}


>=================================================================


程序中的处理大部分可以看懂的,其中有个功能,是
Map paras = UtilMisc.getParameterMap(request);
这是 Ofbiz 的一个有趣但非常有用的功能,它是把 request 中各段的名字和值映射到一个 Map
对象中,然后使用
cust.setNonPKFields(paras);
就可以赋给 Object cust 的各个段,免了我们使用 request.getParameter("name")来取各个
值,在值很多的时候这个功能可以大大减少冗余代码量。

基本程序的逻辑是这样的,
1.从 request 读取传来的值
 2.使用 delegator 来处理,Add/Update/Delete/Query
3.将返回结果放到 Session 中传给 JSP

我做了个 Ant build.xml 文件可以帮助编译,把这个文件放在:
c:\ofbiz\ofbiz\testOfbiz\ 目录下,然后在命令行窗口下进入该目录,敲入 ant
来编译(需要保证已经安装 Ant),编译后的 .class 会放在
c:\ofbiz\ofbiz\testOfbiz\com\geeyo\ofbiz 下,
拷贝 c:\ofbiz\ofbiz\testofbiz\com 目录到 c:\ofbiz\ofbiz\partymgr\webapp\WEB-INF\classes
目录下。

build.xml
>=============================================================================

<project name="TestOfbiz" default="dist" basedir=".">
<description>
Test ofbiz
</description>

<!--test cvs-->
<!-- set global properties for this build -->

<property name="src" location="."/>
<property name="build" location="."/>

<property name="lib_dir" location="c:/ofbiz/catalina/shared/lib"/>
<property name="lib1_dir" location="c:/ofbiz/catalina/common/lib"/>

<path id="project.class.path">
<fileset dir="${lib_dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${lib1_dir}">
<include name="*.jar"/>
</fileset>
</path>

<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>

<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}">
<classpath refid="project.class.path"/>
</javac>
</target>

<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
</target>

<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
</target>
</project>


>=============================================================================

然后我们来创建 JSP 程序,JSP 程序全部放在
c:\ofbiz\ofbiz\partymgr\webapp\party 下面

1.listofbiz.jsp
>=============================================================================

<%@ taglib uri="ofbizTags" prefix="ofbiz" %>

<%@ page import="java.util.*, org.ofbiz.core.service.ModelService" %>
<%@ page import="org.ofbiz.core.util.*, org.ofbiz.core.pseudotag.*" %>
<%@ page import="org.ofbiz.core.entity.*" %>
<jsp:useBean id="security" type="org.ofbiz.core.security.Security" scope="request" />
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />

<script language="JavaScript">
function confirmDelete()
{
return confirm("Are your sure to delete?");
}
</script>


<%if(security.hasEntityPermission("PARTYMGR", "_VIEW", session)) {%>

<table width="600" align="center">
<ofbiz:if name="search_results">
<tr><th>Id</th><th>Name</th><th>Note</th><th></th></tr>
<ofbiz:iterator name="cust" property="search_results">
<tr>
<td><ofbiz:entityfield attribute="cust" field="customerId"/></td>
<td><ofbiz:entityfield attribute="cust" field="customerName"/></td>
<td><ofbiz:entityfield attribute="cust" field="customerNote"/></td>
<td>
<a href='<ofbiz:url>/showtest?customerId=<ofbiz:entityfield attribute="cust" field="customerId"/></ofbiz:url>' class="buttontext">[Edit]</a>
<a href='<ofbiz:url>/removetest?customerId=<ofbiz:entityfield attribute="cust" field="customerId"/></ofbiz:url>' class="buttontext" onclick="return confirmDelete()">[Remove]</a>
</td>
</tr>
</ofbiz:iterator>
</ofbiz:if>
</table>
<table width="200" align="center">
<tr>
<td><a href='<ofbiz:url>/createTestForm</ofbiz:url>'>Create customer</a></td>
</tr>
</table>

<%}else{%>
<h3>You do not have permission to view this page. ("PARTYMGR_VIEW" or "PARTYMGR_ADMIN" needed)</h3>
<%}%>

>=============================================================================

上面程序中需要说明的是
<ofbiz:if name="search_results">

<ofbiz:iterator name="cust" property="search_results">,

<ofbiz:if name="search_results"> 是用来检验在 session 或 pageContext 对象
中是否包含 search_results 对象,该对象是由我们的程序放到 session 中的。
<ofbiz:iterator name="cust" property="search_results"> 是用来循环读取对象
search_results(是个 Collection 对象)中存储的各对象,并赋给cust,然后在循环体
中,我们就可以用 cust 对象来读取各个段的值了。


2.createofbiz.jsp
>=============================================================================

<%@ taglib uri="ofbizTags" prefix="ofbiz" %>

<%@ page import="java.util.*, org.ofbiz.core.service.ModelService" %>
<%@ page import="org.ofbiz.core.util.*, org.ofbiz.core.pseudotag.*" %>
<%@ page import="org.ofbiz.core.entity.*" %>
<jsp:useBean id="security" type="org.ofbiz.core.security.Security" scope="request" />
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<%if(security.hasEntityPermission("PARTYMGR", "_VIEW", session)) {%>

<form method="post" action="<ofbiz:url>/createTest</ofbiz:url>" name="createofbiz">
<table width="300" align="center">
<tr>
<td>Id</td><td><input type="text" name="customerId" size="20"></td>
</tr>
<tr>
<td>Name</td><td><input type="text" name="customerName" size="20"></td>
</tr>
<tr>
<td>Note</td><td><input type="text" name="customerNote" size="30"></td>
</tr>
<tr>
<td></td>
<td><input type="submit"></td>
</tr>
</table>
</form>

<%}else{%>
<h3>You do not have permission to view this page. ("PARTYMGR_VIEW" or "PARTYMGR_ADMIN" needed)</h3>
<%}%>
>=============================================================================

这个程序很容易理解,需要注意的是每个文本框的名字,要跟 Schema StudyCustomer 的各
个段一致,以使程序中跟容易处理。

3.showofbiz.jsp
>=============================================================================

<%@ taglib uri="ofbizTags" prefix="ofbiz" %>

<%@ page import="java.util.*, org.ofbiz.core.service.ModelService" %>
<%@ page import="org.ofbiz.core.util.*, org.ofbiz.core.pseudotag.*" %>
<%@ page import="org.ofbiz.core.entity.*" %>
<jsp:useBean id="security" type="org.ofbiz.core.security.Security" scope="request" />
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<%if(security.hasEntityPermission("PARTYMGR", "_VIEW", session)) {%>

<form method="post" action="<ofbiz:url>/updateTest</ofbiz:url>" name="updateofbiz">
<table width="300" align="center">
<tr>
<td>Id</td><td><input type="text" name="customerId" size="20" value="<ofbiz:entityfield attribute="edit_cust" field="customerId"/>"></td>
</tr>
<tr>
<td>Name</td><td><input type="text" name="customerName" size="20" value="<ofbiz:entityfield attribute="edit_cust" field="customerName"/>"></td>
</tr>
<tr>
<td>Note</td><td><input type="text" name="customerNote" size="30" value="<ofbiz:entityfield attribute="edit_cust" field="customerNote"/>"></td>
</tr>
<tr>
<td></td>
<td><input type="submit"></td>
</tr>
</table>
</form>

<%}else{%>
<h3>You do not have permission to view this page. ("PARTYMGR_VIEW" or "PARTYMGR_ADMIN" needed)</h3>
<%}%>

>=============================================================================

这个程序中,主要是通过
<ofbiz:entityfield attribute="edit_cust" field="customerId"/>
把取到的对象的段显示出来, 对象 edit_cust 是我们在程序中取到并放到 session 中的。

下面我们来配置 controller.xml 和 regions.xml, 在 controller.xml 中加入:
>=============================================================================

<request-map uri="createTestForm">
<description>Show the create form</description>
<security https="false" auth="false"/>
<response name="success" type="view" value="createTestForm"/>
</request-map>

<request-map uri="testofbiz">
<description>Test Ofbiz</description>
<security https="false" auth="false"/>
<response name="success" type="view" value="testofbiz"/>
</request-map>

<request-map uri="listtest">
<description>List all records</description>
<security https="false" auth="false"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="lookAllRecords" />
<response name="success" type="view" value="listAllTest"/>
</request-map>

<request-map uri="showtest">
<description>Show records</description>
<security https="false" auth="false"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="findRecord" />
<response name="success" type="view" value="showTest"/>
</request-map>

<request-map uri="createTest">
<security https="true" auth="true"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="createNewRecord"/>
<response name="success" type="request" value="listtest"/>
<response name="error" type="view" value="createTestForm"/>
</request-map>

<request-map uri="updateTest">
<description>update a record</description>
<security https="false" auth="false"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="updateRecord" />
<response name="success" type="request" value="listtest"/>
</request-map>

<request-map uri="removetest">
<description>remove a record</description>
<security https="false" auth="false"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="removeRecord" />
<response name="success" type="request" value="listtest"/>
</request-map>

<view-map name="listAllTest" type="region"/>
<view-map name="createTestForm" type="region"/>
<view-map name="showTest" type="region"/>
>=============================================================================

在 regions.xml 中加入:
>=============================================================================
<define id='createTestForm' region='MAIN_REGION'>
<put section='title'>Create Ofbiz</put>
<put section='content' content='/party/createofbiz.jsp'/>
</define>

<define id='listAllTest' region='MAIN_REGION'>
<put section='title'>List Ofbiz</put>
<put section='content' content='/party/listofbiz.jsp'/>
</define>

<define id='showTest' region='MAIN_REGION'>
<put section='title'>Show Ofbiz</put>
<put section='content' content='/party/showofbiz.jsp'/>
</define>

>=============================================================================

现在就完成了,我们重新启动 Ofbiz,然后用 IE 访问:
http://localhost:8080/partymgr/control/listtest,用admin/ofbiz 登录后就可以
看到我们刚才的工作成果了,你现在可以增加/删除/修改记录。


6.Ofbiz 通过 XML 来完成数据库操作(非常强大的功能)

这是 Ofbiz 的一个非常强大的功能,可能通过简单的 XML 文件来完成数据增/删/改的处理,
这些处理在数据库应用中是非常多的,因为很多需要维护的数据,所以写程序也是最花时间的,
Ofbiz 把这些操作通过 XML 来完成,不能不说是一大革命---使我们不用写程序就可以完成大
部分处理,这是每个程序员都向往的终极目标。

我们下面举例来讲述一下,处理的数据还是利用我们前面创建的 StudyCustomer,使用 XML
配置文件来完成前面程序 TestOfbiz.java 的大部分操作。

在 c:\ofbiz\ofbiz\testOfbiz\com\geeyo\ofbiz 目录下创建文件 TestOfbizServices.xml,
该文件的内容如下:

>=================================================================

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE simple-methods PUBLIC "-//OFBiz//DTD Simple Methods//EN" "http://www.ofbiz.org/dtds/simple-methods.dtd">

<simple-methods>

<!-- TestOfbiz methods -->
<simple-method method-name="createNewRecord" short-description="Create a new record">
<check-permission permission="STUDYCUSTOMER" action="_CREATE"><fail-message message="Security Error: to run createRecord you must have the STUDYCUSTOMER_CREATE permission"/></check-permission> <check-errors/>

<make-value entity-name="StudyCustomer" value-name="newEntity"/>
<set-pk-fields map-name="parameters" value-name="newEntity"/>
<set-nonpk-fields map-name="parameters" value-name="newEntity"/>

<create-value value-name="newEntity"/>
</simple-method>
<simple-method method-name="updateRecord" short-description="Update a record">
<check-permission permission="STUDYCUSTOMER" action="_UPDATE"><fail-message message="Security Error: to run updateRecord you must have the STUDYCUSTOMER_UPDATE permission"/></check-permission>

<check-errors/>

<make-value entity-name="StudyCustomer" value-name="lookupPKMap"/>
<set-pk-fields map-name="parameters" value-name="lookupPKMap"/>
<find-by-primary-key entity-name="StudyCustomer" map-name="lookupPKMap" value-name="lookedUpValue"/>
<set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>

<store-value value-name="lookedUpValue"/>
</simple-method>

<simple-method method-name="findRecord" short-description="lookup a record">
<check-errors/>

<make-value entity-name="StudyCustomer" value-name="lookupPKMap"/>
<set-pk-fields map-name="parameters" value-name="lookupPKMap"/>
<find-by-primary-key entity-name="StudyCustomer" map-name="lookupPKMap" value-name="edit_cust"/>
<field-to-session field-name="edit_cust"/>
</simple-method>

<simple-method method-name="removeRecord" short-description="Delete a record">
<check-permission permission="STUDYCUSTOMER" action="_DELETE"><fail-message message="Security Error: to run deleteRecord you must have the STUDYCUSTOMER_DELETE permission"/></check-permission>
<check-errors/>

<make-value entity-name="StudyCustomer" value-name="lookupPKMap"/>
<set-pk-fields map-name="parameters" value-name="lookupPKMap"/>
<find-by-primary-key entity-name="StudyCustomer" map-name="lookupPKMap" value-name="lookedUpValue"/>
<remove-value value-name="lookedUpValue"/>
</simple-method>

<simple-method method-name="lookAllRecords" short-description="lookup suitable records">
<check-errors/>
<find-by-and entity-name="StudyCustomer" list-name="search_results"/>
<field-to-session field-name="search_results"/>
</simple-method>

</simple-methods>


>=================================================================

上面的 XML 基本是不用解释的,定义了

createNewRecord
updateRecord
lookAllRecords
removeRecord
findRecord

这几个方法,而且都有对用户权限的检查,这几个方法对应于前面 TestOfbiz.java 中的几个方法,
这样来做数据库操作显然比用 Java 程序写要简单得多,

下面还需要在 controller.xml(具体文件得位置请参照前面的教程)更改一下 mapping 的设置,
更改如下,以前使用 TestOfbiz.java 时的配置我以注释的方式保留着以做参照:

>=================================================================

<request-map uri="createTestForm">
<description>Show the create form</description>
<security https="false" auth="false"/>
<response name="success" type="view" value="createTestForm"/>
</request-map>

<request-map uri="listtest">
<description>List all records</description>
<security https="false" auth="false"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="lookAllRecords" />
<response name="success" type="view" value="listAllTest"/>
</request-map>

<request-map uri="showtest">
<description>Show records</description>
<security https="false" auth="false"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="findRecord" />
<response name="success" type="view" value="showTest"/>
</request-map>

<request-map uri="createTest">
<security https="true" auth="true"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="createNewRecord"/>
<response name="success" type="request" value="listtest"/>
<response name="error" type="view" value="createTestForm"/>
</request-map>

<request-map uri="updateTest">
<description>update a record</description>
<security https="false" auth="false"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="updateRecord" />
<response name="success" type="request" value="listtest"/>
</request-map>

<request-map uri="removetest">
<description>remove a record</description>
<security https="false" auth="false"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="removeRecord" />
<response name="success" type="request" value="listtest"/>
</request-map>

<view-map name="listAllTest" type="region"/>
<view-map name="createTestForm" type="region"/>
<view-map name="testofbiz" type="region"/>
<view-map name="showTest" type="region"/>

>=================================================================

配置该文件的方法请参照前面的教程,regions.xml 不需改动。

配置完后请用前面讲过的方法访问 URL: http://localhost:8080/partymgr/control/listtest

现在我们可以看到,Ofbiz 在 MVC 方面做得非常好,我们可以把后端的处理程序从 java 改
成用 XMl 控制,而其他部分(像 JSP)不需任何改动,这可以保证我们系统各部分的独立性。
完全开放Java源代码的努力终于要结束了。在Sun公司于2006年JavaOne会议上宣布它将免费提供Java,并且根据通用公共许可证开放 Java源代码的计划之后,在开放源代码的道路上一直存在一些斗争。在去年五月发布OpenJDK的时候,大约5%的代码仍然是封闭的。这部分代码不归 Sun所有。

 Sun首席开源软件官员Simon Phipps说:"我们根据通用公共许可证发布我们有权发布的一切东西。这是去年夏季的事情。还有一些源代码没有公开。一种源代码与光栅图形和2D图形有 关。拥有这些源代码的公司不允许我们公开这些源代码。我们与这些公司进行了谈判,因为这些公司曾说,'你可以开放这些源代码,我可以告你破解代码。'"

 Phipps表示,"现在剩下的一些没有公开的源代码是Java中与声音有关的组件。我们最终决定,有关厂商如果不合作的话,我们将从头开始编写这些代码。这项工作将在未来几个月内完成。"

 Phipps称,Java将在未来几个月内完全开放源代码。他说,"我预计这个时间是在今年年底,也许会更快一些。我们将拥有根据通用公共许可证授权的全部Java源代码。"

继Sun在JavaOne 2006上宣布Java将完全开源并使用GPL协议后,其在开源之路上却走了一些弯路。当OpenJDK在去年5月发布后,仍然有5%左右不属于SUN的源代码并未开放。

Sun微系统公司开源办公室主任Simon Phipps说:“从去年夏天开始,我们已经遵循GPL协议开放了所有我们有权利开放的部分。但有两项却不会开源,第一个是在光栅图形学和2D图像领域, 其所有权归另外一家公司,而他们并不希望开放其中的代码。我们正在与他们进行谈判,因为之前他们曾经表示过:‘是的,你们可以开放源代码’,而我能告诉你 们的是他们正在编写解码器。”

另一个尚未开源的部分是Java中与音频相关的组件。我们最终决定,由于其提供商的代码复杂难懂,并且不准备参与此项计划,我们将从头开始重新编写,这项工作将在未来几个月内完成。

Phipps表示Java将在未来几个月内真正变成完全开源的项目。“我们预期在今年年底或者更早之前将所有Java代码在GPL协议下开放。”他说。

红帽也在2007年6月对外界宣布了IcedTea项目,目标是让OpenJDK成为Fedora或者其他Linux发行版本的一部分,不受任何限制。

IcedTea项目已经在本周取得了突破性进展,最新的OpenJDK二进制代码已经通过Java Test Compatibility Kit(一套工具,用来验证是否与Java规范一致)的测试并集成至Fedora 9中。

OpenJDK现在已经是Fedora 9的一部分,包括所有Java SE 6中必需的API。而其计划的最新目标是让OpenJDK完全集成至下一代的红帽Linux企业版-5.3中。(eNet)

Java is Finally Free and Open

| No Comments | No TrackBacks

At JavaOne in May, 2006, Sun Microsystems announced they were going to release Java as free software under the terms of the GPL. The size of the task (6.5 million lines of code) was only eclipsed by the size of the opportunity for Java as a free and open technology.

At JavaOne in May 2007, Sun announced that the work was largely completed and so OpenJDK was launched. What was less newsworthy was the fact that on release - OpenJDK still relied on code that was encumbered - between 4 and 5 percent of the code was closed, non free source that Sun didn't own.(via Dzone)

据Evans Data本周二发表的调查报告显示,移动版本.Net和Java目前是无线应用程序开发人员首选的平台.但是,新进入这个领域的Mac OS和Android预计将加快增长.

调查显示,43%的开发人员选择微软的.Net Compact Framework平台,42%的开发人员选择Java ME平台.这次调查是在今年5月和6月实施的,调查了全球各地的384位开发人员.

这次调查的排名还包括:31%的开发人员选择Windows Mobile 6.0、以下依次排列是Linux(25%)、诺基亚Series 80(22%)、Symbian(20%)、Windows Mobile 5.0(19%)、Java(18%)、Palm OS(15%)、RIM OS(14%)、Mac OS 10(8%)、Android(7%).

Evans总裁兼首席执行官John Andrews本周一在接受采访时表示,包含苹果流行的iPhone设备的Mac OS X的开发和谷歌领导的Android移动平台计划预计将日益流行.他说,我们并不认为这些数字是负面的.事实上,我们认为这些数字是积极地,因为这些平台 还在生命周期的早期阶段.

这次调查的开发人员有5%是制作基于浏览器或者网络内容的应用程序.30%的开发人员是开发商务应用程序.24%的受访者是制作无线门户应用程序.24%的人是在开发CRM系统.

这次调查中说到的目标硬件平台包括诺基亚(56%)、摩托罗拉(33%)和索尼爱立信(29%).(csdn)

NetBeans IDE 是一个为软件开发者提供的自由、开源的集成开发环境。您可以从中获得您所需要的所有工具,用 Java、C/C++ 甚至是 Ruby 来创建专业的桌面应用程序、企业应用程序、web 和移动应用程序。此 IDE 可以在多种平台上运行,包括 Windows、Linux、Mac OS X 以及 Solaris;它易于安装且非常方便使用。6.0 发行版包含了重要的增强功能和新特性,包括完全重写的编辑器基础结构、对扩展语言的支持、新的生产率特性,以及一个能让您根据实际需求安装并配置 IDE 的简化安装过程。

主要更新:



  • JavaScript Support

  • Semantic Highlighting

  • Code Completion and Type Analysis

  • Quick Fixes and Semantic Checks

  • Refactoring 

  • Performance Enhancements

  • Up to 40% faster startup

  • Smarter parsing so that code completion is faster

  • Less memory consumption 

  • Spring Framework Support

  • Bundled Spring Framework 2.5 library

  • Wizards for XML configuration files and Spring Web MVC controllers

  • Code completion of bean names and Java classes and properties

  • Spring Web MVC framework support in web project


  • 查看详情...

    NetBeans 6.1 用于 Windows 上的安装程序/简体中文 (zh_CN)
    netbeans-6.1-ml-windows.exe (217.8 MB)

    MD5: 27f90d05404bafb252a597cb7416c644下载页面:http://dlc.sun.com.edgesuite.net/netbeans/6.1/final/
    下载地址:http://dlc.sun.com.edgesuite.net/netbeans/6.1/final/bundles/netbeans-6.1-ml-windows.exe
    (cnBeta)

    相关归档

    当前归档JAVA

    上一归档:J2EE

    下一归档:JAVASCRIPT