Thread: [mud4j-commit] SF.net SVN: mud4j: [62] trunk/mud4j-core/src/java/net/sf/mud4j
Status: Pre-Alpha
Brought to you by:
mpurland
From: <mpu...@us...> - 2006-12-24 23:10:23
|
Revision: 62 http://mud4j.svn.sourceforge.net/mud4j/?rev=62&view=rev Author: mpurland Date: 2006-12-24 15:10:20 -0800 (Sun, 24 Dec 2006) Log Message: ----------- Add start of dao implementations. Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/account/ trunk/mud4j-core/src/java/net/sf/mud4j/account/Account.java trunk/mud4j-core/src/java/net/sf/mud4j/dao/ trunk/mud4j-core/src/java/net/sf/mud4j/dao/AccountDao.java trunk/mud4j-core/src/java/net/sf/mud4j/dao/CharacterDao.java trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/ trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/AccountDaoHibernate.java trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/CharacterDaoHibernate.java Added: trunk/mud4j-core/src/java/net/sf/mud4j/account/Account.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/account/Account.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/account/Account.java 2006-12-24 23:10:20 UTC (rev 62) @@ -0,0 +1,60 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sf.mud4j.account; + +/** + * + * + * @author Matthew Purland + */ +public class Account { + // Username of the account + private String username; + // Password of the account + private String password; + /** + * Get the password. + * + * @return the password. + */ + public String getPassword() { + return this.password; + } + /** + * Set the password. + * + * @param password the password to set. + */ + public void setPassword(String password) { + this.password = password; + } + /** + * Get the username. + * + * @return the username. + */ + public String getUsername() { + return this.username; + } + /** + * Set the username. + * + * @param username the username to set. + */ + public void setUsername(String username) { + this.username = username; + } +} Added: trunk/mud4j-core/src/java/net/sf/mud4j/dao/AccountDao.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/dao/AccountDao.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/dao/AccountDao.java 2006-12-24 23:10:20 UTC (rev 62) @@ -0,0 +1,57 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sf.mud4j.dao; + +import java.util.List; + +import net.sf.mud4j.account.Account; + +import org.springframework.dao.DataAccessException; +import org.springframework.dao.PermissionDeniedDataAccessException; + +/** + * Account dao interface. + * + * @author Matthew Purland + */ +public interface AccountDao { + /** + * Get list of accounts. + * @return Returns a list of accounts. + * @throws DataAccessException in case of data access I/O problems + */ + List getAccounts() throws DataAccessException; + + /** + * Load an account from the username. + * + * @param username Username of the account to load. + * @return Returns an account from the username. + * @throws DataAccessException in case of data access I/O problems + */ + Account loadAccount(String username) throws DataAccessException; + + /** + * Load an account from the username accessed by a password. + * + * @param username Username of the account. + * @param password Password of the account to verify. + * @return Returns an account if verified. + * @throws DataAccessException in case of data access I/O + * @throws PermissionDeniedDataAccessException if password is incorrect + */ + Account loadAccount(String username, String password) throws DataAccessException, PermissionDeniedDataAccessException; +} Added: trunk/mud4j-core/src/java/net/sf/mud4j/dao/CharacterDao.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/dao/CharacterDao.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/dao/CharacterDao.java 2006-12-24 23:10:20 UTC (rev 62) @@ -0,0 +1,63 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sf.mud4j.dao; + +import java.util.List; + +import org.springframework.dao.DataAccessException; + +/** + * Character dao interface. + * + * @author Matthew Purland + */ +public interface CharacterDao { + /** + * Get a character that matches the characterId. + * + * @param characterId Character id to find character. + * @return Returns character from characterId + * + * @throws DataAccessException in case of data I/O problems + */ + public Character getCharacter(String characterId) throws DataAccessException; + + /** + * Get list of characters. + * + * @return Returns a list of characters. + * + * @throws DataAccessException in case of data I/O problems + */ + public List getCharacters() throws DataAccessException; + + /** + * Save and persist a character. + * @param character Character instance to save. + * + * @throws DataAccessException in case of data I/O problems + */ + public void saveCharacter(Character character) throws DataAccessException; + + /** + * Remove a character. + * + * @param character Character to remove. + * + * @throws DataAccessException in case of data I/O problems + */ + public void removeCharacter(String characterId) throws DataAccessException; +} Added: trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/AccountDaoHibernate.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/AccountDaoHibernate.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/AccountDaoHibernate.java 2006-12-24 23:10:20 UTC (rev 62) @@ -0,0 +1,65 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sf.mud4j.dao.hibernate; + +import java.util.List; + +import org.springframework.dao.DataAccessException; +import org.springframework.dao.PermissionDeniedDataAccessException; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; + +import net.sf.mud4j.account.Account; +import net.sf.mud4j.dao.AccountDao; + +/** + * Account dao implementation for hibernate. + * + * @author Matthew Purland + */ +public class AccountDaoHibernate extends HibernateDaoSupport implements AccountDao { + + /** + * {@inheritDoc} + */ + public List getAccounts() throws DataAccessException { + return getHibernateTemplate().find("from Account"); + } + + /** + * {@inheritDoc} + */ + public Account loadAccount(String username) throws DataAccessException { + Object account = getHibernateTemplate().load(Account.class, username); + + return (Account) account; + } + + /** + * {@inheritDoc} + */ + public Account loadAccount(String username, String password) throws DataAccessException, PermissionDeniedDataAccessException { + Account account = (Account) getHibernateTemplate().load(Account.class, username); + + if (!account.getPassword().equals(password)) { + throw new RuntimeException("Password is incorrect"); + //throw new DataAccessException("Password is incorrect."); + } + + return account; + } + + +} Added: trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/CharacterDaoHibernate.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/CharacterDaoHibernate.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/CharacterDaoHibernate.java 2006-12-24 23:10:20 UTC (rev 62) @@ -0,0 +1,60 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sf.mud4j.dao.hibernate; + +import java.util.List; + +import net.sf.mud4j.dao.CharacterDao; + +import org.springframework.dao.DataAccessException; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; + +/** + * Character dao for hibernate support. + * + * @author Matthew Purland + */ +public class CharacterDaoHibernate extends HibernateDaoSupport implements CharacterDao { + + /** + * {@inheritDoc} + */ + public Character getCharacter(String characterId) throws DataAccessException { + return (Character) getHibernateTemplate().get(Character.class, characterId); + } + + /** + * {@inheritDoc} + */ + public List getCharacters() throws DataAccessException { + return getHibernateTemplate().find("from Character"); + } + + /** + * {@inheritDoc} + */ + public void removeCharacter(String characterId) throws DataAccessException { + Object character = getHibernateTemplate().load(Character.class, characterId); + getHibernateTemplate().delete(character); + } + + /** + * {@inheritDoc} + */ + public void saveCharacter(Character character) throws DataAccessException { + getHibernateTemplate().save(character); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2007-01-07 21:02:11
|
Revision: 92 http://mud4j.svn.sourceforge.net/mud4j/?rev=92&view=rev Author: mpurland Date: 2007-01-07 13:02:06 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Add scripting manager interface. Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/scripting/ trunk/mud4j-core/src/java/net/sf/mud4j/scripting/ScriptingManager.java Added: trunk/mud4j-core/src/java/net/sf/mud4j/scripting/ScriptingManager.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/scripting/ScriptingManager.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/scripting/ScriptingManager.java 2007-01-07 21:02:06 UTC (rev 92) @@ -0,0 +1,31 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sf.mud4j.scripting; + +/** + * Provide interface for scripting managers that will allow different + * scripting engines to be loaded to load different scripts dynamically. + * + * This may include in the future for Groovy, Jython, Rhino, or Java scripting + * managers. When we say a Java scripting manager what is truly meant is for + * a class loader to dynamically compile and load a class dynamically for + * changed scripts. + * + * @author Matthew Purland + */ +public interface ScriptingManager { + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2007-01-07 21:03:33
|
Revision: 93 http://mud4j.svn.sourceforge.net/mud4j/?rev=93&view=rev Author: mpurland Date: 2007-01-07 13:03:31 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Add Login service interface. Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/security/ trunk/mud4j-core/src/java/net/sf/mud4j/security/LoginService.java Added: trunk/mud4j-core/src/java/net/sf/mud4j/security/LoginService.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/security/LoginService.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/security/LoginService.java 2007-01-07 21:03:31 UTC (rev 93) @@ -0,0 +1,27 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sf.mud4j.security; + +/** + * Provides login service for clients that need to login or verify login + * information. This might be useful for the presentation tier for + * validation. + * + * @author Matthew Purland + */ +public interface LoginService { + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2007-06-03 01:23:05
|
Revision: 125 http://mud4j.svn.sourceforge.net/mud4j/?rev=125&view=rev Author: mpurland Date: 2007-06-02 18:22:56 -0700 (Sat, 02 Jun 2007) Log Message: ----------- Add attribute interface. Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/attribute/ trunk/mud4j-core/src/java/net/sf/mud4j/attribute/Attribute.java Added: trunk/mud4j-core/src/java/net/sf/mud4j/attribute/Attribute.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/attribute/Attribute.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/attribute/Attribute.java 2007-06-03 01:22:56 UTC (rev 125) @@ -0,0 +1,25 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sf.mud4j.attribute; + +/** + * + * + * @author Matthew Purland + */ +public interface Attribute { + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2007-10-06 00:59:31
|
Revision: 154 http://mud4j.svn.sourceforge.net/mud4j/?rev=154&view=rev Author: mpurland Date: 2007-10-05 17:59:26 -0700 (Fri, 05 Oct 2007) Log Message: ----------- Add Tick and LoginService. Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/Tick.java trunk/mud4j-core/src/java/net/sf/mud4j/service/LoginService.java Added: trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/Tick.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/Tick.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/Tick.java 2007-10-06 00:59:26 UTC (rev 154) @@ -0,0 +1,5 @@ +package net.sf.mud4j.scheduling; + +public class Tick { + +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/Tick.java ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/mud4j-core/src/java/net/sf/mud4j/service/LoginService.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/service/LoginService.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/service/LoginService.java 2007-10-06 00:59:26 UTC (rev 154) @@ -0,0 +1,57 @@ +package net.sf.mud4j.service; +import net.sf.mud4j.account.Account; +import net.sf.mud4j.dao.AccountDao; + +import org.hibernate.ObjectNotFoundException; +import org.springframework.dao.DataAccessException; + + +/** + * Provides services for login validation and logging in. + * + * @author Matthew Purland + */ +public class LoginService { + private AccountDao accountDao; + + /** + * Set the account DAO for the service. + * + * @param accountDao Account DAO to set. + */ + public void setAccountDao(AccountDao accountDao) { + this.accountDao = accountDao; + } + + /** + * Validate a login through the AccountDAO. + * + * @param login Login to validate with. + * @param password Password to validate the login. + * @return Returns true if validation is successful. + */ + public boolean validateLogin(String login, String password) { + boolean accountValid = false; + Account account = null; + + try { + // Find the account by the login + account = accountDao.findAccount(login); + + if (account != null && account.validatePassword(password)) { + accountValid = true; + } + } + catch (DataAccessException ex) { + + } +// catch (ObjectRetrievalFailureException ex) { +// // Do nothing since we cannot validate an account +// } + catch (ObjectNotFoundException ex) { + System.err.println("Object not found ex caught."); + } + + return accountValid; + } +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/service/LoginService.java ___________________________________________________________________ Name: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2007-11-01 00:01:54
|
Revision: 159 http://mud4j.svn.sourceforge.net/mud4j/?rev=159&view=rev Author: mpurland Date: 2007-10-31 17:01:48 -0700 (Wed, 31 Oct 2007) Log Message: ----------- Add Startup. Add link/one-way and two-way location links. Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/startup/Startup.java trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLink.java trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLinkManager.java trunk/mud4j-core/src/java/net/sf/mud4j/world/link/OneWayLocationLink.java trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TileLocationLink.java trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TwoWayLocationLink.java Added: trunk/mud4j-core/src/java/net/sf/mud4j/startup/Startup.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/startup/Startup.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/startup/Startup.java 2007-11-01 00:01:48 UTC (rev 159) @@ -0,0 +1,19 @@ +package net.sf.mud4j.startup; + +import net.sf.mud4j.scheduling.QuartzSchedulingService; +import net.sf.mud4j.util.SpringHelper; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class Startup { + public static void main(String[] args) { + final boolean saveData = true; + ClassPathXmlApplicationContext appContext = SpringHelper.getClassPathXmlApplicationContext(saveData); + QuartzSchedulingService schedulingService = (QuartzSchedulingService) appContext.getBean("schedulingService"); + +// String[] groupNames = schedulingService.getGroupNames(); +// for (String groupName : groupNames) { +// System.out.println(groupName); +// } + } +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/startup/Startup.java ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLink.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLink.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLink.java 2007-11-01 00:01:48 UTC (rev 159) @@ -0,0 +1,29 @@ +package net.sf.mud4j.world.link; + +import java.util.Set; + +import net.sf.mud4j.world.Location; +import net.sf.mud4j.world.MoveableException; +import net.sf.mud4j.world.Placeable; + +/** + * Link between a set of {@link Location} objects. + * + * @author Matthew Purland + */ +public interface LocationLink<L extends Location> { + /** + * Get set of locations that are linked. + */ + Set<L> getLocations(); + + /** + * Move a placeable using the link to the appropriate location. + * + * @param placeable + * The placeable + * @throws MoveableException + * when the given placeable is not in the source location. + */ + void move(Placeable placeable) throws MoveableException; +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLink.java ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLinkManager.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLinkManager.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLinkManager.java 2007-11-01 00:01:48 UTC (rev 159) @@ -0,0 +1,20 @@ +package net.sf.mud4j.world.link; + +import java.util.HashMap; +import java.util.Map; + +import net.sf.mud4j.world.Location; + +public class LocationLinkManager { + Map<Location, LocationLink> locationToLocationLinkMap = new HashMap<Location, LocationLink>(); + + public void addLink(Location location, LocationLink locationLink) { + locationToLocationLinkMap.put(location, locationLink); + } + + public void removeLink(LocationLink locationLink) { + locationToLocationLinkMap.remove(locationLink); + } + + //public Set<LocationLink> +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/LocationLinkManager.java ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/OneWayLocationLink.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/link/OneWayLocationLink.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/link/OneWayLocationLink.java 2007-11-01 00:01:48 UTC (rev 159) @@ -0,0 +1,15 @@ +package net.sf.mud4j.world.link; + +import net.sf.mud4j.world.Location; + +/** + * One-way link between a source and destination location. + * + * @author Matthew Purland + * + * @param <T> + */ +public interface OneWayLocationLink <T extends Location> extends LocationLink<T> { + + +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/OneWayLocationLink.java ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TileLocationLink.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TileLocationLink.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TileLocationLink.java 2007-11-01 00:01:48 UTC (rev 159) @@ -0,0 +1,74 @@ +package net.sf.mud4j.world.link; + +import java.util.HashSet; +import java.util.Set; + +import net.sf.mud4j.world.Direction; +import net.sf.mud4j.world.MoveableException; +import net.sf.mud4j.world.Placeable; +import net.sf.mud4j.world.TileLocation; + +public class TileLocationLink implements TwoWayLocationLink<TileLocation> { + + private TileLocation sourceLocation; + private TileLocation destLocation; + private Direction directionFromSourceLocation; + private Set<TileLocation> locationSet; + + public TileLocationLink(TileLocation sourceLocation, + TileLocation destLocation, Direction directionFromSourceLocation) { + this.sourceLocation = sourceLocation; + this.destLocation = destLocation; + this.directionFromSourceLocation = directionFromSourceLocation; + } + + /** + * {@inheritDoc} + */ + @Override + public Set<TileLocation> getLocations() { + if (locationSet == null) { + locationSet = new HashSet<TileLocation>(); + locationSet.add(sourceLocation); + locationSet.add(destLocation); + } + return locationSet; + } + + /** + * {@inheritDoc} + */ + @Override + public TileLocation getDestination() { + return destLocation; + } + + /** + * {@inheritDoc} + */ + @Override + public TileLocation getSource() { + return sourceLocation; + } + + /** + * {@inheritDoc} + */ + @Override + public void move(Placeable placeable) throws MoveableException { + boolean inSourceLocation = placeable.getCurrentLocation() != null + && placeable.getCurrentLocation().equals(sourceLocation); + boolean inDestLocation = placeable.getCurrentLocation() != null + && placeable.getCurrentLocation().equals(destLocation); + + if (inSourceLocation) { + placeable.place(destLocation); + } else if (inDestLocation) { + placeable.place(sourceLocation); + } else { + throw new MoveableException("Placeable " + placeable + + " is not in source or destination location in link."); + } + } + +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TileLocationLink.java ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TwoWayLocationLink.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TwoWayLocationLink.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TwoWayLocationLink.java 2007-11-01 00:01:48 UTC (rev 159) @@ -0,0 +1,17 @@ +package net.sf.mud4j.world.link; + +import net.sf.mud4j.world.Location; + +/** + * Two-way link between a source and destination location. The term of source + * and destination is simply used to represent two locations. + * + * @author Matthew Purland + * + * @param <T> + */ +public interface TwoWayLocationLink<T extends Location> extends LocationLink<T> { + T getSource(); + + T getDestination(); +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/world/link/TwoWayLocationLink.java ___________________________________________________________________ Name: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |