DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. Adding Module for Jaggery

Adding Module for Jaggery

Madhuka  Udantha user avatar by
Madhuka Udantha
CORE ·
Feb. 22, 13 · Interview
Like (0)
Save
Tweet
Share
3.44K Views

Join the DZone community and get the full member experience.

Join For Free
If you need any module or (jaggery code) to reuse in jaggery, we can add a module into jaggery easily.  I will be explain how to do it in this article.

We can reuse modules from jaggery applications in each particular jaggery server. I need to add some custom new JavaScript APIs that are mainly for your applications. Modules are he best option you have.

We can write a module in javascript or java (hostobject). In the module('<jaggery-home>\modules\') you have to point out the particular file with its location. Here I am explaining how to achieve this.

[1]Create a folder with your module name inside a '<jaggery-home>\modules\' (My module is for 'phone')

Create a module.xml inside this folder. Add your module names like you see below

<module name="phone" xmlns="http://wso2.org/projects/jaggery/module.xml">
  <script>
  <name>phone</name>
  <path>scripts/phone.js</path>
  </script>
</module>

[2] Add the js file in ‘scripts’ (Phone will have type and number, we can get phone information from the object – the phone I own)

phone.js

var phone = function  (number) {
  this.type = "Apple";
  this.number = number;
  this.getInfo = getPhoneInfo;
}
 
var getPhoneInfo = function () {
  return this.number + ' is ' + this.type + ' phone';
}

[3] Now start Jaggery server, jaggery will have a javascript API for Phone that we create.  Let's try that now.

[4] Create jaggery Applications ‘testPhone’ contains ‘phone.jag’ Here is a jaggery file that I am going to use with the phone API that we created.

<%
  function getPhone(phoneNumber){
 
  var phone = require('phone');
  var myPhone = new phone.phone(phoneNumber);
  return myPhone.getInfo();
 
  }
 
  print(getPhone("94774066666"));
%>

[5] now go to http://localhost:9763/testPhone/phone.jag

image

[6] Now think you buy new Phone and your phone type is now changed to Nokia

<%
  function getPhone(phoneNumber){
 
  var phone = require('phone');
  var myPhone = new phone.phone(phoneNumber);
  //buy new phone
  myPhone.type = "Nokia";
  return myPhone.getInfo();
  }
 
  print(getPhone("94774066666"));
%>

image

application JavaScript API Java (programming language) Object (computer science)

Published at DZone with permission of Madhuka Udantha, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Key Considerations When Implementing Virtual Kubernetes Clusters
  • Top Three Docker Alternatives To Consider
  • Top 5 Java REST API Frameworks
  • An Introduction to Data Mesh

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: