Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Posted in Uncategorized | 1 Comment

A special day

Today is my last day in Sybase, it is special ’cause it labels the end of a wonderful period in my life that i shall always remember.
 
I wanna say i have somewhat established a sturdy connection with Sybase, with the people i loved there and with the the spirts i undertook for the last 3 years. I still couldn’t believe it is now the time for me to say goodbye, but that’s just life, isn’t it? I’m not certain whether i have the chance to meet those beautiful faces again, but what i do know for sure is, those faces and the moments that they connected will always be remembered.
 
"All my best memories
Come back clearly to me
Some can even make me cry
Just like before
It’s yesterday once more…"
 
Anyway, it’s also time to move on, to break a new path and to live a new life… cheers!!
 
 
 
Posted in Uncategorized | 5 Comments

How to Create Context Menu for CommonViewer

As we are moving from eclipse3.1 to eclipse3.3 and beyond, the well-known Common Navigator Framework (CNF) are more commonly utilized to serve the needs of providing a robust and loosely coupled content view structure.

However, the inherent design of the CommonNavigator requests each of its instances maintain their action service and composing viewer separately. In other words, if we want to reuse the common viewer by instantiating one outside of its Navigator scope like wizard page or JFace dialog, we would encounter the bottleneck of reusing the viewer’s associated action service.

Therefore, to achieve adding context menu to a reused common viewer, we have to programmatically constitute the context menu and hook up action service from the navigator.

The following code snippet simply returns an instance of CommonViewer for reuse purpose.

public static CommonViewer createEEViewer(Composite content, int aStyle) {
                CommonViewer commonViewer = new CommonViewer(
                                SuadeServersPlugin.SERVERS_VIEW_VIEWER_ID, content, aStyle);
 
 
                return commonViewer;
        }

 After getting the CommonViewer, we have to programmatically create a context menu manager, get the actionService from the Navigator, and hook it into the context menu. The following section illustrate how to implement a context menu on CommonViewer in a wizard page.

private void createContextMenu(final CommonViewer viewer) {
                MenuManager menuMgr = new MenuManager();
                menuMgr.setRemoveAllWhenShown(true);
                menuMgr.addMenuListener(new IMenuListener() {
                        CommonNavigator eeView = (CommonNavigator) PlatformUI
                                        .getWorkbench().getActiveWorkbenchWindow().getActivePage()
                                        .findView(SuadeServersPlugin.SERVERS_VIEW_VIEWER_ID);
 
                        public void menuAboutToShow(IMenuManager manager) {
                                ISelection selection = viewer.getSelection();
                                eeView.getNavigatorActionService().setContext(
                                                new ActionContext(selection));
                                eeView.getNavigatorActionService().fillContextMenu(manager);
 
                        }
                });
 
                Menu menu = menuMgr.createContextMenu(viewer.getTree());
                viewer.getTree().setMenu(menu);
        }
Posted in Eclipse Plugin/RCP | 2 Comments

Sample Usage of IExtensionStateModel

Description/Implementation

IExtensionStateModel is a fairly useful feature in Common Navigator Framework that we could make use of when dealing with multiple content provider.

It allows clients to coordinate state across components that are part of the same logical extension.[1]

That is, a content provider might vary how it exposes its content based on the state of a specific property in the model. Interested parties may add themselves as IPropertyChangeListener to track changes in the state model.

For example, if we want multiple content provider to take instant adjustments and refresh themselves within a specific scope of tree structure and based on a centralized state change, say a Boolean value on one extension, we could simply register a Boolean value to a specific IExtensionStateModel of the sharing content service

  public void init(IViewPart view) {

                this.view = view;
                if (view instanceof CommonNavigator) {
                IExtensionStateModel stateModel = ((CommonNavigator)view).getNavigatorContentService().findStateModel(DSEPlugin.SERVERS_VIEW_CONTENT_EXTENSION_ID);
                        stateModel.setBooleanProperty(DSEPlugin.PROP_SHOW_CATEGORIES,
                                        currentState);
                }
        }
 
  /*
         * The state model stores properties associated with the extension. Each
         * content extension has its own contained state model. Components of the
         * extension (content provider, label provider, action providers, etc) may
         * attach themselves as listeners to the model
         * and respond to changes to the values of the properties.
         *
         * @param anExtensionId
         *            The extension id defined by a navigatorContent
         *            extension.
         * @return The state model for the given extension id.
         */
IExtensionStateModel findStateModel(String anExtensionId);

 

Then IPropertyChangeListener could be added from another contentProvider to receive notification on the state model change, and take corresponding adjustments.

  private IPropertyChangeListener mPropertyChangeListener = new IPropertyChangeListener() {
 
                public void propertyChange(PropertyChangeEvent event) {
                        //DO something
                }
        };
 
if (mViewer instanceof CommonViewer) {
                IExtensionStateModel stateModel = ((CommonViewer) mViewer)
                                .getNavigatorContentService().findStateModel(
                                                DSE_VIEW_CONTENT_EXTENSION_ID);
                stateModel.addPropertyChangeListener(mPropertyChangeListener);
               
        }


[1] Eclipse Platform API specification – IExtensionStateModel

Posted in Eclipse Plugin/RCP | Leave a comment

Service Component Architecture

Service Component Architecture

Level: Advanced

Contributors: BEA Systems, IBM, IONA, Oracle, SAP AG, Siebel Systems, Sybase

In response to requests from customers and Independent Software Vendor (ISV) partners, BEA, IBM, IONA, Oracle, SAP, Siebel Systems, and Sybase are collaborating on specifications for building systems that use a Service-Oriented Architecture (SOA), which aim to provide developers with simpler and more powerful ways of constructing applications based on SOA. These specifications are published under royalty-free terms.

Service Component Architecture: Build systems using SOA

Service Component Architecture (SCA) is a set of specifications which describe a model for building applications and systems using a Service-Oriented Architecture. SCA extends and complements prior approaches to implementing services, and SCA builds on open standards such as Web services.

SCA encourages an SOA organization of business application code based on components that implement business logic, which offer their capabilities through service-oriented interfaces and which consume functions offered by other components through service-oriented interfaces, called service references. SCA divides up the steps in building a service-oriented application into two major parts:

  • The implementation of components which provide services and consume other services
  • The assembly of sets of components to build business applications, through the wiring of service references to services.

SCA emphasizes the decoupling of service implementation and of service assembly from the details of infrastructure capabilities and from the details of the access methods used to invoke services. SCA components operate at a business level and use a minimum of middleware APIs.
Figure 1. Service Component Architecture
Service Component Architecture

SCA supports service implementations written using any one of many programming languages, both including conventional object-oriented and procedural languages such as Java™, PHP, C++, COBOL, XML-centric languages such as BPEL and XSLT, and also declarative languages such as SQL and XQuery. SCA also supports a range of programming styles, including asynchronous and message-oriented styles, in addition to the synchronous call-and-return style.

SCA supports bindings to a wide range of access mechanisms used to invoke services. These include Web services, Messaging systems and CORBA IIOP. Bindings are handled declaratively and are independent of the implementation code. Infrastructure capabilities, such as Security, Transactions and the use of Reliable Messaging are also handled declaratively and are separated from the implementation code. SCA defines the usage of infrastructure capabilities through the use of Policies, which are designed to simplify the mechanism by which the capabilities are applied to business systems.

SCA also promotes the use of Service Data Objects to represent the business data that forms the parameters and return values of services, providing uniform access to business data to complement the uniform access to business services offered by SCA itself.

The SCA specification is divided into a number of documents, each dealing with a different aspect of SCA. The Assembly Model deals with the linking of components through wiring. The Assembly Model is independent of implementation language. The Client and Implementation specification deals with the implementation of services and of service clients — each implementation language has its own Client and Implementation specification, which describes the SCA model for that language.

The current SCA specifications are published at a version 0.9 level, indicating that the specifications are not in their final form. The specifications are published with the intent of getting feedback from the community in order to ensure that the eventual version 1.0 level of the specifications more fully meets the needs of developers and businesses.

Posted in SOA | 4 Comments

Memo: Setting up an OpenLDAP server

To create and run an LDAP server, you must first download and install OpenLDAP to your hard-disk.

After installation, you need to do some configuration settings:

  1. Copy the sybase.schema file into the schema folder
  2. Modify the slapd.conf file:
    • include "sybase.schema"
    • define BDB settings(suffix, rootdn & rootpw), the rootdn is the DN that you would specify with the -D option when adding an entry
    • specify other settings if it is needed(e.g. sizelimit, access control)
  3. Run the server using "slapd -d 1" command, this will parse the configuration file and initialize all the settings 
  4. Add initial entries to your directory:
    • create an LDIF file (e.g. sybase.ldif), define the entries info into the ldif file. Make sure you start adding from a top-down sequence and don’t violet the objectClass settings.
    • run command "ldapadd -D [rootdn] -w [rootpw] -f [file name]" to add the entries (for example: ldapadd -D "cn=Test,dc=sybase,dc=com" -w secret -f sybase.ldif)

      If success, you will be able to browse the results through "ldapsearch -x -b ‘dc=sybase,dc=com’ ‘(objectclass=*)"

Posted in Open Source | Leave a comment

webapp连MySQL 中文乱码问题总结

困扰了我两天的MySQL乱码问题终于攻破,在此自我陶醉一下。哎,可惜了当时在场的3人无人能体会此项伟大突破的历史意义。
 
anyway 还是值得总结一下。
 
mysql字符集机制设定的“独特性”让我这个原先自认为精通webapp乱码问题的人也头痛了一番。
 
它的独特性体现在已下几个方面:
  1. 存在不同级别的默认设置。MySQL4.0以后的对数据库字符集存在4+1个级别的支持。
    a) 系统级:由/etc/my.cf;windows下为%MySQLHOMEmy.ini 系统配置文件定义
    b) character_set_server(服务器):这是设置服务器使用的字符集
    c) character_set_client(客户端) :这是设置客户端发送查询使用的字符集
    d) character_set_connection:这是设置服务器需要将收到的查询串转换成的字符集
    e) character_set_results :这是设置服务器要将结果数据转换到的字符集,转换后才发送给客户端
  2.  特殊的字符集转换流程。
    client(如servlet)发送一个查询 -> 服务器收到查询,将查询串从character_set_client 转换到character_set_connection,然后执行转换后的查询 -> 服务器将结果数据转换到character_set_results字符集后发送回客户端。

 mySQL乱码问题分析解决:

  • 假设在webapp应用中的所有jsp页面都采用gb2312编码,并构建全局过滤器过滤所有请求的编码格式为gb2312。
  • MySQL用 alter database dbName character set gb2312 修改了数据库的字符集编码,以存放中文字符。
  • 那么在正常情况下,查看数据库各级别字符集支持 mysql> SHOW VARIABLES LIKE ‘character_set_%’;
    mysql> SHOW VARIABLES LIKE ‘collation_%’;
    会发现所有级别默认设定为UTF-8,在CRUD操作过程中这当然会导致编码冲突并产生乱码。
  • 那么我们自然会想到将所有级别的字符集设定为gb2312。
    set character_set_client = gb2312
    set character_set_server = gb2312
    set character_set_connection = gb2312
    set character_set_results = gb2312
  • ok 设定完后,调试发现仍然存在乱码? 那么这是为什么?其实问题出在系统级的字符集设定上。我的理解是,当client(这里当然就是webapp)以任何方式与MySQL建立请求,并用SQL进行CRUD操作时,系统会预先由MySQL的预设系统级字符编码(latin)来做一次转换。那么原先按gb2312编码的字符会被按照latin来解码,这时的字符已经为乱码。
  • 所以,必须去修改my.ini文件里的 default-character-set=gb2312 或者在命令行输入mysqld –default-character-set=latin1

不查manual的话,这最后的一条还真是很难想到。

实际项目过程中确实会碰到许多问题并逐步发掘到需要学习的东西,“实践中学习”这句话说得还是极其有道理的。

prospective topic next week — hibernate + struts应用的lazyinitialization问题

Posted in J2EE | 2 Comments