[Contents] [Previous] [Next] [Index]

## Chapter 2
About the CDK

The Netscape Component Developer's Kit (CDK) offers instruction and examples for creating, installing, using, and deploying Netscape ONE components in Web-based applications built with Netscape tools such as Visual JavaScript (VJS). This Component Developer's Guide, which accompanies the CDK, provides detailed information about the creation, installation, and deployment of Netscape ONE components in Web-based applications.

This guide contains the following sections:

- What Is the CDK? An introduction to the contents of the CDK, including the documentation and sample files.

- What Is a Component? A general overview of component concepts, which is useful if you are unfamiliar with component architecture.

- What Is a Netscape ONE Component? A specific introduction to the platform-independent, open standards of the Netscape ONE component architecture, particularly the JavaScript Bean (JSB) file structure used to describe components for tools like VJS.

- Creating, Installing, and Deploying Netscape ONE Components A guide to using the rest of this document to create, install, and deploy Netscape ONE components.

## What Is the CDK?

The CDK is a set of examples and the Component Developer's Guide that together describe how to shape Netscape ONE components and deploy them to applications using Netscape tools such as VJS.

A Netscape ONE component is any component that adheres to the JavaSoft Bean specification. Each of the following components can be Netscape ONE components:

- JavaScript component, coded as a JavaScript object, complete with properties, events, and methods.A JavaScript component is embedded in a JavaScript Bean (JSB) file.

- JavaBeans component, coded in Java and supplied with a `BeanInfo` class.

- CORBA component, accessed through a CORBA-compliant object request broker (ORB).

- Native component plug-in, such as the multimedia player in Communicator 4.0.

All Netscape ONE components can be described using JSB files. A JSB file is an SGML-based text file that uses a hierarchical set of tags to describe a component and its properties, events, and methods. The JSB file structure is tightly modeled on the JavaBeans specification, but a JSB file can sometimes contain extra tool- or platform-specific information.

Depending on the native language used to create an actual component, a JSB file can consist of either:

- Interface definitions for the component's actual implementation. In this case the actual component is implemented in Java or C++.

- Interface definitions, constructor code, and helper function code. In this case the component is a JavaScript component implemented directly in the constructor code in the JSB.

You can create a JSB file using a text editor. Depending on the type of component and the development tools you use, a JSB file may be created automatically for you. For example, suppose you import a CORBA object into VJS to use in building an application. VJS uses the IDL description of the CORBA object to build a corresponding JSB file--the CORBA component--that becomes part of your VJS project. When you compile your application and deploy it, VJS uses the JSB files to generate appropriate interface code for the component.

The Component Developer's Guide is divided into separate, linked HTML files. Each file describes components derived from different sources (for example, Java, CORBA, or JavaScript), and notes any tool or platform requirements specific to components of that type. Currently, tool discussions are limited to VJS, and platform discussions are based on Netscape Communicator 4.xx unless otherwise noted.

For JavaScript components, the Component Developer's Guide describes how to create and import components into the VJS palette. All other components are created and implemented in a native language, such as Java or C++. The Component Developer's Guide explains how to import these externally derived components into the VJS palette, and notes any special requirements and adaptations that are necessary.

Once you import a component into the palette, you can use it as an application building block, just as you can use the built-in VJS components. To the end user of a VJS application, the originating source of a component does not matter. Once incorporated, all components function transparently.

The CDK contains sample code that implements Java and CORBA objects. You can import these objects into VJS as components. Although in general you can import almost any Java or CORBA object into VJS as a component, the CDK sample code illustrates refinements that you can make to native object code for even tighter integration into a Netscape ONE Internet application.

## What Is a Component?

A component is a modular and reusable unit of programming code, with a clearly designed interface, that you can use as application building blocks. For example, any element of a graphical user interface, such as a window, button or text field, can be represented by a component. A component can also represent nonvisual application elements, such as database or server connections, timers, or internal data structures.

### Component Modularity

A component is modular--or self-contained--because it performs an isolated or discrete task or set of related tasks. For example, a component that represents a button on the screen may manage the appearance of the button, keep track of its state conditions, handle user interactions, and return a result condition.

Task isolation has an added advantage: specific error conditions can be trapped and handled more easily within components. General application logic does not have to be devoted to error trapping and handling, making it easier to maintain and extend the application.

### Component Reusability

Components are reusable because the tasks they perform are generic and narrowly defined, and can be applied in similar manners across applications. For example, a button component behaves in the same manner in any application that employs it. A user can click the button to take an action, and the button responds by executing the action assigned to it by the developer at design time.

### Understanding the Component Interface

An application communicates with the component through a carefully defined interface. The interface prescribes how the component receives information and what information it will return. When you use an existing component, such as the built-in components in VJS, to build an application you need be concerned only with the component's interface, but not with its internal workings. As long as the existing interface does not change, the internal workings of a component can be changed without breaking applications that use it.

In traditional programming parlance, a component interface defines its entry points, the hooks that you use to call into a component in order to execute its tasks. In one sense, a component interface is more sophisticated than traditional entry points: it offers both design-time and run-time elements.

Design-time elements permit you to customize aspects of a component's appearance and behavior during application development. For example, a button component may define an interface element that permits the developer to specify the color of the button face.

Run-time elements enable the application to interact with a component, in response either to user-initiated actions, or to certain predetermined application conditions you set up at design time. For example, a button component typically has a run-time element that responds to a mouse clicks from the user.

When you create your own components you must design an appropriate, flexible, and adaptable interface for others to use, but can hide the actual implementation details from view. A component interface usually has three elements: properties, methods, and events.

#### Working with Properties

From an application developer's view, properties behave very much like function variables. Developers can set or read property values as if they are variables, but properties are more powerful than variables for two reasons:

- Application developers can set properties at design time. Unlike methods, which are available only at run time, properties let the developer customize components while building an application. In VJS, developers can view, set and validate property values in the Inspector.

- Properties can hide implementation details. Properties let developers attach complex effects to outwardly simple assignments. What looks like an assignment to a variable might be a call to a method that implements elaborate processing. For example, data stored internally in an encrypted form can appear unencrypted as the value of a property. Although the value may a simple number, the component may look up the value in a database or perform complex calculations to arrive at it.

#### Working with Methods

A method is run-time interface element. It is a function that operates on data belonging to the component. Application developers use a component's methods to direct the component to perform a special action or return a value not already stored in a component property. Because a method executes code, methods are available only at run time. Methods are useful because they:

- Encapsulate the functionality of a component in the same object where the data resides.

- Can hide complicated procedures under a simple, consistent interface. An application developer can call a component's method without knowing how the method works or how it differs from a similarly named method belonging to another component.

- Allow updating of several properties with a single call.

#### Working with Events

Events are special methods that link a component with an application. Events send information or requests from a component instance to the application that contains and uses the component. For example, when a user clicks a button component, the user action triggers the component's `onClick` event handler.

An event handler can perform two types of actions: internal actions that are the same for each instance of a button component, and external actions that differ by application or even by invocation within an application. For example, suppose an application instantiates two button components. Each button's internal action in response to an `onClick` event might be to display momentarily the button in its clicked state before redisplaying it in its normal state. Externally, the `onClick` event for one button might call a routine that submits the current data on a form to a database for one button, while the `onClick` event for the other button might close the application.

### Components for the Web

Developing components for Web applications adds additional requirements to the component model. Components for the Web must be:

- Operating system(OS) independent. Components must run in any Web-based environment regardless of a system's underlying OS. For example, components written using Java or JavaScript are OS independent.

- Open standards-based. Components must use languages and protocols with published specifications, such as Java and HTML, that are shared across the Internet development community. Adherence to open standards ensures that any corporation's investment in component technology today can be leveraged at all times across all platforms tomorrow.

- Language transparent. Components must either communicate directly with other components and applications written using a variety of programming languages, such as Java or JavaScript, or communicate through commonly shared, and open-standards based protocols, such as CORBA and IIOP.

- Server and client transparent. Components must work across a distributed, heterogeneous network environment, regardless of the underlying hardware and software architectures of each client or server machine involved.

## What Is a Netscape ONE Component?

A Netscape Open Network Environment (ONE) component is a Web-based component that is OS-independent, language transparent, and based on open standards embraced by Netscape and its partners. Using Netscape ONE components, you can build Internet-based applications that:

- are platform-independent
- run in a heterogeneous client-server environment
- communicate using native Internet protocols, such as LDAP and SMTP
- integrate easily with legacy databases
- provide Internet security

Netscape ONE components are modeled on Sun's JavaBeans specification, but the components themselves can be created in Java, JavaScript, and HTML, using a variety of tools. When you create Netscape ONE CORBA components, you can implement the underlying CORBA object itself in C++ or Java.

Once you create a component, you can use it directly in your applications, and you can install it into a palette in VJS, where you can use it over and over again each time you build a new application. You can also develop components and libraries of components for others to use and install in development tools like VJS.

## Creating, Installing, and Deploying Netscape ONE Components

The CDK is about creating, installing, and deploying Netscape ONE components in your Web applications. You create components using different tools and technologies, depending on the source language or protocol for your component. For example, you can use a tool such as Visual Cafe to create JavaBeans components. For CORBA components, you define a CORBA object by creating an IDL file for it, implement the object in C++ or Java, and import the IDL file into VJS to create a corresponding JavaScript wrapper component. You can then use the wrapper component to build applications. To create JavaScript components, you use a text editor to create a JavaScript Bean (JSB) file that describes the component's properties, methods, events, and constructor function, and you install the component into VJS, where you can use it to build applications.

> NOTE: The VJS Developer's Guide describes how to use VJS to develop robust Web applications.

> The Component Developer's Guide is the document that describes what you need to know to create your own Netscape ONE components, install them in the VJS palette where you can use them to build Web applications, and deploy them with the applications you build.

> ### Creating Components

> The process for creating a component differs, depending on whether you use Java or JavaScript to create the component, and whether you are creating a CORBA component that is based on a CORBA object. The CDK documentation describes each creation process in a separate chapter.

> #### Creating Java-based Components

> You create Java-based components using a Java development environment such as Visual Cafe, and the Java Development Kit (JDK) 1.1. Java-based components can be:

> - applets
> - objects
> - JavaBeans
> The Component Developer's Guide assumes you are familiar with creating Java objects, applets, and Beans, so it does not instruct you on creating them. Using Java Objects as Components describes how to adapt Java objects, applets, and Beans for use as Netscape ONE components.

> > NOTE: You can also create JavaScript Bean (JSB) files as wrapper components for Java objects. Using JSB files as wrappers for Java objects enables you to hide component implementation details from the users of your components. For example, this is the only way to work with server-side Java components in VJS, and is typically used with LiveConnect to instantiate a Java class from JavaScript. The intention here is that only part of the underlying class need be exposed through the JSB file as long as the class can be instantiated using the JavaScript new operation. JSB File Structure Reference describes the JSB file format and provides a reference for its syntax.

> #### Creating JavaScript Components

> VJS extends JavaScript by providing a JavaScript Beans (JSB) file format that enables you to create JavaScript components with properties, methods, and events. JSB files provide a convenient way to create reusable units of JavaScript code for commonly used objects, such as buttons, text fields, and radio buttons. Creating JavaScript Components describes how to create JavaScript components using a JSB file. JSB File Structure Reference provides a reference for JSB syntax; the JSB file format is modeled on easily constructed and readable SGML tagging conventions.

> Once you create JavaScript components, you install them into the VJS palette, where you can drag them into your applications and set their properties as appropriate.

> #### Creating CORBA Components

> Netscape ONE makes it possible for you to create CORBA components from your CORBA objects. Creating a CORBA component is a three-step process:

> 1. Create the CORBA object definition using IDL.

> 2. Implement the CORBA object in C++ or Java.

> 3. Import the IDL file into VJS, which automatically generates a corresponding JSB file for the object and installs it into the VJS palette. The resulting CORBA component can be used just like other components in VJS to build your applications.
> Using CORBA Components describes these steps in more detail.

> ### Installing Components in VJS

> To use Netscape ONE components to build Web applications, you should install your components into a VJS palette. In general, Java and JavaScript components that consist of more than one file, such as a Java class that receives support from other Java classes, must be packaged into a JAR file. The JAR file must be installed in VJS. For CORBA objects, the installation process automatically creates a component in VJS from an IDL file. Regardless of the origin of your component, installation is an easy process that is described in general terms in the VJS Developer's Guide. Additional installation guidelines, specific to each type of component, may be found throughout the Component Developer's Guide as indicated below.

> #### Installing Java Components

> Because Java components typically consist of several class files, you must package the files into a JAR file, and then install the JAR file into VJS. Using Java Objects as Components describes the steps necessary for creating a Java component. Packaging Components for Import provides guidelines for using the JDK JAR packager to prepare a component for installation in the VJS palette.

> #### Installing JavaScript Components

> If a JavaScript component consists of a single JSB file, then you can install the component directly into a VJS palette. If your JavaScript component uses JS files to provide additional support routines, then you must package the JSB and JS files into a JAR file before installing the component in VJS. Creating JavaScript Components describes the steps necessary for creating a JavaScript component that consists of a stand-alone JSB file, and it describes how to install it in VJS. Packaging Components for Import provides guidelines for using the JDK JAR packager to prepare a multifile JavaScript component for installation in the VJS palette.

> #### Installing CORBA Components

> A CORBA component does not exist until you install a CORBA object's IDL file into VJS. Installation automatically creates a CORBA component, in the form of a JSB file that correlates to the IDL file. Using CORBA Components describes the installation process.

> ### Deploying Components in Applications

> Application deployment refers to how you package and deliver an application to your users. When you install components into VJS, and use them to build your application, VJS ensures that the necessary code for using the components at run time is automatically inserted into your application's code base. When you package your application, the components it uses are automatically packaged as part of the application.

> VJS manages component deployment based on how you installed the component into VJS itself. If you create components that consist of multiple files, properly package the component and all its support files in a JAR file, and install the JAR file into VJS, then VJS knows exactly how to deploy your component when you build and package your application. Deployment is a straightforward process described in the VJS Developer's Guide.

> [Contents] [Previous] [Next] [Index]

> Last Updated: 11/20/97 13:56:30

> Copyright © 1997 Netscape Communications Corporation