<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FDesign_Pattern%2FHOPP_Pattern</id>
		<title>Java/Design Pattern/HOPP Pattern - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FDesign_Pattern%2FHOPP_Pattern"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Design_Pattern/HOPP_Pattern&amp;action=history"/>
		<updated>2026-04-22T08:21:54Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Design_Pattern/HOPP_Pattern&amp;diff=7785&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Design_Pattern/HOPP_Pattern&amp;diff=7785&amp;oldid=prev"/>
				<updated>2010-06-01T06:50:38Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:50, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Design_Pattern/HOPP_Pattern&amp;diff=7784&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Design_Pattern/HOPP_Pattern&amp;diff=7784&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== HOPP Pattern in Java ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
//[C] 2002 Sun Microsystems, Inc.---&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.ObjectInputStream;&lt;br /&gt;
import java.io.ObjectOutputStream;&lt;br /&gt;
import java.io.Serializable;&lt;br /&gt;
import java.rmi.Naming;&lt;br /&gt;
import java.rmi.Remote;&lt;br /&gt;
import java.rmi.RemoteException;&lt;br /&gt;
import java.rmi.server.UnicastRemoteObject;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.Date;&lt;br /&gt;
import java.util.HashMap;&lt;br /&gt;
public class RunHOPPPattern {&lt;br /&gt;
    private static java.util.Calendar dateCreator = java.util.Calendar.getInstance();&lt;br /&gt;
    public static void main(String [] arguments) throws RemoteException{&lt;br /&gt;
        System.out.println(&amp;quot;Example for the HOPP pattern&amp;quot;);&lt;br /&gt;
        System.out.println();&lt;br /&gt;
        System.out.println(&amp;quot;This example will use RMI to demonstrate the HOPP pattern.&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot; In the sample, there will be two objects created, CalendarImpl&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot; and CalendarHOPP. The CalendarImpl object provides the true&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot; server-side implementation, while the CalendarHOPP would be&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot; a client or middle-tier representative. The CalendarHOPP will&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot; provide some functionality, in this case supplying the hostname&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot; in response to the getHost method.&amp;quot;);&lt;br /&gt;
        System.out.println();&lt;br /&gt;
        System.out.println(&amp;quot;Note: This example runs the rmiregistry, CalendarHOPP and CalendarImpl&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot; on the same machine.&amp;quot;);&lt;br /&gt;
        System.out.println();&lt;br /&gt;
        &lt;br /&gt;
        try{&lt;br /&gt;
            Process p1 = Runtime.getRuntime().exec(&amp;quot;rmic CalendarImpl&amp;quot;);&lt;br /&gt;
            Process p2 = Runtime.getRuntime().exec(&amp;quot;rmic CalendarHOPP&amp;quot;);&lt;br /&gt;
            p1.waitFor();&lt;br /&gt;
            p2.waitFor();&lt;br /&gt;
        }&lt;br /&gt;
        catch (IOException exc){&lt;br /&gt;
            System.err.println(&amp;quot;Unable to run rmic utility. Exiting application.&amp;quot;);&lt;br /&gt;
            System.exit(1);&lt;br /&gt;
        }&lt;br /&gt;
        catch (InterruptedException exc){&lt;br /&gt;
            System.err.println(&amp;quot;Threading problems encountered while using the rmic utility.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        System.out.println(&amp;quot;Starting the rmiregistry&amp;quot;);&lt;br /&gt;
        System.out.println();&lt;br /&gt;
        Process rmiProcess = null;&lt;br /&gt;
        try{&lt;br /&gt;
            rmiProcess = Runtime.getRuntime().exec(&amp;quot;rmiregistry&amp;quot;);&lt;br /&gt;
            Thread.sleep(15000);&lt;br /&gt;
        }&lt;br /&gt;
        catch (IOException exc){&lt;br /&gt;
            System.err.println(&amp;quot;Unable to start the rmiregistry. Exiting application.&amp;quot;);&lt;br /&gt;
            System.exit(1);&lt;br /&gt;
        }&lt;br /&gt;
        catch (InterruptedException exc){&lt;br /&gt;
            System.err.println(&amp;quot;Threading problems encountered when starting the rmiregistry.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        System.out.println(&amp;quot;Creating the CalendarImpl object, which provides the server-side implementation.&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot;(Note: If the CalendarImpl object does not have a file containing Appointments,&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot;  this call will produce an error message. This will not affect the example.)&amp;quot;);&lt;br /&gt;
        CalendarImpl remoteObject = new CalendarImpl();&lt;br /&gt;
        &lt;br /&gt;
        System.out.println();&lt;br /&gt;
        System.out.println(&amp;quot;Creating the CalendarHOPP object, which provides client-side functionality.&amp;quot;);&lt;br /&gt;
        CalendarHOPP localObject = new CalendarHOPP();&lt;br /&gt;
        &lt;br /&gt;
        System.out.println();&lt;br /&gt;
        System.out.println(&amp;quot;Getting the hostname. The CalendarHOPP will handle this method locally.&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot;Hostname is &amp;quot; + localObject.getHost());&lt;br /&gt;
        System.out.println();&lt;br /&gt;
        &lt;br /&gt;
        System.out.println(&amp;quot;Creating and adding appointments. The CalendarHOPP will forward&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot; these calls to the CalendarImpl object.&amp;quot;);&lt;br /&gt;
        Contact attendee = new ContactImpl(&amp;quot;Jenny&amp;quot;, &amp;quot;Yip&amp;quot;, &amp;quot;Chief Java Expert&amp;quot;, &amp;quot;MuchoJava LTD&amp;quot;);&lt;br /&gt;
        ArrayList contacts = new ArrayList();&lt;br /&gt;
        contacts.add(attendee);&lt;br /&gt;
        Location place = new LocationImpl(&amp;quot;Albuquerque, NM&amp;quot;);&lt;br /&gt;
        localObject.addAppointment(new Appointment(&amp;quot;Opening speeches at annual Java Guru&amp;quot;s dinner&amp;quot;,&lt;br /&gt;
            contacts, place, createDate(2001, 4, 1, 16, 0),&lt;br /&gt;
            createDate(2001, 4, 1, 18, 0)), createDate(2001, 4, 1, 0, 0));&lt;br /&gt;
        localObject.addAppointment(new Appointment(&amp;quot;Java Guru post-dinner Cafe time&amp;quot;,&lt;br /&gt;
            contacts, place, createDate(2001, 4, 1, 19, 30),&lt;br /&gt;
            createDate(2001, 4, 1, 21, 45)), createDate(2001, 4, 1, 0, 0));&lt;br /&gt;
        System.out.println(&amp;quot;Appointments added.&amp;quot;);&lt;br /&gt;
        System.out.println();&lt;br /&gt;
        &lt;br /&gt;
        System.out.println(&amp;quot;Getting the Appointments for a date. The CalendarHOPP will forward&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot; this call to the CalendarImpl object.&amp;quot;);&lt;br /&gt;
        System.out.println(localObject.getAppointments(createDate(2001, 4, 1, 0, 0)));&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public static Date createDate(int year, int month, int day, int hour, int minute){&lt;br /&gt;
        dateCreator.set(year, month, day, hour, minute);&lt;br /&gt;
        return dateCreator.getTime();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
interface Contact extends Serializable{&lt;br /&gt;
    public static final String SPACE = &amp;quot; &amp;quot;;&lt;br /&gt;
    public String getFirstName();&lt;br /&gt;
    public String getLastName();&lt;br /&gt;
    public String getTitle();&lt;br /&gt;
    public String getOrganization();&lt;br /&gt;
    &lt;br /&gt;
    public void setFirstName(String newFirstName);&lt;br /&gt;
    public void setLastName(String newLastName);&lt;br /&gt;
    public void setTitle(String newTitle);&lt;br /&gt;
    public void setOrganization(String newOrganization);&lt;br /&gt;
}&lt;br /&gt;
class ContactImpl implements Contact{&lt;br /&gt;
    private String firstName;&lt;br /&gt;
    private String lastName;&lt;br /&gt;
    private String title;&lt;br /&gt;
    private String organization;&lt;br /&gt;
    &lt;br /&gt;
    public ContactImpl(){}&lt;br /&gt;
    public ContactImpl(String newFirstName, String newLastName,&lt;br /&gt;
        String newTitle, String newOrganization){&lt;br /&gt;
            firstName = newFirstName;&lt;br /&gt;
            lastName = newLastName;&lt;br /&gt;
            title = newTitle;&lt;br /&gt;
            organization = newOrganization;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public String getFirstName(){ return firstName; }&lt;br /&gt;
    public String getLastName(){ return lastName; }&lt;br /&gt;
    public String getTitle(){ return title; }&lt;br /&gt;
    public String getOrganization(){ return organization; }&lt;br /&gt;
    &lt;br /&gt;
    public void setFirstName(String newFirstName){ firstName = newFirstName; }&lt;br /&gt;
    public void setLastName(String newLastName){ lastName = newLastName; }&lt;br /&gt;
    public void setTitle(String newTitle){ title = newTitle; }&lt;br /&gt;
    public void setOrganization(String newOrganization){ organization = newOrganization; }&lt;br /&gt;
    &lt;br /&gt;
    public String toString(){&lt;br /&gt;
        return firstName + SPACE + lastName;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
interface Location extends Serializable{&lt;br /&gt;
    public String getLocation();&lt;br /&gt;
    public void setLocation(String newLocation);&lt;br /&gt;
}&lt;br /&gt;
class LocationImpl implements Location{&lt;br /&gt;
    private String location;&lt;br /&gt;
    &lt;br /&gt;
    public LocationImpl(){ }&lt;br /&gt;
    public LocationImpl(String newLocation){&lt;br /&gt;
        location = newLocation;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public String getLocation(){ return location; }&lt;br /&gt;
    &lt;br /&gt;
    public void setLocation(String newLocation){ location = newLocation; }&lt;br /&gt;
    &lt;br /&gt;
    public String toString(){ return location; }&lt;br /&gt;
}&lt;br /&gt;
interface Calendar extends Remote{&lt;br /&gt;
    public String getHost() throws RemoteException;&lt;br /&gt;
    public ArrayList getAppointments(Date date) throws RemoteException;&lt;br /&gt;
    public void addAppointment(Appointment appointment, Date date) throws RemoteException;&lt;br /&gt;
}&lt;br /&gt;
class CalendarHOPP implements Calendar, java.io.Serializable{&lt;br /&gt;
    private static final String PROTOCOL = &amp;quot;rmi://&amp;quot;;&lt;br /&gt;
    private static final String REMOTE_SERVICE = &amp;quot;/calendarimpl&amp;quot;;&lt;br /&gt;
    private static final String HOPP_SERVICE = &amp;quot;calendar&amp;quot;;&lt;br /&gt;
    private static final String DEFAULT_HOST = &amp;quot;localhost&amp;quot;;&lt;br /&gt;
    private Calendar calendar;&lt;br /&gt;
    private String host;&lt;br /&gt;
    &lt;br /&gt;
    public CalendarHOPP(){&lt;br /&gt;
        this(DEFAULT_HOST);&lt;br /&gt;
    }&lt;br /&gt;
    public CalendarHOPP(String host){&lt;br /&gt;
        try {&lt;br /&gt;
            this.host = host;&lt;br /&gt;
            String url = PROTOCOL + host + REMOTE_SERVICE;&lt;br /&gt;
            calendar = (Calendar)Naming.lookup(url);&lt;br /&gt;
            Naming.rebind(HOPP_SERVICE, this);&lt;br /&gt;
        }&lt;br /&gt;
        catch (Exception exc){&lt;br /&gt;
            System.err.println(&amp;quot;Error using RMI to look up the CalendarImpl or register the CalendarHOPP &amp;quot; + exc);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public String getHost(){ return host; }&lt;br /&gt;
    public ArrayList getAppointments(Date date) throws RemoteException{ return calendar.getAppointments(date); }&lt;br /&gt;
    &lt;br /&gt;
    public void addAppointment(Appointment appointment, Date date) throws RemoteException { calendar.addAppointment(appointment, date); }&lt;br /&gt;
}&lt;br /&gt;
class CalendarImpl implements Calendar{&lt;br /&gt;
    private static final String REMOTE_SERVICE = &amp;quot;calendarimpl&amp;quot;;&lt;br /&gt;
    private static final String DEFAULT_FILE_NAME = &amp;quot;calendar.ser&amp;quot;;&lt;br /&gt;
    private HashMap appointmentCalendar = new HashMap();&lt;br /&gt;
    &lt;br /&gt;
    public CalendarImpl(){&lt;br /&gt;
        this(DEFAULT_FILE_NAME);&lt;br /&gt;
    }&lt;br /&gt;
    public CalendarImpl(String filename){&lt;br /&gt;
        File inputFile = new File(filename);&lt;br /&gt;
        appointmentCalendar = (HashMap)FileLoader.loadData(inputFile);&lt;br /&gt;
        if (appointmentCalendar == null){&lt;br /&gt;
            appointmentCalendar = new HashMap();&lt;br /&gt;
        }&lt;br /&gt;
        try {&lt;br /&gt;
            UnicastRemoteObject.exportObject(this);&lt;br /&gt;
            Naming.rebind(REMOTE_SERVICE, this);&lt;br /&gt;
        }&lt;br /&gt;
        catch (Exception exc){&lt;br /&gt;
            System.err.println(&amp;quot;Error using RMI to register the CalendarImpl &amp;quot; + exc);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public String getHost(){ return &amp;quot;&amp;quot;; }&lt;br /&gt;
    public ArrayList getAppointments(Date date){&lt;br /&gt;
        ArrayList returnValue = null;&lt;br /&gt;
        Long appointmentKey = new Long(date.getTime());&lt;br /&gt;
        if (appointmentCalendar.containsKey(appointmentKey)){&lt;br /&gt;
            returnValue = (ArrayList)appointmentCalendar.get(appointmentKey);&lt;br /&gt;
        }&lt;br /&gt;
        return returnValue;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void addAppointment(Appointment appointment, Date date){&lt;br /&gt;
        Long appointmentKey = new Long(date.getTime());&lt;br /&gt;
        if (appointmentCalendar.containsKey(appointmentKey)){&lt;br /&gt;
            ArrayList appointments = (ArrayList)appointmentCalendar.get(appointmentKey);&lt;br /&gt;
            appointments.add(appointment);&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
            ArrayList appointments = new ArrayList();&lt;br /&gt;
            appointments.add(appointment);&lt;br /&gt;
            appointmentCalendar.put(appointmentKey, appointments);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class FileLoader{&lt;br /&gt;
    public static Object loadData(File inputFile){&lt;br /&gt;
        Object returnValue = null;&lt;br /&gt;
        try{&lt;br /&gt;
            if (inputFile.exists()){&lt;br /&gt;
                if (inputFile.isFile()){&lt;br /&gt;
                    ObjectInputStream readIn = new ObjectInputStream(new FileInputStream(inputFile));&lt;br /&gt;
                    returnValue = readIn.readObject();&lt;br /&gt;
                    readIn.close();&lt;br /&gt;
                }&lt;br /&gt;
                else {&lt;br /&gt;
                    System.err.println(inputFile + &amp;quot; is a directory.&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            else {&lt;br /&gt;
                System.err.println(&amp;quot;File &amp;quot; + inputFile + &amp;quot; does not exist.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        catch (ClassNotFoundException exc){&lt;br /&gt;
            exc.printStackTrace();&lt;br /&gt;
            &lt;br /&gt;
        }&lt;br /&gt;
        catch (IOException exc){&lt;br /&gt;
            exc.printStackTrace();&lt;br /&gt;
            &lt;br /&gt;
        }&lt;br /&gt;
        return returnValue;&lt;br /&gt;
    }&lt;br /&gt;
    public static void storeData(File outputFile, Serializable data){&lt;br /&gt;
        try{&lt;br /&gt;
            ObjectOutputStream writeOut = new ObjectOutputStream(new FileOutputStream(outputFile));&lt;br /&gt;
            writeOut.writeObject(data);&lt;br /&gt;
            writeOut.close();&lt;br /&gt;
        }&lt;br /&gt;
        catch (IOException exc){&lt;br /&gt;
            exc.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Appointment implements Serializable{&lt;br /&gt;
    private String description;&lt;br /&gt;
    private ArrayList contacts;&lt;br /&gt;
    private Location location;&lt;br /&gt;
    private Date startDate;&lt;br /&gt;
    private Date endDate;&lt;br /&gt;
    public Appointment(String description, ArrayList contacts, Location location, Date startDate, Date endDate){&lt;br /&gt;
        this.description = description;&lt;br /&gt;
        this.contacts = contacts;&lt;br /&gt;
        this.location = location;&lt;br /&gt;
        this.startDate = startDate;&lt;br /&gt;
        this.endDate = endDate;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public String getDescription(){ return description; }&lt;br /&gt;
    public ArrayList getContacts(){ return contacts; }&lt;br /&gt;
    public Location getLocation(){ return location; }&lt;br /&gt;
    public Date getStartDate(){ return startDate; }&lt;br /&gt;
    public Date getEndDate(){ return endDate; }&lt;br /&gt;
    &lt;br /&gt;
    public void setDescription(String description){ this.description = description; }&lt;br /&gt;
    public void setContacts(ArrayList contacts){ this.contacts = contacts; }&lt;br /&gt;
    public void setLocation(Location location){ this.location = location; }&lt;br /&gt;
    public void setStartDate(Date startDate){ this.startDate = startDate; }&lt;br /&gt;
    public void setEndDate(Date endDate){ this.endDate = endDate; }&lt;br /&gt;
    &lt;br /&gt;
    public String toString(){&lt;br /&gt;
        return &amp;quot;Appointment:&amp;quot; + &amp;quot;\n    Description: &amp;quot; + description +&lt;br /&gt;
    &amp;quot;\n    Location: &amp;quot; + location + &amp;quot;\n    Start: &amp;quot; +&lt;br /&gt;
            startDate + &amp;quot;\n    End: &amp;quot; + endDate + &amp;quot;\n&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>