<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4532018939601396597</id><updated>2011-11-27T16:29:51.147-08:00</updated><category term='OO Design'/><title type='text'>Swathi's Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javajuggler.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4532018939601396597/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://javajuggler.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Swathi</name><uri>http://www.blogger.com/profile/13556341205589043213</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4532018939601396597.post-3883088133536858985</id><published>2011-02-03T20:13:00.000-08:00</published><updated>2011-02-07T06:56:52.072-08:00</updated><title type='text'>Dummy guide for Form based authentication using weblogic10.3</title><content type='html'>Dummy guide for Form based authentication using weblogic10.3:&lt;br /&gt;Form-based authentication lets developers customize the authentication user interface. The login-config section of web.xml defines the type of authentication mechanism, and the URIs to login and error pages.&lt;br /&gt;These instructions assume a security realm is already created and configured to LDAP active directory.&lt;br /&gt;1. Create Group:&lt;br /&gt;Go to Security Realms -&amp;gt; myrealm (already created realm) -&amp;gt; Users &amp; Groups -&amp;gt; Groups. Create a new group AdminGroup. Select DefaultAuthenticator as provider.&lt;br /&gt;2. Create User:&lt;br /&gt;Go to Security Realms -&amp;gt; myrealm (already created realm) -&amp;gt; Users &amp; Groups -&amp;gt; Users. Create a new user AdminUser. Select DefaultAuthenticator as provider.&lt;br /&gt;3. Associate user with group&lt;br /&gt;Click on the created user and under Groups tab, select the AdminGroup. This will associate the user with the group&lt;br /&gt;4. Associate the user/group security model to the deployment. &lt;br /&gt;Go to Deployments -&amp;gt; myDeployment -&amp;gt; Security. Create New scoped role.&lt;br /&gt;Select the newly created scoped role and Add Conditions. Select group from Predicate List drop down and select the newly created AdminGroup.&lt;br /&gt;Violaa.. you are almost done with the setup in console.&lt;br /&gt;5. On your webapps, add the following into web.xml&lt;br /&gt;&lt;pre&gt;&amp;lt;security-constraint&amp;gt;&lt;br /&gt;&amp;lt;display-name&amp;gt;&amp;lt;/display-name&amp;gt;&lt;br /&gt;&amp;lt;web-resource-collection&amp;gt;&lt;br /&gt;&amp;lt;web-resource-name&amp;gt;AdminGroup&amp;lt;/web-resource-name&amp;gt;&lt;br /&gt;&amp;lt;description&amp;gt;Security Constraints for AdminGroup&amp;lt;/description&amp;gt;&lt;br /&gt;&amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;&amp;lt;http-method&amp;gt;POST&amp;lt;/http-method&amp;gt;&lt;br /&gt;&amp;lt;http-method&amp;gt;GET&amp;lt;/http-method&amp;gt;&lt;br /&gt;&amp;lt;/web-resource-collection&amp;gt;&lt;br /&gt;&amp;lt;auth-constraint&amp;gt;&lt;br /&gt;&amp;lt;description&amp;gt;Security Constraints for AdminGroup&amp;lt;/description&amp;gt;&lt;br /&gt;&amp;lt;role-name&amp;gt;AdminGroup&amp;lt;/role-name&amp;gt;&lt;br /&gt;&amp;lt;/auth-constraint&amp;gt;&lt;br /&gt;&amp;lt;user-data-constraint&amp;gt;&lt;br /&gt;&amp;lt;description&amp;gt;SSL not required&amp;lt;/description&amp;gt;&lt;br /&gt;&amp;lt;transport-guarantee&amp;gt;NONE&amp;lt;/transport-guarantee&amp;gt;&lt;br /&gt;&amp;lt;/user-data-constraint&amp;gt;&lt;br /&gt;&amp;lt;/security-constraint&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;login-config&amp;gt;&lt;br /&gt;&amp;lt;auth-method&amp;gt;FORM&amp;lt;/auth-method&amp;gt;&lt;br /&gt;&amp;lt;realm-name&amp;gt;MyApplication&amp;lt;/realm-name&amp;gt;&lt;br /&gt;&amp;lt;form-login-config&amp;gt;&lt;br /&gt;&amp;lt;form-login-page&amp;gt;/login.jsp&amp;lt;/form-login-page&amp;gt;&lt;br /&gt;&amp;lt;form-error-page&amp;gt;/login_error.jsp&amp;lt;/form-error-page&amp;gt;&lt;br /&gt;&amp;lt;/form-login-config&amp;gt;&lt;br /&gt;&amp;lt;/login-config&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;security-role&amp;gt;&lt;br /&gt;&amp;lt;description&amp;gt;Administrators&amp;lt;/description&amp;gt;&lt;br /&gt;&amp;lt;role-name&amp;gt;AdminGroup&amp;lt;/role-name&amp;gt;&lt;br /&gt;&amp;lt;/security-role&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;6. Update weblogic.xml with the role assignment&lt;br /&gt;&lt;pre&gt;&amp;lt;security-role-assignment&amp;gt;&lt;br /&gt;&amp;lt;role-name&amp;gt;AdminGroup&amp;lt;/role-name&amp;gt;&lt;br /&gt;&amp;lt;externally-defined/&amp;gt;&lt;br /&gt;&amp;lt;/security-role-assignment&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;7. Create login.jsp&lt;br /&gt;&amp;lt;form method="POST" action="j_security_check"&amp;gt;&lt;br /&gt;&amp;lt;input type="text" name="j_username"&amp;gt;&lt;br /&gt;&amp;lt;input type="password" name="j_password"&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;That’s it. That’s all there is for setting up the login.&lt;br /&gt;To logout the user, form based authentication goes by regular HTTP session. So in your logout.jsp, calling session.invalidate(); will invalidate the session and logs the user out.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4532018939601396597-3883088133536858985?l=javajuggler.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javajuggler.blogspot.com/feeds/3883088133536858985/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javajuggler.blogspot.com/2011/02/dummy-guide-for-form-based.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4532018939601396597/posts/default/3883088133536858985'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4532018939601396597/posts/default/3883088133536858985'/><link rel='alternate' type='text/html' href='http://javajuggler.blogspot.com/2011/02/dummy-guide-for-form-based.html' title='Dummy guide for Form based authentication using weblogic10.3'/><author><name>Swathi</name><uri>http://www.blogger.com/profile/13556341205589043213</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4532018939601396597.post-7339913169875603227</id><published>2011-01-05T09:11:00.000-08:00</published><updated>2011-01-05T09:32:45.503-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OO Design'/><title type='text'>OO Design for ParkingLot</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span"  &gt;Its a parking lot design day. I am thinking of a simple parking lot where there are finite number of spaces and the space can either be a compact/handicap/regular.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;A car can be parked or unparked. The parking lot can be full or empty.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;I think below design will do:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;ParkingLot:&lt;/b&gt; this class can park or unpark and holds finite number of spaces and the spaces are held by two lists one for Parkedspaces and one for unparkedSpaces&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;b&gt;ParkingSpace: &lt;/b&gt; is another class that represents the actual parking space. It needs a property to specify whether it is a compact/handicap/regular parking space&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  &gt;&lt;b&gt;Car: &lt;/b&gt; is the final class that has a property of what kind of car it is and if it is parked, the slot number where it is parked.&lt;/span&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;table width="50%" style="border-style:solid;border-color:black;border-width:1px"&gt;&lt;tr&gt;&lt;td&gt;&lt;pre&gt;public class ParkingLot {&lt;br /&gt;    int totalSpaces = 100;&lt;br /&gt;    public static List ParkingSpace parkedSpaces = new ArrayList();&lt;br /&gt;    public static List ParkingSpace emptySpaces = new ArrayList();&lt;br /&gt;&lt;br /&gt;    public static void park(Car car) {&lt;br /&gt;        //Traverse though the emptySpaces list to find the &lt;br /&gt;        //spot for specific car type&lt;br /&gt;        //set the car object for that parkingspace&lt;br /&gt;        //change it to park. move the object into parkedSpaces&lt;br /&gt;        // remove it from emptySpaces&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static void unPark(int parkingSpot) {&lt;br /&gt;        //get the parkingspot from array&lt;br /&gt;        //set the parkingspace to available&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static boolean isEmpty() {&lt;br /&gt;        if (emptySpaces.size() &gt; 0)&lt;br /&gt;            return true;&lt;br /&gt;        return false;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static void main(String args[]) {&lt;br /&gt;        //build emptySpaces list. Insert 100 parking spaces &lt;br /&gt;        //with their type properties&lt;br /&gt;        Car car = new Car();&lt;br /&gt;        car.setCompact(true);&lt;br /&gt;        if(ParkingLot.isEmpty())&lt;br /&gt;            ParkingLot.park(car);&lt;br /&gt;&lt;br /&gt;        ParkingLot.unPark(20);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class ParkingSpace {&lt;br /&gt;&lt;br /&gt;    boolean isCompact;&lt;br /&gt;    boolean isRegular;&lt;br /&gt;    boolean isHandicap;&lt;br /&gt;&lt;br /&gt;    //setter and getter calls&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Car {&lt;br /&gt;   boolean isCompact;&lt;br /&gt;   boolean isRegular;&lt;br /&gt;   boolean isHandicap;&lt;br /&gt;   int parkingSlotNumber;&lt;br /&gt;&lt;br /&gt;   public Car() {&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void setParkingSlotNumber(int value) {&lt;br /&gt;    this.parkingSlotNumber = value;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;p&gt;The Car object can be further subclassed as CompactCar, HandiCapCar, RegularCar instead of the booleans. Same with the ParkingSpace as well.&lt;br/&gt;&lt;br /&gt;But is there any use in that?&lt;/p&gt;Please share your thoughts.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4532018939601396597-7339913169875603227?l=javajuggler.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javajuggler.blogspot.com/feeds/7339913169875603227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javajuggler.blogspot.com/2011/01/oo-design-for-parkinglot.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4532018939601396597/posts/default/7339913169875603227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4532018939601396597/posts/default/7339913169875603227'/><link rel='alternate' type='text/html' href='http://javajuggler.blogspot.com/2011/01/oo-design-for-parkinglot.html' title='OO Design for ParkingLot'/><author><name>Swathi</name><uri>http://www.blogger.com/profile/13556341205589043213</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4532018939601396597.post-6311568985988008427</id><published>2011-01-04T07:09:00.000-08:00</published><updated>2011-01-04T10:07:02.315-08:00</updated><title type='text'>In an array find two numbers that add up to a given value X</title><content type='html'>&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span"&gt;As part of researching into regular math questions asked in interview, I stumbled upon this simple data structure question of "from an array of integers, given an input x, how do you find two numbers that add up to X.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;The basic algorithm to find two numbers that add up to X:&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span"&gt;&lt;/span&gt;&lt;table width="50%" style="border-style:solid;border-color:black;border-width:1px"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span class="Apple-style-span"&gt;&lt;pre&gt;declare hash&lt;br /&gt;for each element in the array&lt;br /&gt;   diff = current_element - X&lt;br /&gt;   if(!hash.contains(current_element))&lt;br /&gt;     hash.put(current_element, diff);&lt;br /&gt;   end if&lt;br /&gt;   if(hash.contains(diff))&lt;br /&gt;     the two numbers are current_element, diff&lt;br /&gt;   end if&lt;br /&gt;end for&lt;/pre&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;span class="Apple-style-span"&gt;Here is the tested java code for the same:&lt;/span&gt;&lt;/p&gt;&lt;table width="50%" style="border-style:solid;border-color:black;border-width:1px"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span class="Apple-style-span"&gt;&lt;pre&gt;public class IntegerArrayTest {&lt;br /&gt;  public static final int[] int_array  =&lt;br /&gt;           {1,2,3,4,5,6,7,8,9,10};&lt;br /&gt;  public static java.util.Hashtable&lt;integer,integer&gt; intHash =&lt;br /&gt;       new java.util.Hashtable&lt;integer, integer=""&gt;();&lt;br /&gt;  public static String getResult(int x_number) {&lt;br /&gt;    for (int i=0;i&lt;int_array.length;i++)&lt;br /&gt;      int current_element = int_array[i];   &lt;br /&gt;      int diff = 0;&lt;br /&gt;      if( x_number &gt; current_element)&lt;br /&gt;        diff = x_number - current_element;&lt;br /&gt;      else&lt;br /&gt;        diff = current_element - x_number;&lt;br /&gt;      if(!intHash.containsKey(current_element)) {&lt;br /&gt;        //just add it in&lt;br /&gt;        intHash.put(current_element, diff);&lt;br /&gt;      }&lt;br /&gt;      if(intHash.containsKey(diff)){&lt;br /&gt;        //out quest stops here&lt;br /&gt;        return new StringBuffer("The numbers are ").&lt;br /&gt;    append(current_element).append(" and ").&lt;br /&gt;    append(diff).toString();&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;    return "Did not find mathing number";&lt;br /&gt;  }&lt;br /&gt;  public static void main(String args[]) {&lt;br /&gt;    String x_number = args[0];&lt;br /&gt;    String result = &lt;br /&gt;   IntegerArrayTest.getResult(&lt;br /&gt;            Integer.parseInt(x_number));&lt;br /&gt;    System.out.println(result);&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div&gt;There you go, thats my take on that algorithm. Let me know how it can be enhanced.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4532018939601396597-6311568985988008427?l=javajuggler.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javajuggler.blogspot.com/feeds/6311568985988008427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javajuggler.blogspot.com/2011/01/in-array-find-two-numbers-that-add-up.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4532018939601396597/posts/default/6311568985988008427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4532018939601396597/posts/default/6311568985988008427'/><link rel='alternate' type='text/html' href='http://javajuggler.blogspot.com/2011/01/in-array-find-two-numbers-that-add-up.html' title='In an array find two numbers that add up to a given value X'/><author><name>Swathi</name><uri>http://www.blogger.com/profile/13556341205589043213</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
