Skip to content

Companies

Using the Accent Color

Microsoft Silverlight content - 5 hours 59 min ago
Learn how to design your Windows Phone applications to take advantage of the accent color....( read more )...(read more)
Categories: Companies

QA#4: Java EE 6: Developers focus on business logic, Much lower TCO - by Johan Vos

Miles to go ... - Arun Gupta - Thu, 07/29/2010 - 00:07

Jigsaw puzzle, modular, standard, integrated specifications, simple, annotation-driven, standards compliance, vendor independence, and light-weight deployment are some of the benefits highlighted by the Java EE 6 community.

In the Java EE 6 Feedback from Community series you can learn about how Java EE 6 is currently being used in production, development and deployment environments used within the community, and even feature requests for Java EE 7.

This entry comes from Johan Vos who started to work with Java in 1995. He worked on the Java Linux port with the Blackdown team. He has been doing Java consulting and development for a number of customers in completely different areas. Over the years, he has been active in a number of Java-based community projects, e.g. OSGi, the Glassfish project and JFXtras.org. With LodgON, the company he co-founded, he is mainly working on Java solutions for social networking software. Since he can't make a choice between embedded development and enterprise development, his main focus is on end-to-end Java, combining the strengths of back-end systems and embedded devices. His favorite technologies are currently Java EE / Glassfish at the backend and JavaFX at the frond-end.

Here is a short summary of Java EE 6 from him:

Developers can concentrate on business logic, Java EE 6 is providing a standard for the infrastructure

Read on for other fun stuff ...

1. How are you using Java EE 6 today ? What limits your adoption ?

I'm using Java EE 6 in most of the Enterprise projects I'm doing. This is not a requirement, but it turns out that when talking to people about what they really want, the Java EE 6 platform provides lots of the components that are needed to create an end-to-end solution.

Java EE 6 has evolved since the announcement of J2EE. It became more usable, and easier to develop and configure. In the past, a large number of non-standard libraries and frameworks have been developed since J2EE was too complex for most simple problems. The Java EE expert group clearly has learned from these evolutions, and the current Java EE 6 spec provides the functionality that is available in those frameworks, but as a standard. This is a huge benefit.


2. What Java EE 6 technologies are you using and why ?

I often use JPA. In earlier versions of the Java Enterprise standard, it was very hard to use the persistence layer in order to connect to a database. It was often easier to write your own connection pooling system, and perform SQL queries. But with JPA 2.0, it became much easier to manage the persistence.

I'm using (stateless) Session Beans as well, including the new Singleton Bean, combined with the @Startup annotation. The latter makes it much easier to perform tasks that need to be done only once.

I'm also using JAX-RS and Jersey frequently. In particular, I use Jersey for the communication with clients based on XML. The Transaction API is also something that I often use, either explicitly or implicitly.

3. What is your development and deployment environment ?

I'm mainly using NetBeans 6.9 on Linux. I download the full version of NetBeans, since I need both Java EE as well as JavaFX. NetBeans 6.9 comes pre-installed with Glassfish 3.0.1, so there is no need to download a whole application server to start Java EE 6 development.


4. What previous versions of Java EE / J2EE have you used ? How has the migration to Java EE 6 benefited ?

I've been working with Java EE since version J2EE 1.2. I have always avoided to migrate projects from older to newer versions, but I always start new projects on the latest released version. Early version of J2EE required more implementation-specific XML configuration (remember the sun-cmp-mappings.xml), and once you've done this you don't want to change this. Once projects are in deployment, you cannot easily change the runtime procedures.

Operations are often carried out by a different group than the development team. New versions of the J2EE/Java EE standard require changes in development but also in operations.

One of the benefits of Java EE 6, however, is that it also simplify the packaging and deployment procedures. Using annotations in JAX-RS and Servlets, for example, eliminates the need of XML-based configuration files. And often these configuration files make the handover from development to production deployment difficult. Clearly, the TCO for an average Enterprise project can be much lower when using Java EE6.

5. Describe the benefits of Java EE 6 to you in 120 characters.

Developers can concentrate on business logic, JavaEE6 is providing a standard for the infrastructure.


6. Advice for anybody who is looking at Java EE 6 for their next project ?

Use what you need. Nothing less, and nothing more. Although much easier than 10 years ago, Java Enterprise development can be complex. There are 2 situations you have to avoid:

  1. Sometimes, developers don't know about the infrastructure already provided by the Java EE platform, and they are duplicating functionality in their own code. If you look at the JPA and the JTA for example, that provides functionality that is needed in most projects.
  2. In a number of other cases, I see developers using features that are available in the appserver, but that are not needed in their application. The Java EE 6 spec is a composition of a number of specifications, and you don't have to use all the sub-specs.

7.  What new features you'd like to see in Java EE 7 ?

Java EE 6 brought simplicity in complex enterprise applications, and made a significant move towards web-based projects. Indeed, the Java EE 6 specification is rather focused on the Web. While there are many usecases and real-world scenarios that have the Web as the most important client, I think there should be more attention for other clients, i.e. PDA, mobile phone, TV, JavaCard. Easy integration capabilities between those low-resource devices and high-end backend system will drive the adoption of Java EE.

From another point of view, more integration with the environment would be useful. For example, in a number of cases I would like to execute a specific EJB-call once CPU load is below 50%, or once disk usage is too high. I understand this is rather difficult to standardize in a non-platform dependent way.

Thanks you Johan for taking time to prepare the answers!

Are you using, consulting, training, authoring books, etc in Java EE 6 ? Drop a comment on this blog and I'll line you up for the Q&A session :-)

The Java EE 6 hub is your key resource to learn all about the technology.

And you can always try all Java EE 6 features in GlassFish. Here is an extensive of Java EE 6 & GlassFish demos is available.

Technorati: javaee6 community feedback johanvos glassfish v3


Categories: Companies

Announcing Ext JS 3.3 Beta – PivotGrids, Calendars and More

Ext JS - Wed, 07/28/2010 - 22:21
We are pleased to announce the availability of Ext JS 3.3 beta 1 for immediate download. This release introduces great new Calendar and PivotGrid components, plus over 160 enhancements and bug fixes.
Categories: Companies

TeamPulse is LIVE!!

Telerik Blogs - Wed, 07/28/2010 - 18:30
The TeamPulse team is excited to announce that our first official release of TeamPulse is now READY for general download.

Here is a quick summary of the features for the Q2 2010 Release:

 

1. Community and Standard Editions

  • Fully functional Community Edition is free with a limitation of 5 users and 1 project
  • Standard Edition is $249 USD per user

 

2. Requirements

  • Story Management
  • Persona Management

 

3. Planning:

  • Project Release Scheduling
  • Iteration Planning
  • Work Decomposition

 

4. Tracking

  • Project Dashboard
  • Story Board
  • Current Iteration Tracking Grid

 

5. Analyze

  • Best Practice Analyzer

 

You can download TeamPulse here: http://www.telerik.com/team-productivity-tools/download.aspx

 

Benefits of TeamPulse: http://www.telerik.com/team-productivity-tools/benefits.aspx

 

Here is a list of all of our produce videos to date:

 

Check out our product page here: http://www.telerik.com/team-productivity-tools.aspx

 

Don’t ...

Categories: Companies

The new Telerik OpenAccess Schema Update wizard

Telerik Blogs - Wed, 07/28/2010 - 18:00

One of the new features of Telerik OpenAccess ORM Visual designer is the forward mapping wizard that can be used to update the database schema from the model. Yes it is true! With just few clicks you are able to generate and execute either a schema definition or schema update script that will alter you database schema.

First you will need to open our Schema Update Wizard. You can do this by either right clicking in the schema explorer or in the model explorer: the command is named Update Database from Model… This will open the following page:

schemaUpdateWizardFirstPage

On the first page you can select from several schema update strategies (you can do so from the first panel):

  1. Generate schema definition script – Generates a complete schema definition script. This option will not take in consideration the current schema.
  2. Generate schema migration script – Generates a migration script. The migration ...
Categories: Companies

Explained: RadGridView for WinForms virtualization and its implications. The case with CellElement and RowElement

Telerik Blogs - Wed, 07/28/2010 - 17:30

As the Logical vs. Visual Grid Structure help article states, RadGridView for WinForms uses virtualization for its cells/rows and as of Q2 2010 there is column virtualization as well. What is virtualization? To put it simply, when you bind RadGridView to a DataTable with 1000 rows, you get 1000 data row objects created in RadGridView (of type GridViewDataRowInfo). However, not all data row objects can be visible at the same time in the RadGridView estate in your application. This is why only the visual rows that can be shown in the estate get created (these visual rows are of type GridDataRowElement), or about 20-30 rows for an average application with medium sized RadGridView. These visual rows are reused during scrolling, filtering and other operations with the grid, meaning dramatically improved performance and memory footprint as we create only a small number of visual items, rather than all of them. This ...

Categories: Companies

JustMock. The tale continues... (Part 3)

Telerik Blogs - Wed, 07/28/2010 - 17:00

Last time we saw how we can inject code at the beginning of generic methods. Today I will show you how to inject code in properties. I will cover the syntax for static classes as well.

So, let's start with a demo program that I will explain line-by-line.

using System; using Telerik.CodeWeaver.Hook;   namespace ConsoleApplication4 {     public sealed class TargetClass1     {         public TargetClass1(string text)         {             Text = InitText = text;         }           public string InitText { get; private set; }           public string Text { get; private set; }           public int Integer         {             set { throw new NotImplementedException(); }         }     }       public static class TargetStaticClass     {         public static void PrintText(string text)         {             Console.WriteLine(text);         }     }       class Program     {         ...
Categories: Companies

FISL 2010 Trip Report

Miles to go ... - Arun Gupta - Wed, 07/28/2010 - 15:03
4998 attendees registered and participated at the 11th edition of FISL - the biggest open source conference in Brazil. This was my second year at FISL. Even though the attendance was slightly down from last year but there was no let down in the energy. With 13 parallel tracks and sessions running from 9am to 11pm, it can be absolutely overwhelming. However most of the sessions were in Portuguese (with no English translation) so I could not attend.

I presented on the Java EE 6 Toolshow to an audience of approx 200. This slides-free session showed how NetBeans 6.9 provides comprehensive tooling around Java EE 6 and GlassFish 3. The session showed:

  • Simplicity and ease-of-use for creating Java EE 6 web applications
  • Boost productivity using Deploy-on-Save and Session-preservation across multiple redeployments
  • JSP, Servlets 3.0, EJB 3.1 in Java EE 6 web apps
  • Database access using Java Persistence API 2.0
  • Using Facelets with Java Server Faces 2.0
  • Contexts & Dependency Injection 1.0 with JSF 2
  • RESTful Web services using JAX-RS

The screencast #30 made the session delivery quite a breeze and you can watch the entire session by watching the multi-part screencasts.

Meeting Bruno Souza and Fabiane Nardon was a good highlight of the trip. They are both fairly well known in the Brazilian community and we shared stories from last year's presence of Sun Microsystems at FISL. Check out their latest adventure at toolscloud.com where they provide open source tools-based development environment in the cloud.

Personally, I stayed for only couple of days because I had to come back to run a race (more on that in next blog) and attend a wedding over the weekend. A short trip but always good to spend face-to-face time with the local community.

Check out some pictures from the trip:



And the complete album at:


Technorati: conf fisl brazil oracle glassfish javaee6 netbeans


Categories: Companies

View local (offline) help in Visual Studio 2010 with this extension

Microsoft Silverlight content - Wed, 07/28/2010 - 01:15
Although I am involved with content creation (meaning I write the stuff) and not the actual publishing mechanisms for MSDN documentation, I've still heard the rumblings about the new help experience with Visual Studio 2010. A lot of folks don't like the...(read more)
Categories: Companies

Silverlight in Action Book Update

Microsoft Silverlight content - Tue, 07/27/2010 - 21:51
Silverlight in Action, Revised Edition (title likely to be changed to Silverlight 4 in Action) is almost complete. I've turned in all 25 chapters plus appendix, and had them go through editorial review, tech review, and copy editing. All the images are...(read more)
Categories: Companies

New Video Tutorial on Mobile Web Development

The Flash Blog - Lee Brimelow - Tue, 07/27/2010 - 21:45

I just uploaded a new tutorial that shows you how to create a mobile-optimized website using HTML and CSS. The tutorial also highlights the new multi-screen development features of Dreamweaver CS5. It is important to have a strong grasp on standard web technologies as only then can you make an informed decision about when to use Flash.

Categories: Companies

Silverlight and WCF RIA Services (6–Validation)

Microsoft Silverlight content - Tue, 07/27/2010 - 17:37
One of the strengths of WCF RIA Services is in its capabilities around the application of common validation logic on both the client tier and the service tier. If I take the simplest route to create a new Silverlight+RIA Services project as in File |...(read more)
Categories: Companies

New videos for Telerik WebUI Test Studio

Telerik Blogs - Tue, 07/27/2010 - 16:39

The new version of Telerik WebUI Test Studio has been out for a couple of weeks and we have already received a lot of positive feedback on the new features and improvements we have made. We have also produced a lot of new video content to help you get quickly started:

Enjoy all these videos and let us know of any feedback you have. We are always open to your ideas for new features ... and new videos.

Read more on Telerik Automated Testing Tools

Categories: Companies

Silverlight and WebSockets

Microsoft Silverlight content - Tue, 07/27/2010 - 13:03
I was intrigued by this post from Tomek which has links to a prototype of an application built with Silverlight but using WebSockets. It’s kind of interesting because running the application in IE9 gives me; now, the only bit of that application that...(read more)
Categories: Companies

Qt Mobility 1.1.0 Technology Preview

TrollTech Qt Labs Blogs - Tue, 07/27/2010 - 12:09

The Qt Mobility teams are working full steam to bring you new APIs and extend our Qt developer offering.

To that end, we are very pleased to share the Technology Preview of our latest APIs.
This set of new APIs will be matured, with your help, and released later this year as QtMobility 1.1.0.

As you may know, we have also worked hard to resolve issues within the QtMobility 1.0.1 release, and to that end, earlier today we released our 1.0.2 package. While the quality of 1.0 is of the highest importance, we did not want to delay in sharing our drafts here for 1.1, as we believe that sharing early and often with you helps to achieve robust, high quality APIs.

Those longer term veterans understand that the Technology Preview releases are the best opportunity for you to help shape our new APIs before they solidify.

Releasing a Technology Preview early on like this however has some limitations for those reviewing. Specifically, given the early stage of development we have included only minimal backend support. But it is better to release the API drafts early and give you the opportunity to review and contribute before things become too settled.

On the subject of Contributions:
Your contribution toward desktop backends in particular is always most welcome as the program are firstly prioritising mobilie platforms; specifically Symbian and Maemo. (And later this year in Q3/Q4 we change our default development environment to Meego! :) )

Some detail on the logistics of how to go about reviewing this Technology Preview release:
This time round we are introducing ‘DevNet’ to the process.
DevNet facilitates better API review and communications.
Each of the new APIs will be individually introduced via Wiki on DevNet at http://developer.qt.nokia.com/.
There will also be a forum thread for each API, where you can share your review comments and track progress of the API as it matures toward Beta.
Good eh!? we certainly hope so :)
Also, let us know how you feel about that.

Ok, so whats in the box this time round!?
This Technology Preview contains 8 new APIs and also, in a few cases, some extensions to the existing APIs that were introduced in 1.0.
We are also introducing Qt Quick (QML) bindings for our APIs and several of those too are shared in this preview!

The list is as follows:

  • Service Framework API (Out-of process)
  • Document Gallery API
  • Maps/Navigation API
  • Organizer API
  • Landmarks API
  • Camera API
  • Versit/Organizer API
  • Telephony Events API
  • Feedback API
  • Contacts API
  • You can download the source package from:
    ftp://ftp.qt.nokia.com/qt/solutions/qt-mobility-opensource-src-1.1.0-tp.tar.gz
    ftp://ftp.qt.nokia.com/qt/solutions/qt-mobility-opensource-src-1.1.0-tp.zip

    Some APIs have been worked on a little more than others but overall, we believe they are in good shape for you to commence your review. Backend implementation wise, most of the APIs have the Maemo 5 backend which is currently our primary development environment.
    For each API there is an example application that demonstrates usage.
    Please note that Symbian SIS packages are not provided within this technology preview release as the backend is still under heavy development.

    We hope you enjoy this early preview of the ongoing work and as always,
    please continue to contribute, as your feedback is very valuable in helping us get it right!

    Thank you,

    Gerard and Min.
    On behalf of the Qt Mobility Program team

    Categories: Companies

    Qt Mobility 1.0.2 Released

    TrollTech Qt Labs Blogs - Tue, 07/27/2010 - 11:43

    Its here!
    For those in Europe enjoying a well deserved vacation by the side of a pool, or indeed for the rest of us around the world working hard on our projects, the availability of this package should come as very good news.

    The team, have worked very hard to ensure that our 1.0.2 package addresses those critical fixes (P0, P1 errors) that we communicated about on our recent alert post.

    In short, the more prominent APIs issues were: Location API crashes on Symbian platforms and Sensors API failing on Maemo 5.

    So we are very happy/relieved to be able to say that the promised 1.0.2 package has now arrived and can be downloaded from our Qt Solutions webpage.

    Also, coming very soon…your chance to download the technology preview release and be the first to try the next set of new APIs!! Not long to wait now at all :)

    We hope you enjoy!

    Kind regards,
    Gerard & Min.

    On behalf of the Qt Mobility Team.

    Categories: Companies

    The first Ribbon Bar for Silverlight, to fully comply with the Microsoft fluent UI guidelines.

    Telerik Blogs - Tue, 07/27/2010 - 08:24

    This week we will release new major feature for the RadRibbonBar – keyboard access.

    KeyTips provide keyboard access to every control in the Ribbon. They are activated by pressing the ALT key, following by the key for the button you want to activate. KeyTips are very well explained at the Microsoft’s fluent UI guidelines, you can read more about KeyTips on msdn…

    This feature is in the Required section from the Ribbon specification, but it’s nature and hard implementation details was preventing us from implementing it sooner.

    Currently this feature is the one with most votes in our PITS system, thus we considered it for high priority.

    Announcing the first keyboard support for Silverlight Ribbon Bar.

    Currently this is feature is not implemented by any other control vendor for Silverlight. Telerik is the first to offer this feature.

    KeyTip1

    KeyTips are also available for the ApplicationMenu, QuickAccessToolbar, drop down items – ...

    Categories: Companies

    Silverlight HTML5 WebSocket client with an HTML bridge to Ajax/JavaScript

    Microsoft Silverlight content - Tue, 07/27/2010 - 04:04
    As part of our ongoing experimentation with the HTML5 WebSocket proposed standard for duplex communication between web browsers and servers, we have prototyped a WebSocket protocol implementation based on Microsoft technologies. The prototype consists...(read more)
    Categories: Companies

    Server-side data types

    Midnight Coders Blog - Tue, 07/27/2010 - 03:46


    This post presents an example that is one baby step more complicated that my first post, “Hello, World!”, in order to describe WebORB’s way of handling server-side data types.

    In the “Hello, World!” app, the client’s call to the server returned (asynchronously) a simple data type: a string. It’s more common to request more-complex data — personnel records, weather data, astronomical info, marked-up medical images, or whatever.

    In this example, our client’s request will return such “complex data.” It won’t be terribly complex, though, so don’t be frightened. ;-)

    Here’s the first cut at our server-side code (in C#, for Visual Studio):

    using System;
    using System.Web;
    
    namespace ComplexDataServer
    {
        public class ComplexDataService
        {
            public ComplexData getComplexData()
            {
                ComplexData result = new ComplexData();
                return result;
            }
        }
    
        public class ComplexData
        {
            string helloString = "Hello, World!";
            string now = DateTime.Now.ToString();
            double r = (new Random()).NextDouble();
        }
    }
    

    Proper code would have getters and setters…but then, proper code probably wouldn’t be setting hard-coded values in ComplexData’s constructor, either. I’m keeping this simple.

    This code compiles cleanly, with no errors or warnings, so it looks Good To Go. We can deploy it into WebORB for .NET by copying its DLL into WebORB’s \bin directory, as described in my earlier “Hello, World!” post.

    We can verify that the deployed code works as intended by invoking it from WebORB for .NET’s management console, as shown below:

    Wait a minute…what did the method invocation return, exactly? Let’s look closer:

    That doesn’t look right. WebORB doesn’t know how to interpret the data returned by the service.

    Hmmmmm.

    Well, gee, I’m new at this, so maybe I just don’t get it, so I’ll go ahead and generate the client-side code anyway, load it up into Flash Builder, and hope for the best.

    Clicking the “Download Code” button generates the weborb.codegen file for this service, which I import into Flash Builder..mostly, but not entirely, as I did in “Hello, World!”. This time, when Flex’s Import… process displays its “Choose Flex SDK Version” dialog, I’m going to click the “Use Flex 3 Compatibility Mode” checkbox on the import dialog. That way, the generated code will “just work” with Flash SDK 4, even though it was generated for Flash SDK 3.x.

    In Flash Builder, the generated project is shown in the Package Explorer as shown above. It’s structure is identical to the “Hello, World!” project:

    • In the default package
      • main.mxml
    • In the [Service] folder (where) [Service] is the name of the DLL/namespace of the server-side code)
      • [Service].as
      • [Service]Model.as

    Seeing the same structure is rather comforting — like seeing an old friend’s face in an unfamiliar crowd.

    main.mxml looks like this:

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onLoad()">
    	<mx:Script>
    		<![CDATA[
    
    			public function onLoad():void
    			{
    
    			}
    		]]>
    	</mx:Script>
    </mx:Application>
    

    …which is pretty much the same as it looked in “Hello, World!”.

    As before, we’ll go into the [Service].as file (in this case, ComplexDataService.as), copy out the code that’s in its header comment, paste it into main.mxml’s CDATA block, and update the onLoad() function to have the serviceProxy call the remote function (in this case, serviceProxy.getComplexData()). The result of all that looks like this:

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onLoad()" width="275" height="298">
    	<mx:Script>
    		<![CDATA[
    			import ComplexDataServer.ComplexDataService;
    			import ComplexDataServer.ComplexDataServiceModel;
    
    			[Bindable]
    			var model:ComplexDataServiceModel = new ComplexDataServiceModel();
    			var serviceProxy:ComplexDataService = new ComplexDataService( model );
    
    			public function onLoad():void
    			{
    				// make sure to substitute foo() with a method from the class
    				serviceProxy.getComplexData();
    			}
    		]]>
    	</mx:Script>
    </mx:Application>
    

    There’s only one problem: the code won’t compile. The compiler barfs error #”1046: Type was not found or was not a compile-time constant: ComplexData. ComplexDataServiceModel.as.” Well, fooey.

    Here’s ComplexDataServiceModel.as:

        package ComplexDataServer
        {
          [Bindable]
          public class ComplexDataServiceModel
          {
            public var getComplexDataResult:ComplexData;
          }
        }
    

    By golly, the type of ComplexDataServiceModel’s getComplexDataResult property is ComplexData, and ComplexData is defined…where, exactly? It was defined over in the C# code on the server, but WebORB doesn’t seem to know about that.

    WTF? Why did WebORB understand the “Hello, World!” service’s result type/class/whatever, but not ComplexData’s?

    The answer is, in brief, that the “Hello, World!” service’s result type was simple — that is, it was of a single instance of a single type well-known to the type systems of both C# and Flex, so WebORB could shoot it right over. ComplexDataService’s result isn’t a simple type; it’s a complex type. It’s a user-defined class, containing a couple of strings and a double-precision real number. That may not be super-complicated, but it isn’t “simple,” either.

    How can we make our Flex-based client aware of the type/class/structure of our server-side data? The fix is rather arcane, due to a quirk of Flex. Fortunately, WebORB handles most of the complexity.

    The thing is, that the [Service] result’s class, in this case ComplexData, must have its properties declared to be public. Like so:

        public class ComplexData
        {
            public string helloString = "Hello, World!";
            public string now = DateTime.Now.ToString();
            public double r = (new Random()).NextDouble();
        }
    
    • Add those three “public” keywords,
    • build the ComplexDataServer.DLL,
    • drag it to WebORB’s \bin directory (replacing the previous version),
    • launch WebORB’s management console,
    • refresh its list of .NET Assemblies,
    • find the revised ComplexDataServer service,
    • walk down the hierarchical menu to find the getComplexData() function,
    • click the “Invoke” button, and
    • voila!

    …you ought to see a service result that looks like this:

    [Of course, if you do this, the values you see for "now" and "r" will be different, as "now" is the current DateTime and "r" is a random number.]

    Let’s generate a new project from the revised ComplexDataServer, import into Flex Builder as ComplexDataService2, and take a look at it.

    Its structure looks different. There’s a new “vo” package, and two new files — ComplexData.as and DataTypeInitializer.as.

    Let’s look at ComplexData.as first:

    package ComplexDataServer.vo
    {
    	import flash.utils.ByteArray;
    	import mx.collections.ArrayCollection;
    
    	[Bindable]
    	[RemoteClass(alias="ComplexDataServer.ComplexData")]
    	public class ComplexData
    	{
    		public function ComplexData(){}
    
    		public var helloString:String;
    		public var now:String;
    		public var r:Number;
    	}
    }
    

    Well, that makes sense. It’s a re-declaration, in ActionScript, of the ComplexData class defined in C# on the server. Clearly, WebORB must do some type-mapping magic here — for example, mapping C#’s double to Flash’s Number — but the code above makes sense.

    That solves Mystery #1: getting server-side complex data type definitions into client-side Flex code via WebORB. The trick is to ensure that all of the properties (that you care about) are declared t be “public”.

    But…what’s this “DataTypeInitializer” thingy?

    Let’s look at its code:

    package ComplexDataServer
    {
    	import ComplexDataServer.vo.ComplexData;
    	public class DataTypeInitializer
    	{
    		public function DataTypeInitializer()
    		{
    			new ComplexDataServer.vo.ComplexData();
    		}
    	}
    }
    

    WTF? All this code does is

    • define a new class, DataTypeInitializer, with a constructor that
    • allocates a new object of class ComplexData…and throws it away.

    It gets weirder. Look at the onLoad() function in the new project’s main.mxml file:

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onLoad()">
    	<mx:Script>
    		<![CDATA[
    			import ComplexDataServer.DataTypeInitializer;
    
    			public function onLoad():void
    			{
    				new DataTypeInitializer();
    			}
    		]]>
    	</mx:Script>
    </mx:Application>
    

    Once again, all it does is allocate something that is immediately thrown away — in this case, an object of class DataTypeInitializer.

    That is,

    • onLoad() allocates a DataTypeInitializer
      • which allocates a ComplexData
      • and then throws the ComplexData away
    • and then throws away the DataTypeInitializer.

    That’s a whole lot of allocation, for no effect…unless the allocations have an important side-effect. As, indeed, they do.

    Flex has this nasty/useful tendency to strip out the definitions of all types/classes that are never instantiated.

    • On the one hand, this is useful, because keeps run-time code as small as possible.
    • On the other hand, it’s nasty, because it forces developers to perform Stupid Programming Tricks to keep their class/type definitions from being stripped.

    WebORB generates the code you need — not just the code you need to define your server-side types on the client, but also the code you need to keep Flex from stripping those definitions out. WebORB does Stupid Programming Tricks so that you don’t have to.

    Which solves Mystery #2. Just import all the code that WebORB generates, and call “new DataTypeInitializer();” in your application’s initializer. DataTypeInitializer()’s constructor will contain allocations of ALL of your server-side data types, to ensure that none of them get stripped by Flex.

    Another WebORB programming mystery exposed! ;-)

    To finish up the client side of the ComplexDataService2 app, here’s the final version of its main.mxml:

    <mx:Application
    	xmlns:mx="http://www.adobe.com/2006/mxml"
    	layout="absolute"
    	width="354" height="184"
    	initialize="onLoad()">
    
    	<mx:Script>
    		<![CDATA[
    			import ComplexDataServer.DataTypeInitializer;
    			import ComplexDataServer.ComplexDataService;
    			import ComplexDataServer.ComplexDataServiceModel;
    
    			[Bindable]
    			private var model:ComplexDataServiceModel
    							= new ComplexDataServiceModel();
    			private var serviceProxy:ComplexDataService
    							= new ComplexDataService( model );
    
    			public function onLoad():void
    			{
    				new DataTypeInitializer();
    
    				// initialize the model
    				serviceProxy.getComplexData();
    			}
    		]]>
    	</mx:Script>
    	<mx:Panel x="10" y="10" width="332"
    			  height="130"
    			  layout="absolute"
    			  title="ComplexData">
    
    		<mx:Label x="10" y="10" text="hello" fontWeight="bold"/>
    		<mx:Label x="10" y="36" text="now" fontWeight="bold"/>
    		<mx:Label x="10" y="62" text="r" fontWeight="bold"/>
    
    		<mx:Label x="49" y="9" text="{model.getComplexDataResult.helloString}"/>
    		<mx:Label x="49" y="35" text="{model.getComplexDataResult.now}"/>
    		<mx:Label x="49" y="61" text="{model.getComplexDataResult.r}"/>
    	</mx:Panel>
    
    	<mx:Button x="144" y="152"
    			   label="Again"
    			   click="{serviceProxy.getComplexData();}"/>
    </mx:Application>
    

    Notice that:

    • The UI elements bind to the model’s properties.
    • The “Again…” button’s click handler, and the application’s onLoad() method, both call “serviceProxy.getComplexData()” to update the service’s data model via a call to the server.

    [You can find a concise presentation of this blarticle's key points here, in WebORB's formal documentation.]

    Categories: Companies

    Getting Started with Phidgets and ActionScript 3

    Mike Chambers - Mon, 07/26/2010 - 23:41


    Phidgets are a set of devices and sensors that provide a simple way for developers to create applications that both send and receiving information from external sensors, motors and pretty much anything else you can hook up via electronics. They are similar to the open source Arduino electronic platform.

    Im not going to do a big comparison between Arduino and Phidgets in this post. I plan to do that in another post (along with an Arduino / Flash hello world article). Suffice it to say though, that one of the major benefits of Phidgets, is that the Phidgets devices are a bit higher level, both on the hardware, and software side and thus can be a little easier for a developer new to electronics to get started with.

    If you are a Flash developer, Phidget’s are very attractive, as they provide a very well developed and documented ActionScript API for working with the Phidgets devices. The API works by connecting via a socket from Flash content, to a Phidgets local (or remote) server. The Phidgets server connects directly to the Phidgets devices over USB, and proxies communication between the Flash / ActionScript content, and the Phidgets devices and electronics.

    In this post, I will cover everything you need to know in order to get started integrating Phidgets electronics and Flash / ActionScript content.


    You can grab all of the code for the example from my GitHub Example repository.

    First, here is what you will need to get started:

    • An ActionScript 3 compiler (such as Flash Builder, Flash Professional, or the open source MXMLC compiler included in the Flex 4 SDK).
    • An IDE or text editor to edit ActionScript (such as Flash Builder, Flash Authoring, FDT, TextMate or any other general text editor).
    • The Phidgets ActionScript 3 library. You can find the library’s SWC in Flex 3 Code Sample ZIP file, and can find the source in the Flash AS3 Code Sample Zip file, both on the Phidgets programming resources page.
    • The Phidgets drivers for your platform. This will install the drivers for the devices, as well as the proxy application / server that Flash will use to communicate with the devices. You can download these from the Phidgets driver page.
    • At least one Phidgets device that can connect directly to your computer USB. If you are just getting started, then I would recommend the 1018 – PhidgetInterfaceKit 8/8/8 as it is the most flexible and extensible. This article will assume you are using this kit.
    • One LED to test the kit with.

    For this article I will be using TextMate on a Mac and compiling with the free mxmlc compiler included in the Flex 4 SDK. We will be running the example via Adobe AIR (via ADL included in the Flex 4 SDK) (although the SWF we create will also work in the Flash Player in the browser).

    Install Drivers

    First, download and install the Phidgets drivers for your platform. This will install the drivers to interface with the devices via USB, and will also install a standalone application / server that will proxy calls between Flash and the devices.

    Test Installation

    Once you have installed the drivers, download the manual for the 1018 – PhidgetInterfaceKit 8/8/8. I strongly recommend you read through the entire PDF document, but at a minimum, you will want to read the “Product Features” and “Getting Started”" sections.

    Connect your Phidget via USB to your computer and then read and follow the steps under the Getting Started > Testing section in the 1018 docs. This will show you how to ensure that your Phidgets and software are setup and functioning correctly. Make sure to run the sample program as described in the docs.

    Download Phidget ActionScript Library

    In order to communication with the Phidgets devices / proxy application via ActionScript, we need to download the Phidgets ActionScript library. There are two Flash related libraries on the Phidgets Programming Resources page. The Flash AS3 download contains example FLAs to be run in Flash Authoring (4 or 5), as well as the source code for the Phidgets ActionScript library. The Flex AS3 download contains both Flex / MXML and pure ActionScript examples, as well as the Phidget AS3 Library SWC. You can also download API references and a getting started guide on the page.

    You can use either the Phidget library source from the Flash AS3 download, or the Phidget library SWC from the Flex AS3 download. Just make sure to link them in when compiling your ActionScript. For this article I will be using the compiled SWC.

    Configure the Phidget

    For our simple hello world example, we are going to connect an LED to our Phidget and then turn it on via ActionScript. In order to do this, we need to connect an LED to the PhidgetInterfaceKit. Connect an LED to output pins G (Ground) and 0. Make sure that the long wire (anode) of the LED is connected to pin 0, and the short wire (cathode) is connect to the ground (G).

    Next, make sure that the Phidget is connected to the computer via USB. You can test that everything is connected and hooked up correctly by opening the Phidget preferences, and selecting output 0 on the Phidget Interface Kit screen. This should turn on the LED (make sure to turn it off once you are done).

    Turn on Phidget Proxy / Server

    The last step before we can write our code is to make sure that the Phidget proxy / web server is running. This is a simple socket server that runs locally and proxies calls between Flash and the Phidget.

    On Mac, you can start this in System Preferences > Phidgets > Web Service > Start Web Service. Check the documentation for how to start it on other platforms.

    For now you can leave the ServerID and Password blank, and leave the port at its default value of “5001″.

    Write ActionScript Code

    We are finally ready to write the ActionScript code to interface with the Phidget.

    Open you ActionScript editor, and type in the following code in a file named PhidgetsHelloWorld.as. The code below is fully commented and explains what is going on.

    /*
    	The MIT License
    
    	Copyright (c) 2010 Mike Chambers
    
    	Permission is hereby granted, free of charge, to any person obtaining a copy
    	of this software and associated documentation files (the "Software"), to deal
    	in the Software without restriction, including without limitation the rights
    	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    	copies of the Software, and to permit persons to whom the Software is
    	furnished to do so, subject to the following conditions:
    
    	The above copyright notice and this permission notice shall be included in
    	all copies or substantial portions of the Software.
    
    	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    	THE SOFTWARE.
    */
    
    package
    {
    	import flash.display.Sprite;
    	import flash.events.Event;
    
    	//import the Phidget classes we need for this example
    	//from the Phidget's library / SWC
    	import com.phidgets.Phidget;
    	import com.phidgets.PhidgetInterfaceKit;
    	import com.phidgets.events.PhidgetEvent;	
    
    	public class PhidgetsHelloWorld extends Sprite
    	{		
    
    		//reference to the Phidget Interface Kit we are connecting to
    		private var interfaceKit:PhidgetInterfaceKit;
    
    		//constructor
    		public function PhidgetsHelloWorld()
    		{
    			//listen for when we are added to the stage
    			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    		}
    
    		private function onAddedToStage(e:Event):void
    		{
    			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    
    			//create instance of PhidgetInterfaceKit
    			interfaceKit = new PhidgetInterfaceKit();
    
    			//listen for event that we need for this example
    
    			//connected to proxy
    			interfaceKit.addEventListener(PhidgetEvent.CONNECT,	onConnect);
    
    			//device attached
    			interfaceKit.addEventListener(PhidgetEvent.ATTACH,	onAttach);
    
    			//device detached
    			interfaceKit.addEventListener(PhidgetEvent.DETACH,	onDetach);
    
    			//disconnected from proxy
    			interfaceKit.addEventListener(PhidgetEvent.DISCONNECT, onDisconnect);
    
    			//proxy address. Usually localhost / 127.0.0.1, but can be any server
    			//on any computer. The proxy returns proper security policy file
    			var serverAddress:String = "127.0.0.1";
    
    			//port the proxy is listening on
    			var serverPort:uint = 5001;
    
    			//connect to the proxy and device
    			interfaceKit.open("127.0.0.1", 5001);
    		}
    
    		//called when we connect to the proxy server
    		private function onConnect(e:PhidgetEvent):void
    		{
    			//note, we cannot access any devices here yet, since
    			//we have not connected to them. You have to wait for the
    			//onAttach event
    			trace("-------onConnect------- ");
    		}
    
    		//called when we attach / connect to the actual Phidget
    		private function onAttach(e:PhidgetEvent):void
    		{
    			trace("-------onAttach------- ");
    
    			//get a reference to the device we connected to
    			var device:Phidget = e.Device;
    
    			//print out a bunch of information about it
    			trace(device.Name + " : " + device.Label);
    			trace("Version : " + device.Version);
    			trace("Serial : " + device.serialNumber);
    
    			//output number / pin that the LED is connected to
    			var outputPin:uint = 0;
    
    			//state to set the output pin. true = on, false = off
    			var state:Boolean = true;
    
    			//set the output state for pin 0 to true / on.
    			//this will turn on the LED
    			interfaceKit.setOutputState(outputPin, state);
    
    			//note, you have to explicitly turn it off, or else
    			//it will stay on, even after the program has stopped running
    		}
    
    		//called when a device is detached. i.e. the USB cable is disconnected
    		//while the program is running
    		private function onDetach(e:PhidgetEvent):void
    		{
    			//you cannot access the devices here.
    			trace("-------onDetach------- ");
    		}		
    
    		//called once the connection to the proxy server is closed.
    		private function onDisconnect(e:PhidgetEvent):void
    		{
    			//you cannot access the devices here
    			trace("-------onAttach------- ");
    		}
    	}
    }

     

    I am going to run this via ADL (Adobe AIR) included in the Flex SDK, and thus also need the following PhidgetHelloWorld-app.xml file:

    <?xml version ="1.0" encoding="utf-8" ?>
    <application xmlns="http://ns.adobe.com/air/application/2.0">
    	<id>PhidgetsHelloWorld</id>
    	<version>1.0</version>
    	<filename>PhidgetsHelloWorld</filename>
    	<description></description>
    	<name>PhidgetsHelloWorld</name>
    	<copyright></copyright>
    	<initialWindow>
    		<content>PhidgetsHelloWorld.swf</content>
    		<systemChrome>standard</systemChrome>
    		<transparent>false</transparent>
    		<visible>true</visible>
    		<fullScreen>false</fullScreen>
    		<autoOrients>false</autoOrients>
    		<aspectRatio>portrait</aspectRatio>
    		<renderMode>auto</renderMode>
    	</initialWindow>
    	<customUpdateUI>false</customUpdateUI>
    	<allowBrowserInvocation>false</allowBrowserInvocation>
    	<icon>
    	</icon>
    </application>
    

     

    I am running it via ADL / Adobe AIR as it will easily allow me to see the trace output on the command line.

    Here is the command to compile the program using MXMLC:

    mxmlc -library-path+=Phidget21Library.swc PhidgetHelloWorld.as

     

    You may receive a warning about runtime shared libraries. You can safely ignore this.

    If you get an error that mxmlc cant be found, then make sure you have added the FLEXSDK/bin directory to your system’s path.

    If you receive any errors, make sure you are linking in the Phidget library correctly. Once it compiles, you can test it on the command line with the following command:

    adl PhidgetHelloWorld-app.xml

     

    When I run this on my machine the LED turns on on the Phidget, and I get the following output on the command line:

    -------onConnect-------
    -------onAttach-------
    Phidget InterfaceKit 8/8/8 :
    Version : 900
    Serial : 116799

     

    If you run the SWF in the player, then you should see the LED turn on. If you run in Flash Authoring (FLA included) or FlashBuilder, then you should also see the trace output in the output panel.

    Notice that once you close the program, the LED is still on. You have to explicitly turn off the LED. You can do this by modifying the code to turn it off, and then run it again.

    This is an important point. The device may maintain its state even after the program has stopped running. Because of this, you should always set the device to a known state when your application starts up, and make sure it is in the correct state when you shut down your program.

    Once you are at this point, it is just a matter of hooking up additional sensors, motors and outputs. The Phidgets ActionScript library is very well written, and makes it easy to work with additional Phidgets.

    Make sure to check out all of the Phidgets and ActionScript related docs on the Phidgets site, as well as the Phidgets ActionScript forum.

    If you find any errors, or have any questions or suggestions, then please leave them in the comments.

    Categories: Blogs, Companies