Source Code Cross Referenced for BaseAliasService.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » alias » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.alias.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/alias/tags/sakai_2-4-1/alias-impl/impl/src/java/org/sakaiproject/alias/impl/BaseAliasService.java $
0003:         * $Id: BaseAliasService.java 10978 2006-06-21 18:48:35Z ggolden@umich.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
0007:         * 
0008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
0009:         * you may not use this file except in compliance with the License. 
0010:         * You may obtain a copy of the License at
0011:         * 
0012:         *      http://www.opensource.org/licenses/ecl1.php
0013:         * 
0014:         * Unless required by applicable law or agreed to in writing, software 
0015:         * distributed under the License is distributed on an "AS IS" BASIS, 
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
0017:         * See the License for the specific language governing permissions and 
0018:         * limitations under the License.
0019:         *
0020:         **********************************************************************************/package org.sakaiproject.alias.impl;
0021:
0022:        import java.util.Collection;
0023:        import java.util.Iterator;
0024:        import java.util.List;
0025:        import java.util.Map;
0026:        import java.util.Set;
0027:        import java.util.Stack;
0028:
0029:        import org.apache.commons.logging.Log;
0030:        import org.apache.commons.logging.LogFactory;
0031:        import org.sakaiproject.alias.api.Alias;
0032:        import org.sakaiproject.alias.api.AliasEdit;
0033:        import org.sakaiproject.alias.api.AliasService;
0034:        import org.sakaiproject.authz.api.FunctionManager;
0035:        import org.sakaiproject.authz.api.SecurityService;
0036:        import org.sakaiproject.component.api.ServerConfigurationService;
0037:        import org.sakaiproject.entity.api.Edit;
0038:        import org.sakaiproject.entity.api.Entity;
0039:        import org.sakaiproject.entity.api.EntityManager;
0040:        import org.sakaiproject.entity.api.HttpAccess;
0041:        import org.sakaiproject.entity.api.Reference;
0042:        import org.sakaiproject.entity.api.ResourceProperties;
0043:        import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0044:        import org.sakaiproject.event.api.EventTrackingService;
0045:        import org.sakaiproject.exception.IdInvalidException;
0046:        import org.sakaiproject.exception.IdUnusedException;
0047:        import org.sakaiproject.exception.IdUsedException;
0048:        import org.sakaiproject.exception.InUseException;
0049:        import org.sakaiproject.exception.PermissionException;
0050:        import org.sakaiproject.memory.api.Cache;
0051:        import org.sakaiproject.memory.api.MemoryService;
0052:        import org.sakaiproject.site.api.SiteService;
0053:        import org.sakaiproject.time.api.Time;
0054:        import org.sakaiproject.time.api.TimeService;
0055:        import org.sakaiproject.tool.api.SessionBindingEvent;
0056:        import org.sakaiproject.tool.api.SessionBindingListener;
0057:        import org.sakaiproject.tool.api.SessionManager;
0058:        import org.sakaiproject.user.api.User;
0059:        import org.sakaiproject.user.api.UserDirectoryService;
0060:        import org.sakaiproject.util.BaseResourceProperties;
0061:        import org.sakaiproject.util.BaseResourcePropertiesEdit;
0062:        import org.sakaiproject.util.StorageUser;
0063:        import org.sakaiproject.util.StringUtil;
0064:        import org.sakaiproject.util.Validator;
0065:        import org.w3c.dom.Document;
0066:        import org.w3c.dom.Element;
0067:        import org.w3c.dom.Node;
0068:        import org.w3c.dom.NodeList;
0069:
0070:        /**
0071:         * <p>
0072:         * BaseAliasService is ...
0073:         * </p>
0074:         */
0075:        public abstract class BaseAliasService implements  AliasService,
0076:                StorageUser {
0077:            /** Our logger. */
0078:            private static Log M_log = LogFactory
0079:                    .getLog(BaseAliasService.class);
0080:
0081:            /** Storage manager for this service. */
0082:            protected Storage m_storage = null;
0083:
0084:            /** The initial portion of a relative access point URL. */
0085:            protected String m_relativeAccessPoint = null;
0086:
0087:            /** A cache of calls to the service and the results. */
0088:            protected Cache m_callCache = null;
0089:
0090:            /**********************************************************************************************************************************************************************************************************************************************************
0091:             * Abstractions, etc.
0092:             *********************************************************************************************************************************************************************************************************************************************************/
0093:
0094:            /**
0095:             * Construct storage for this service.
0096:             */
0097:            protected abstract Storage newStorage();
0098:
0099:            /**
0100:             * Access the partial URL that forms the root of resource URLs.
0101:             * 
0102:             * @param relative
0103:             *        if true, form within the access path only (i.e. starting with /content)
0104:             * @return the partial URL that forms the root of resource URLs.
0105:             */
0106:            protected String getAccessPoint(boolean relative) {
0107:                return (relative ? "" : serverConfigurationService()
0108:                        .getAccessUrl())
0109:                        + m_relativeAccessPoint;
0110:
0111:            } // getAccessPoint
0112:
0113:            /**
0114:             * Access the internal reference which can be used to access the resource from within the system.
0115:             * 
0116:             * @param id
0117:             *        The alias id string.
0118:             * @return The the internal reference which can be used to access the resource from within the system.
0119:             */
0120:            public String aliasReference(String id) {
0121:                return getAccessPoint(true) + Entity.SEPARATOR + id;
0122:
0123:            } // aliasReference
0124:
0125:            /**
0126:             * Access the alias id extracted from a alias reference.
0127:             * 
0128:             * @param ref
0129:             *        The alias reference string.
0130:             * @return The the alias id extracted from a alias reference.
0131:             */
0132:            protected String aliasId(String ref) {
0133:                String start = getAccessPoint(true) + Entity.SEPARATOR;
0134:                int i = ref.indexOf(start);
0135:                if (i == -1)
0136:                    return ref;
0137:                String id = ref.substring(i + start.length());
0138:                return id;
0139:
0140:            } // aliasId
0141:
0142:            /**
0143:             * Check security permission.
0144:             * 
0145:             * @param lock
0146:             *        The lock id string.
0147:             * @param resource
0148:             *        The resource reference string, or null if no resource is involved.
0149:             * @return true if allowed, false if not
0150:             */
0151:            protected boolean unlockCheck(String lock, String resource) {
0152:                if (!securityService().unlock(lock, resource)) {
0153:                    return false;
0154:                }
0155:
0156:                return true;
0157:
0158:            } // unlockCheck
0159:
0160:            /**
0161:             * Check security permission.
0162:             * 
0163:             * @param lock
0164:             *        The lock id string.
0165:             * @param resource
0166:             *        The resource reference string, or null if no resource is involved.
0167:             * @exception PermissionException
0168:             *            Thrown if the user does not have access
0169:             */
0170:            protected void unlock(String lock, String resource)
0171:                    throws PermissionException {
0172:                if (!unlockCheck(lock, resource)) {
0173:                    throw new PermissionException(sessionManager()
0174:                            .getCurrentSessionUserId(), lock, resource);
0175:                }
0176:
0177:            } // unlock
0178:
0179:            /**
0180:             * Check security permission, target modify based.
0181:             * 
0182:             * @param target
0183:             *        The target resource reference string.
0184:             * @return true if allowed, false if not
0185:             */
0186:            protected boolean unlockTargetCheck(String target) {
0187:                // check the target for modify access.
0188:                // TODO: this is setup only for sites and mail archive channels, we need an Entity Model based generic "allowModify()" -ggolden.
0189:                Reference ref = entityManager().newReference(target);
0190:                if (ref.getType().equals(SiteService.APPLICATION_ID)) {
0191:                    return siteService().allowUpdateSite(ref.getId());
0192:                }
0193:
0194:                // TODO: fake this dependency (MailArchiveService.APPLICATION_ID) to keep the mailarchive dependencies away -ggolden
0195:                else if (ref.getType().equals("sakai:mailarchive")) {
0196:                    // base this on site update, too
0197:                    return siteService().allowUpdateSite(ref.getContext());
0198:                }
0199:
0200:                return false;
0201:
0202:            } // unlockTargetCheck
0203:
0204:            /**
0205:             * Create the live properties for the user.
0206:             */
0207:            protected void addLiveProperties(ResourcePropertiesEdit props) {
0208:                String current = sessionManager().getCurrentSessionUserId();
0209:
0210:                props.addProperty(ResourceProperties.PROP_CREATOR, current);
0211:                props.addProperty(ResourceProperties.PROP_MODIFIED_BY, current);
0212:
0213:                String now = timeService().newTime().toString();
0214:                props.addProperty(ResourceProperties.PROP_CREATION_DATE, now);
0215:                props.addProperty(ResourceProperties.PROP_MODIFIED_DATE, now);
0216:
0217:            } // addLiveProperties
0218:
0219:            /**
0220:             * Update the live properties for a user for when modified.
0221:             */
0222:            protected void addLiveUpdateProperties(ResourcePropertiesEdit props) {
0223:                String current = sessionManager().getCurrentSessionUserId();
0224:
0225:                props.addProperty(ResourceProperties.PROP_MODIFIED_BY, current);
0226:                props.addProperty(ResourceProperties.PROP_MODIFIED_DATE,
0227:                        timeService().newTime().toString());
0228:
0229:            } // addLiveUpdateProperties
0230:
0231:            /**********************************************************************************************************************************************************************************************************************************************************
0232:             * Dependencies
0233:             *********************************************************************************************************************************************************************************************************************************************************/
0234:
0235:            /**
0236:             * @return the MemoryService collaborator.
0237:             */
0238:            protected abstract MemoryService memoryService();
0239:
0240:            /**
0241:             * @return the ServerConfigurationService collaborator.
0242:             */
0243:            protected abstract ServerConfigurationService serverConfigurationService();
0244:
0245:            /**
0246:             * @return the EntityManager collaborator.
0247:             */
0248:            protected abstract EntityManager entityManager();
0249:
0250:            /**
0251:             * @return the SecurityService collaborator.
0252:             */
0253:            protected abstract SecurityService securityService();
0254:
0255:            /**
0256:             * @return the SessionManager collaborator.
0257:             */
0258:            protected abstract SessionManager sessionManager();
0259:
0260:            /**
0261:             * @return the SiteService collaborator.
0262:             */
0263:            protected abstract SiteService siteService();
0264:
0265:            /**
0266:             * @return the TimeService collaborator.
0267:             */
0268:            protected abstract TimeService timeService();
0269:
0270:            /**
0271:             * @return the FunctionManager collaborator.
0272:             */
0273:            protected abstract FunctionManager functionManager();
0274:
0275:            /**
0276:             * @return the EventTrackingService collaborator.
0277:             */
0278:            protected abstract EventTrackingService eventTrackingService();
0279:
0280:            /**
0281:             * @return the UserDirectoryService collaborator.
0282:             */
0283:            protected abstract UserDirectoryService userDirectoryService();
0284:
0285:            /**********************************************************************************************************************************************************************************************************************************************************
0286:             * Configuration
0287:             *********************************************************************************************************************************************************************************************************************************************************/
0288:
0289:            /** The # seconds to cache gets. 0 disables the cache. */
0290:            protected int m_cacheSeconds = 0;
0291:
0292:            /**
0293:             * Set the # minutes to cache a get.
0294:             * 
0295:             * @param time
0296:             *        The # minutes to cache a get (as an integer string).
0297:             */
0298:            public void setCacheMinutes(String time) {
0299:                m_cacheSeconds = Integer.parseInt(time) * 60;
0300:            }
0301:
0302:            /** The # seconds to cache gets. 0 disables the cache. */
0303:            protected int m_cacheCleanerSeconds = 0;
0304:
0305:            /**
0306:             * Set the # minutes between cache cleanings.
0307:             * 
0308:             * @param time
0309:             *        The # minutes between cache cleanings. (as an integer string).
0310:             */
0311:            public void setCacheCleanerMinutes(String time) {
0312:                m_cacheCleanerSeconds = Integer.parseInt(time) * 60;
0313:            }
0314:
0315:            /**********************************************************************************************************************************************************************************************************************************************************
0316:             * Init and Destroy
0317:             *********************************************************************************************************************************************************************************************************************************************************/
0318:
0319:            /**
0320:             * Final initialization, once all dependencies are set.
0321:             */
0322:            public void init() {
0323:                try {
0324:                    m_relativeAccessPoint = REFERENCE_ROOT;
0325:
0326:                    // construct storage and read
0327:                    m_storage = newStorage();
0328:                    m_storage.open();
0329:
0330:                    // <= 0 indicates no caching desired
0331:                    if ((m_cacheSeconds > 0) && (m_cacheCleanerSeconds > 0)) {
0332:                        // build a synchronized map for the call cache, automatiaclly checking for expiration every 15 mins, expire on user events, too.
0333:                        m_callCache = memoryService().newHardCache(
0334:                                m_cacheCleanerSeconds, aliasReference(""));
0335:                    }
0336:
0337:                    // register as an entity producer
0338:                    entityManager()
0339:                            .registerEntityProducer(this , REFERENCE_ROOT);
0340:
0341:                    // register functions
0342:                    functionManager().registerFunction(SECURE_ADD_ALIAS);
0343:                    functionManager().registerFunction(SECURE_UPDATE_ALIAS);
0344:                    functionManager().registerFunction(SECURE_REMOVE_ALIAS);
0345:
0346:                    M_log.info("init()" + " - caching minutes: "
0347:                            + m_cacheSeconds / 60
0348:                            + " - cache cleaner minutes: "
0349:                            + m_cacheCleanerSeconds / 60);
0350:                } catch (Throwable t) {
0351:                    M_log.warn("init(): ", t);
0352:                }
0353:
0354:            } // init
0355:
0356:            /**
0357:             * Returns to uninitialized state.
0358:             */
0359:            public void destroy() {
0360:                m_storage.close();
0361:                m_storage = null;
0362:
0363:                M_log.info("destroy()");
0364:            }
0365:
0366:            /**********************************************************************************************************************************************************************************************************************************************************
0367:             * AliasService implementation
0368:             *********************************************************************************************************************************************************************************************************************************************************/
0369:
0370:            /**
0371:             * Check if the current user has permission to set this alias.
0372:             * 
0373:             * @param alias
0374:             *        The alias.
0375:             * @param target
0376:             *        The resource reference string alias target.
0377:             * @return true if the current user has permission to set this alias, false if not.
0378:             */
0379:            public boolean allowSetAlias(String alias, String target) {
0380:                return unlockTargetCheck(target);
0381:
0382:            } // allowSetAlias
0383:
0384:            /**
0385:             * Allocate an alias for a resource
0386:             * 
0387:             * @param alias
0388:             *        The alias.
0389:             * @param target
0390:             *        The resource reference string alias target.
0391:             * @throws IdUsedException
0392:             *         if the alias is already used.
0393:             * @throws IdInvalidException
0394:             *         if the alias id is invalid.
0395:             * @throws PermissionException
0396:             *         if the current user does not have permission to set this alias.
0397:             */
0398:            public void setAlias(String alias, String target)
0399:                    throws IdUsedException, IdInvalidException,
0400:                    PermissionException {
0401:                // check for a valid alias name
0402:                Validator.checkResourceId(alias);
0403:
0404:                if (!unlockTargetCheck(target)) {
0405:                    throw new PermissionException(sessionManager()
0406:                            .getCurrentSessionUserId(), SECURE_ADD_ALIAS,
0407:                            target);
0408:                }
0409:
0410:                // attempt to register this alias with storage - if it's in use, this will return null
0411:                AliasEdit a = m_storage.put(alias);
0412:                if (a == null) {
0413:                    throw new IdUsedException(alias);
0414:                }
0415:                a.setTarget(target);
0416:
0417:                // update the properties
0418:                addLiveUpdateProperties(a.getPropertiesEdit());
0419:
0420:                // complete the edit
0421:                m_storage.commit(a);
0422:
0423:                // track it
0424:                eventTrackingService().post(
0425:                        eventTrackingService().newEvent(SECURE_ADD_ALIAS,
0426:                                aliasReference(alias), true));
0427:
0428:            } // setAlias
0429:
0430:            /**
0431:             * Check to see if the current user can remove this alias.
0432:             * 
0433:             * @param alias
0434:             *        The alias.
0435:             * @return true if the current user can remove this alias, false if not.
0436:             */
0437:            public boolean allowRemoveAlias(String alias) {
0438:                return unlockCheck(SECURE_REMOVE_ALIAS, aliasReference(alias));
0439:
0440:            } // allowRemoveAlias
0441:
0442:            /**
0443:             * Remove an alias.
0444:             * 
0445:             * @param alias
0446:             *        The alias.
0447:             * @exception IdUnusedException
0448:             *            if not found.
0449:             * @exception PermissionException
0450:             *            if the current user does not have permission to remove this alias.
0451:             * @exception InUseException
0452:             *            if the Alias object is locked by someone else.
0453:             */
0454:            public void removeAlias(String alias) throws IdUnusedException,
0455:                    PermissionException, InUseException {
0456:                AliasEdit a = edit(alias);
0457:                remove(a);
0458:
0459:            } // removeAlias
0460:
0461:            /**
0462:             * Check to see if the current user can remove these aliasese for this target resource reference.
0463:             * 
0464:             * @param target
0465:             *        The target resource reference string.
0466:             * @return true if the current user can remove these aliasese for this target resource reference, false if not.
0467:             */
0468:            public boolean allowRemoveTargetAliases(String target) {
0469:                return unlockTargetCheck(target);
0470:
0471:            } // allowRemoveTargetAliases
0472:
0473:            /**
0474:             * Remove all aliases for this target resource reference, if any.
0475:             * 
0476:             * @param target
0477:             *        The target resource reference string.
0478:             * @throws PermissionException
0479:             *         if the current user does not have permission to remove these aliases.
0480:             */
0481:            public void removeTargetAliases(String target)
0482:                    throws PermissionException {
0483:                if (!unlockTargetCheck(target)) {
0484:                    throw new PermissionException(sessionManager()
0485:                            .getCurrentSessionUserId(), SECURE_REMOVE_ALIAS,
0486:                            target);
0487:                }
0488:
0489:                List all = getAliases(target);
0490:                for (Iterator iAll = all.iterator(); iAll.hasNext();) {
0491:                    Alias alias = (Alias) iAll.next();
0492:                    try {
0493:                        AliasEdit a = m_storage.edit(alias.getId());
0494:                        if (a != null) {
0495:                            // complete the edit
0496:                            m_storage.remove(a);
0497:
0498:                            // track it
0499:                            eventTrackingService().post(
0500:                                    eventTrackingService().newEvent(
0501:                                            SECURE_REMOVE_ALIAS,
0502:                                            a.getReference(), true));
0503:                        }
0504:                    } catch (Exception ignore) {
0505:                    }
0506:                }
0507:
0508:            } // removeTargetAliases
0509:
0510:            /**
0511:             * Find the target resource reference string associated with this alias.
0512:             * 
0513:             * @param alias
0514:             *        The alias.
0515:             * @return The target resource reference string associated with this alias.
0516:             * @throws IdUnusedException
0517:             *         if the alias is not defined.
0518:             */
0519:            public String getTarget(String alias) throws IdUnusedException {
0520:                // check the cache
0521:                String ref = aliasReference(alias);
0522:                if ((m_callCache != null) && (m_callCache.containsKey(ref))) {
0523:                    return (String) m_callCache.get(ref);
0524:                }
0525:
0526:                BaseAliasEdit a = (BaseAliasEdit) m_storage.get(alias);
0527:                if (a == null)
0528:                    throw new IdUnusedException(alias);
0529:
0530:                // cache
0531:                if (m_callCache != null)
0532:                    m_callCache.put(ref, a.getTarget(), m_cacheSeconds);
0533:
0534:                return a.getTarget();
0535:
0536:            } // getTarget
0537:
0538:            /**
0539:             * Find all the aliases defined for this target.
0540:             * 
0541:             * @param target
0542:             *        The target resource reference string.
0543:             * @return A list (Alias) of all the aliases defined for this target.
0544:             */
0545:            public List getAliases(String target) {
0546:                List allForTarget = m_storage.getAll(target);
0547:
0548:                return allForTarget;
0549:
0550:            } // getAliases
0551:
0552:            /**
0553:             * Find all the aliases defined for this target, within the record range given (sorted by id).
0554:             * 
0555:             * @param target
0556:             *        The target resource reference string.
0557:             * @param first
0558:             *        The first record position to return.
0559:             * @param last
0560:             *        The last record position to return.
0561:             * @return A list (Alias) of all the aliases defined for this target, within the record range given (sorted by id).
0562:             */
0563:            public List getAliases(String target, int first, int last) {
0564:                List allForTarget = m_storage.getAll(target, first, last);
0565:
0566:                return allForTarget;
0567:
0568:            } // getAliases
0569:
0570:            /**
0571:             * Find all the aliases within the record range given (sorted by id).
0572:             * 
0573:             * @param first
0574:             *        The first record position to return.
0575:             * @param last
0576:             *        The last record position to return.
0577:             * @return A list (Alias) of all the aliases within the record range given (sorted by id).
0578:             */
0579:            public List getAliases(int first, int last) {
0580:                List all = m_storage.getAll(first, last);
0581:
0582:                return all;
0583:
0584:            } // getAliases
0585:
0586:            /**
0587:             * {@inheritDoc}
0588:             */
0589:            public int countAliases() {
0590:                return m_storage.count();
0591:            }
0592:
0593:            /**
0594:             * {@inheritDoc}
0595:             */
0596:            public List searchAliases(String criteria, int first, int last) {
0597:                return m_storage.search(criteria, first, last);
0598:            }
0599:
0600:            /**
0601:             * {@inheritDoc}
0602:             */
0603:            public int countSearchAliases(String criteria) {
0604:                return m_storage.countSearch(criteria);
0605:            }
0606:
0607:            /**
0608:             * Check to see if the current user can add an alias.
0609:             * 
0610:             * @return true if the current user can add an alias, false if not.
0611:             */
0612:            public boolean allowAdd() {
0613:                return unlockCheck(SECURE_ADD_ALIAS, aliasReference(""));
0614:
0615:            } // allowAdd
0616:
0617:            /**
0618:             * Add a new alias. Must commit() to make official, or cancel() when done!
0619:             * 
0620:             * @param id
0621:             *        The alias id.
0622:             * @return A locked AliasEdit object (reserving the id).
0623:             * @exception IdInvalidException
0624:             *            if the alias id is invalid.
0625:             * @exception IdUsedException
0626:             *            if the alias id is already used.
0627:             * @exception PermissionException
0628:             *            if the current user does not have permission to add an alias.
0629:             */
0630:            public AliasEdit add(String id) throws IdInvalidException,
0631:                    IdUsedException, PermissionException {
0632:                // check for a valid user name
0633:                Validator.checkResourceId(id);
0634:
0635:                // check security (throws if not permitted)
0636:                unlock(SECURE_ADD_ALIAS, aliasReference(id));
0637:
0638:                // reserve an alias with this id from the info store - if it's in use, this will return null
0639:                AliasEdit a = m_storage.put(id);
0640:                if (a == null) {
0641:                    throw new IdUsedException(id);
0642:                }
0643:
0644:                ((BaseAliasEdit) a).setEvent(SECURE_ADD_ALIAS);
0645:
0646:                return a;
0647:
0648:            } // add
0649:
0650:            /**
0651:             * Check to see if the current user can edit this alias.
0652:             * 
0653:             * @param id
0654:             *        The alias id string.
0655:             * @return true if the current user can edit this alias, false if not.
0656:             */
0657:            public boolean allowEdit(String id) {
0658:                return unlockCheck(SECURE_UPDATE_ALIAS, aliasReference(id));
0659:
0660:            } // allowEdit
0661:
0662:            /**
0663:             * Get a locked alias object for editing. Must commit() to make official, or cancel() (or remove()) when done!
0664:             * 
0665:             * @param id
0666:             *        The alias id string.
0667:             * @return An AliasEdit object for editing.
0668:             * @exception IdUnusedException
0669:             *            if not found.
0670:             * @exception PermissionException
0671:             *            if the current user does not have permission to mess with this alias.
0672:             * @exception InUseException
0673:             *            if the Alias object is locked by someone else.
0674:             */
0675:            public AliasEdit edit(String id) throws IdUnusedException,
0676:                    PermissionException, InUseException {
0677:                if (id == null)
0678:                    throw new IdUnusedException("null");
0679:
0680:                // check security (throws if not permitted)
0681:                unlock(SECURE_UPDATE_ALIAS, aliasReference(id));
0682:
0683:                // check for existance
0684:                if (!m_storage.check(id)) {
0685:                    throw new IdUnusedException(id);
0686:                }
0687:
0688:                // ignore the cache - get the user with a lock from the info store
0689:                AliasEdit a = m_storage.edit(id);
0690:                if (a == null)
0691:                    throw new InUseException(id);
0692:
0693:                ((BaseAliasEdit) a).setEvent(SECURE_UPDATE_ALIAS);
0694:
0695:                return a;
0696:
0697:            } // edit
0698:
0699:            /**
0700:             * Commit the changes made to a AliasEdit object, and release the lock. The AliasEdit is disabled, and not to be used after this call.
0701:             * 
0702:             * @param user
0703:             *        The AliasEdit object to commit.
0704:             */
0705:            public void commit(AliasEdit edit) {
0706:                // check for closed edit
0707:                if (!edit.isActiveEdit()) {
0708:                    try {
0709:                        throw new Exception();
0710:                    } catch (Exception e) {
0711:                        M_log.warn("commit(): closed AliasEdit", e);
0712:                    }
0713:                    return;
0714:                }
0715:
0716:                // update the properties
0717:                addLiveUpdateProperties(edit.getPropertiesEdit());
0718:
0719:                // complete the edit
0720:                m_storage.commit(edit);
0721:
0722:                // track it
0723:                eventTrackingService().post(
0724:                        eventTrackingService().newEvent(
0725:                                ((BaseAliasEdit) edit).getEvent(),
0726:                                edit.getReference(), true));
0727:
0728:                // close the edit object
0729:                ((BaseAliasEdit) edit).closeEdit();
0730:
0731:            } // commit
0732:
0733:            /**
0734:             * Cancel the changes made to a AliasEdit object, and release the lock. The AliasEdit is disabled, and not to be used after this call.
0735:             * 
0736:             * @param user
0737:             *        The AliasEdit object to commit.
0738:             */
0739:            public void cancel(AliasEdit edit) {
0740:                // check for closed edit
0741:                if (!edit.isActiveEdit()) {
0742:                    try {
0743:                        throw new Exception();
0744:                    } catch (Exception e) {
0745:                        M_log.warn("cancel(): closed AliasEdit", e);
0746:                    }
0747:                    return;
0748:                }
0749:
0750:                // release the edit lock
0751:                m_storage.cancel(edit);
0752:
0753:                // close the edit object
0754:                ((BaseAliasEdit) edit).closeEdit();
0755:
0756:            } // cancel
0757:
0758:            /**
0759:             * Remove this alias information - it must be a user with a lock from edit(). The AliasEdit is disabled, and not to be used after this call.
0760:             * 
0761:             * @param edit
0762:             *        The locked AliasEdit object to remove.
0763:             * @exception PermissionException
0764:             *            if the current user does not have permission to remove this alias.
0765:             */
0766:            public void remove(AliasEdit edit) throws PermissionException {
0767:                // check for closed edit
0768:                if (!edit.isActiveEdit()) {
0769:                    try {
0770:                        throw new Exception();
0771:                    } catch (Exception e) {
0772:                        M_log.warn("remove(): closed AliasEdit", e);
0773:                    }
0774:                    return;
0775:                }
0776:
0777:                // check security (throws if not permitted)
0778:                unlock(SECURE_REMOVE_ALIAS, edit.getReference());
0779:
0780:                // complete the edit
0781:                m_storage.remove(edit);
0782:
0783:                // track it
0784:                eventTrackingService().post(
0785:                        eventTrackingService().newEvent(SECURE_REMOVE_ALIAS,
0786:                                edit.getReference(), true));
0787:
0788:                // close the edit object
0789:                ((BaseAliasEdit) edit).closeEdit();
0790:
0791:            } // remove
0792:
0793:            /**********************************************************************************************************************************************************************************************************************************************************
0794:             * EntityProducer implementation
0795:             *********************************************************************************************************************************************************************************************************************************************************/
0796:
0797:            /**
0798:             * {@inheritDoc}
0799:             */
0800:            public String getLabel() {
0801:                return "alias";
0802:            }
0803:
0804:            /**
0805:             * {@inheritDoc}
0806:             */
0807:            public boolean willArchiveMerge() {
0808:                return false;
0809:            }
0810:
0811:            /**
0812:             * {@inheritDoc}
0813:             */
0814:            public HttpAccess getHttpAccess() {
0815:                return null;
0816:            }
0817:
0818:            /**
0819:             * {@inheritDoc}
0820:             */
0821:            public boolean parseEntityReference(String reference, Reference ref) {
0822:                // for preferences access
0823:                if (reference.startsWith(REFERENCE_ROOT)) {
0824:                    String id = null;
0825:
0826:                    // we will get null, service, userId
0827:                    String[] parts = StringUtil.split(reference,
0828:                            Entity.SEPARATOR);
0829:
0830:                    if (parts.length > 2) {
0831:                        id = parts[2];
0832:                    }
0833:
0834:                    ref.set(APPLICATION_ID, null, id, null, null);
0835:
0836:                    return true;
0837:                }
0838:
0839:                return false;
0840:            }
0841:
0842:            /**
0843:             * {@inheritDoc}
0844:             */
0845:            public String getEntityDescription(Reference ref) {
0846:                return null;
0847:            }
0848:
0849:            /**
0850:             * {@inheritDoc}
0851:             */
0852:            public ResourceProperties getEntityResourceProperties(Reference ref) {
0853:                return null;
0854:            }
0855:
0856:            /**
0857:             * {@inheritDoc}
0858:             */
0859:            public Entity getEntity(Reference ref) {
0860:                return null;
0861:            }
0862:
0863:            /**
0864:             * {@inheritDoc}
0865:             */
0866:            public Collection getEntityAuthzGroups(Reference ref, String userId) {
0867:                // for alias access %%% ? what realm? -ggolden
0868:                return null;
0869:            }
0870:
0871:            /**
0872:             * {@inheritDoc}
0873:             */
0874:            public String getEntityUrl(Reference ref) {
0875:                return null;
0876:            }
0877:
0878:            /**
0879:             * {@inheritDoc}
0880:             */
0881:            public String archive(String siteId, Document doc, Stack stack,
0882:                    String archivePath, List attachments) {
0883:                return "";
0884:            }
0885:
0886:            /**
0887:             * {@inheritDoc}
0888:             */
0889:            public String merge(String siteId, Element root,
0890:                    String archivePath, String fromSiteId, Map attachmentNames,
0891:                    Map userIdTrans, Set userListAllowImport) {
0892:                return "";
0893:            }
0894:
0895:            /**********************************************************************************************************************************************************************************************************************************************************
0896:             * Alias implementation
0897:             *********************************************************************************************************************************************************************************************************************************************************/
0898:
0899:            /**
0900:             * <p>
0901:             * BaseAlias is an implementation of the CHEF Alias object.
0902:             * </p>
0903:             * 
0904:             * @author University of Michigan, CHEF Software Development Team
0905:             */
0906:            public class BaseAliasEdit implements  AliasEdit,
0907:                    SessionBindingListener {
0908:                /** The alias id. */
0909:                protected String m_id = null;
0910:
0911:                /** The alias target. */
0912:                protected String m_target = null;
0913:
0914:                /** The properties. */
0915:                protected ResourcePropertiesEdit m_properties = null;
0916:
0917:                /** The created user id. */
0918:                protected String m_createdUserId = null;
0919:
0920:                /** The last modified user id. */
0921:                protected String m_lastModifiedUserId = null;
0922:
0923:                /** The time created. */
0924:                protected Time m_createdTime = null;
0925:
0926:                /** The time last modified. */
0927:                protected Time m_lastModifiedTime = null;
0928:
0929:                /** The event code for this edit. */
0930:                protected String m_event = null;
0931:
0932:                /** Active flag. */
0933:                protected boolean m_active = false;
0934:
0935:                /**
0936:                 * Clean up.
0937:                 */
0938:                protected void finalize() {
0939:                    // catch the case where an edit was made but never resolved
0940:                    if (m_active) {
0941:                        cancel(this );
0942:                    }
0943:
0944:                } // finalize
0945:
0946:                /**
0947:                 * Construct.
0948:                 * 
0949:                 * @param id
0950:                 *        The id.
0951:                 */
0952:                public BaseAliasEdit(String id) {
0953:                    m_id = id;
0954:
0955:                    // setup for properties
0956:                    ResourcePropertiesEdit props = new BaseResourcePropertiesEdit();
0957:                    m_properties = props;
0958:
0959:                    // if not a reconstruction, add properties
0960:                    if ((m_id != null) && (m_id.length() > 0))
0961:                        addLiveProperties(props);
0962:
0963:                } // BaseAlias
0964:
0965:                /**
0966:                 * ReConstruct.
0967:                 * 
0968:                 * @param id
0969:                 *        The id.
0970:                 * @param target
0971:                 *        The target.
0972:                 * @param createdBy
0973:                 *        The createdBy property.
0974:                 * @param createdOn
0975:                 *        The createdOn property.
0976:                 * @param modifiedBy
0977:                 *        The modified by property.
0978:                 * @param modifiedOn
0979:                 *        The modified on property.
0980:                 */
0981:                public BaseAliasEdit(String id, String target,
0982:                        String createdBy, Time createdOn, String modifiedBy,
0983:                        Time modifiedOn) {
0984:                    m_id = id;
0985:                    m_target = target;
0986:                    m_createdUserId = createdBy;
0987:                    m_lastModifiedUserId = modifiedBy;
0988:                    m_createdTime = createdOn;
0989:                    m_lastModifiedTime = modifiedOn;
0990:
0991:                    // setup for properties, but mark them lazy since we have not yet established them from data
0992:                    BaseResourcePropertiesEdit props = new BaseResourcePropertiesEdit();
0993:                    props.setLazy(true);
0994:                    m_properties = props;
0995:
0996:                } // BaseAlias
0997:
0998:                /**
0999:                 * Construct from another Alias object.
1000:                 * 
1001:                 * @param alias
1002:                 *        The alias object to use for values.
1003:                 */
1004:                public BaseAliasEdit(BaseAliasEdit alias) {
1005:                    setAll(alias);
1006:
1007:                } // BaseAlias
1008:
1009:                /**
1010:                 * Construct from information in XML.
1011:                 * 
1012:                 * @param el
1013:                 *        The XML DOM Element definining the alias.
1014:                 */
1015:                public BaseAliasEdit(Element el) {
1016:                    // setup for properties
1017:                    m_properties = new BaseResourcePropertiesEdit();
1018:
1019:                    m_id = el.getAttribute("id");
1020:                    m_target = el.getAttribute("target");
1021:
1022:                    m_createdUserId = StringUtil.trimToNull(el
1023:                            .getAttribute("created-id"));
1024:                    m_lastModifiedUserId = StringUtil.trimToNull(el
1025:                            .getAttribute("modified-id"));
1026:
1027:                    String time = StringUtil.trimToNull(el
1028:                            .getAttribute("created-time"));
1029:                    if (time != null) {
1030:                        m_createdTime = timeService().newTimeGmt(time);
1031:                    }
1032:
1033:                    time = StringUtil.trimToNull(el
1034:                            .getAttribute("modified-time"));
1035:                    if (time != null) {
1036:                        m_lastModifiedTime = timeService().newTimeGmt(time);
1037:                    }
1038:
1039:                    // the children (properties)
1040:                    NodeList children = el.getChildNodes();
1041:                    final int length = children.getLength();
1042:                    for (int i = 0; i < length; i++) {
1043:                        Node child = children.item(i);
1044:                        if (child.getNodeType() != Node.ELEMENT_NODE)
1045:                            continue;
1046:                        Element element = (Element) child;
1047:
1048:                        // look for properties
1049:                        if (element.getTagName().equals("properties")) {
1050:                            // re-create properties
1051:                            m_properties = new BaseResourcePropertiesEdit(
1052:                                    element);
1053:
1054:                            // pull out some properties into fields to convert old (pre 1.18) versions
1055:                            if (m_createdUserId == null) {
1056:                                m_createdUserId = m_properties
1057:                                        .getProperty("CHEF:creator");
1058:                            }
1059:                            if (m_lastModifiedUserId == null) {
1060:                                m_lastModifiedUserId = m_properties
1061:                                        .getProperty("CHEF:modifiedby");
1062:                            }
1063:                            if (m_createdTime == null) {
1064:                                try {
1065:                                    m_createdTime = m_properties
1066:                                            .getTimeProperty("DAV:creationdate");
1067:                                } catch (Exception ignore) {
1068:                                }
1069:                            }
1070:                            if (m_lastModifiedTime == null) {
1071:                                try {
1072:                                    m_lastModifiedTime = m_properties
1073:                                            .getTimeProperty("DAV:getlastmodified");
1074:                                } catch (Exception ignore) {
1075:                                }
1076:                            }
1077:                            m_properties.removeProperty("CHEF:creator");
1078:                            m_properties.removeProperty("CHEF:modifiedby");
1079:                            m_properties.removeProperty("DAV:creationdate");
1080:                            m_properties.removeProperty("DAV:getlastmodified");
1081:                        }
1082:                    }
1083:
1084:                } // BaseAlias
1085:
1086:                /**
1087:                 * Take all values from this object.
1088:                 * 
1089:                 * @param alias
1090:                 *        The alias object to take values from.
1091:                 */
1092:                protected void setAll(BaseAliasEdit alias) {
1093:                    m_id = alias.m_id;
1094:                    m_target = alias.m_target;
1095:                    m_createdUserId = ((BaseAliasEdit) alias).m_createdUserId;
1096:                    m_lastModifiedUserId = ((BaseAliasEdit) alias).m_lastModifiedUserId;
1097:                    if (((BaseAliasEdit) alias).m_createdTime != null)
1098:                        m_createdTime = (Time) ((BaseAliasEdit) alias).m_createdTime
1099:                                .clone();
1100:                    if (((BaseAliasEdit) alias).m_lastModifiedTime != null)
1101:                        m_lastModifiedTime = (Time) ((BaseAliasEdit) alias).m_lastModifiedTime
1102:                                .clone();
1103:
1104:                    m_properties = new BaseResourcePropertiesEdit();
1105:                    m_properties.addAll(alias.getProperties());
1106:                    ((BaseResourcePropertiesEdit) m_properties)
1107:                            .setLazy(((BaseResourceProperties) alias
1108:                                    .getProperties()).isLazy());
1109:
1110:                } // setAll
1111:
1112:                /**
1113:                 * Serialize the resource into XML, adding an element to the doc under the top of the stack element.
1114:                 * 
1115:                 * @param doc
1116:                 *        The DOM doc to contain the XML (or null for a string return).
1117:                 * @param stack
1118:                 *        The DOM elements, the top of which is the containing element of the new "resource" element.
1119:                 * @return The newly added element.
1120:                 */
1121:                public Element toXml(Document doc, Stack stack) {
1122:                    Element alias = doc.createElement("alias");
1123:
1124:                    if (stack.isEmpty()) {
1125:                        doc.appendChild(alias);
1126:                    } else {
1127:                        ((Element) stack.peek()).appendChild(alias);
1128:                    }
1129:
1130:                    stack.push(alias);
1131:
1132:                    alias.setAttribute("id", m_id);
1133:                    alias.setAttribute("target", m_target);
1134:                    alias.setAttribute("created-id", m_createdUserId);
1135:                    alias.setAttribute("modified-id", m_lastModifiedUserId);
1136:                    alias
1137:                            .setAttribute("created-time", m_createdTime
1138:                                    .toString());
1139:                    alias.setAttribute("modified-time", m_lastModifiedTime
1140:                            .toString());
1141:
1142:                    // properties
1143:                    getProperties().toXml(doc, stack);
1144:
1145:                    stack.pop();
1146:
1147:                    return alias;
1148:
1149:                } // toXml
1150:
1151:                /**
1152:                 * Access the alias id.
1153:                 * 
1154:                 * @return The alias id string.
1155:                 */
1156:                public String getId() {
1157:                    return m_id;
1158:
1159:                } // getId
1160:
1161:                /**
1162:                 * {@inheritDoc}
1163:                 */
1164:                public User getCreatedBy() {
1165:                    try {
1166:                        return userDirectoryService().getUser(m_createdUserId);
1167:                    } catch (Exception e) {
1168:                        return userDirectoryService().getAnonymousUser();
1169:                    }
1170:                }
1171:
1172:                /**
1173:                 * {@inheritDoc}
1174:                 */
1175:                public User getModifiedBy() {
1176:                    try {
1177:                        return userDirectoryService().getUser(
1178:                                m_lastModifiedUserId);
1179:                    } catch (Exception e) {
1180:                        return userDirectoryService().getAnonymousUser();
1181:                    }
1182:                }
1183:
1184:                /**
1185:                 * {@inheritDoc}
1186:                 */
1187:                public Time getCreatedTime() {
1188:                    return m_createdTime;
1189:                }
1190:
1191:                /**
1192:                 * {@inheritDoc}
1193:                 */
1194:                public Time getModifiedTime() {
1195:                    return m_lastModifiedTime;
1196:                }
1197:
1198:                /**
1199:                 * Access the alias target.
1200:                 * 
1201:                 * @return The alias target.
1202:                 */
1203:                public String getTarget() {
1204:                    return m_target;
1205:
1206:                } // getTarget
1207:
1208:                /**
1209:                 * Set the alias target.
1210:                 * 
1211:                 * @param target
1212:                 *        The alias target.
1213:                 */
1214:                public void setTarget(String target) {
1215:                    m_target = target;
1216:
1217:                } // setTarget
1218:
1219:                /**
1220:                 * Access the URL which can be used to access the resource.
1221:                 * 
1222:                 * @return The URL which can be used to access the resource.
1223:                 */
1224:                public String getUrl() {
1225:                    return getAccessPoint(false) + m_id;
1226:
1227:                } // getUrl
1228:
1229:                /**
1230:                 * Access the internal reference which can be used to access the resource from within the system.
1231:                 * 
1232:                 * @return The the internal reference which can be used to access the resource from within the system.
1233:                 */
1234:                public String getReference() {
1235:                    return aliasReference(m_id);
1236:
1237:                } // getReference
1238:
1239:                /**
1240:                 * @inheritDoc
1241:                 */
1242:                public String getReference(String rootProperty) {
1243:                    return getReference();
1244:                }
1245:
1246:                /**
1247:                 * @inheritDoc
1248:                 */
1249:                public String getUrl(String rootProperty) {
1250:                    return getUrl();
1251:                }
1252:
1253:                /**
1254:                 * Access the resources's properties.
1255:                 * 
1256:                 * @return The resources's properties.
1257:                 */
1258:                public ResourceProperties getProperties() {
1259:                    // if lazy, resolve
1260:                    if (((BaseResourceProperties) m_properties).isLazy()) {
1261:                        ((BaseResourcePropertiesEdit) m_properties)
1262:                                .setLazy(false);
1263:                        m_storage.readProperties(this , m_properties);
1264:                    }
1265:
1266:                    return m_properties;
1267:
1268:                } // getProperties
1269:
1270:                /**
1271:                 * Are these objects equal? If they are both Alias objects, and they have matching id's, they are.
1272:                 * 
1273:                 * @return true if they are equal, false if not.
1274:                 */
1275:                public boolean equals(Object obj) {
1276:                    if (!(obj instanceof  BaseAliasEdit))
1277:                        return false;
1278:                    return ((BaseAliasEdit) obj).getId().equals(getId());
1279:
1280:                } // equals
1281:
1282:                /**
1283:                 * Make a hash code that reflects the equals() logic as well. We want two objects, even if different instances, if they have the same id to hash the same.
1284:                 */
1285:                public int hashCode() {
1286:                    return getId().hashCode();
1287:
1288:                } // hashCode
1289:
1290:                /**
1291:                 * Compare this object with the specified object for order.
1292:                 * 
1293:                 * @return A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
1294:                 */
1295:                public int compareTo(Object obj) {
1296:                    if (!(obj instanceof  BaseAliasEdit))
1297:                        throw new ClassCastException();
1298:
1299:                    // if the object are the same, say so
1300:                    if (obj == this )
1301:                        return 0;
1302:
1303:                    // sort based on (unique) id
1304:                    int compare = getId().compareTo(
1305:                            ((BaseAliasEdit) obj).getId());
1306:
1307:                    return compare;
1308:
1309:                } // compareTo
1310:
1311:                /**
1312:                 * Access the event code for this edit.
1313:                 * 
1314:                 * @return The event code for this edit.
1315:                 */
1316:                protected String getEvent() {
1317:                    return m_event;
1318:                }
1319:
1320:                /**
1321:                 * Set the event code for this edit.
1322:                 * 
1323:                 * @param event
1324:                 *        The event code for this edit.
1325:                 */
1326:                protected void setEvent(String event) {
1327:                    m_event = event;
1328:                }
1329:
1330:                /**
1331:                 * Access the resource's properties for modification
1332:                 * 
1333:                 * @return The resource's properties.
1334:                 */
1335:                public ResourcePropertiesEdit getPropertiesEdit() {
1336:                    // if lazy, resolve
1337:                    if (((BaseResourceProperties) m_properties).isLazy()) {
1338:                        ((BaseResourcePropertiesEdit) m_properties)
1339:                                .setLazy(false);
1340:                        m_storage.readProperties(this , m_properties);
1341:                    }
1342:
1343:                    return m_properties;
1344:
1345:                } // getPropertiesEdit
1346:
1347:                /**
1348:                 * Enable editing.
1349:                 */
1350:                protected void activate() {
1351:                    m_active = true;
1352:
1353:                } // activate
1354:
1355:                /**
1356:                 * Check to see if the edit is still active, or has already been closed.
1357:                 * 
1358:                 * @return true if the edit is active, false if it's been closed.
1359:                 */
1360:                public boolean isActiveEdit() {
1361:                    return m_active;
1362:
1363:                } // isActiveEdit
1364:
1365:                /**
1366:                 * Close the edit object - it cannot be used after this.
1367:                 */
1368:                protected void closeEdit() {
1369:                    m_active = false;
1370:
1371:                } // closeEdit
1372:
1373:                /**
1374:                 * @return a description of the item this alias's target applies to.
1375:                 */
1376:                public String getDescription() {
1377:                    try {
1378:                        // the rest are references to some resource
1379:                        Reference ref = entityManager().newReference(
1380:                                getTarget());
1381:                        return ref.getDescription();
1382:                    } catch (Throwable any) {
1383:                        return "unknown";
1384:                    }
1385:
1386:                } // getDescription
1387:
1388:                /******************************************************************************************************************************************************************************************************************************************************
1389:                 * SessionBindingListener implementation
1390:                 *****************************************************************************************************************************************************************************************************************************************************/
1391:
1392:                public void valueBound(SessionBindingEvent event) {
1393:                }
1394:
1395:                public void valueUnbound(SessionBindingEvent event) {
1396:                    if (M_log.isDebugEnabled())
1397:                        M_log.debug("valueUnbound()");
1398:
1399:                    // catch the case where an edit was made but never resolved
1400:                    if (m_active) {
1401:                        cancel(this );
1402:                    }
1403:
1404:                } // valueUnbound
1405:
1406:            } // BaseAliasEdit
1407:
1408:            /**********************************************************************************************************************************************************************************************************************************************************
1409:             * Storage
1410:             *********************************************************************************************************************************************************************************************************************************************************/
1411:
1412:            protected interface Storage {
1413:                /**
1414:                 * Open.
1415:                 */
1416:                public void open();
1417:
1418:                /**
1419:                 * Close.
1420:                 */
1421:                public void close();
1422:
1423:                /**
1424:                 * Check if an alias with this id exists.
1425:                 * 
1426:                 * @param id
1427:                 *        The alias id (case insensitive).
1428:                 * @return true if an alias by this id exists, false if not.
1429:                 */
1430:                public boolean check(String id);
1431:
1432:                /**
1433:                 * Get the alias with this id, or null if not found.
1434:                 * 
1435:                 * @param id
1436:                 *        The alias id (case insensitive).
1437:                 * @return The alias with this id, or null if not found.
1438:                 */
1439:                public AliasEdit get(String id);
1440:
1441:                /**
1442:                 * Get all the alias.
1443:                 * 
1444:                 * @return The List (BaseAliasEdit) of all alias.
1445:                 */
1446:                public List getAll();
1447:
1448:                /**
1449:                 * Get all the alias in record range.
1450:                 * 
1451:                 * @param first
1452:                 *        The first record position to return.
1453:                 * @param last
1454:                 *        The last record position to return.
1455:                 * @return The List (BaseAliasEdit) of all alias.
1456:                 */
1457:                public List getAll(int first, int last);
1458:
1459:                /**
1460:                 * Count all the aliases.
1461:                 * 
1462:                 * @return The count of all aliases.
1463:                 */
1464:                public int count();
1465:
1466:                /**
1467:                 * Search for aliases with id or target matching criteria, in range.
1468:                 * 
1469:                 * @param criteria
1470:                 *        The search criteria.
1471:                 * @param first
1472:                 *        The first record position to return.
1473:                 * @param last
1474:                 *        The last record position to return.
1475:                 * @return The List (BaseAliasEdit) of all alias.
1476:                 */
1477:                public List search(String criteria, int first, int last);
1478:
1479:                /**
1480:                 * Count all the aliases with id or target matching criteria.
1481:                 * 
1482:                 * @param criteria
1483:                 *        The search criteria.
1484:                 * @return The count of all aliases with id or target matching criteria.
1485:                 */
1486:                public int countSearch(String criteria);
1487:
1488:                /**
1489:                 * Get all the alias that point at this target.
1490:                 * 
1491:                 * @return The List (BaseAliasEdit) of all alias that point at this target
1492:                 */
1493:                public List getAll(String target);
1494:
1495:                /**
1496:                 * Get all the alias that point at this target, in record range.
1497:                 * 
1498:                 * @param first
1499:                 *        The first record position to return.
1500:                 * @param last
1501:                 *        The last record position to return.
1502:                 * @return The List (BaseAliasEdit) of all alias that point at this target, in record range.
1503:                 */
1504:                public List getAll(String target, int first, int last);
1505:
1506:                /**
1507:                 * Add a new alias with this id.
1508:                 * 
1509:                 * @param id
1510:                 *        The alias id.
1511:                 * @return The locked Alias object with this id, or null if the id is in use.
1512:                 */
1513:                public AliasEdit put(String id);
1514:
1515:                /**
1516:                 * Get a lock on the alias with this id, or null if a lock cannot be gotten.
1517:                 * 
1518:                 * @param id
1519:                 *        The alias id (case insensitive).
1520:                 * @return The locked Alias with this id, or null if this records cannot be locked.
1521:                 */
1522:                public AliasEdit edit(String id);
1523:
1524:                /**
1525:                 * Commit the changes and release the lock.
1526:                 * 
1527:                 * @param user
1528:                 *        The alias to commit.
1529:                 */
1530:                public void commit(AliasEdit alias);
1531:
1532:                /**
1533:                 * Cancel the changes and release the lock.
1534:                 * 
1535:                 * @param user
1536:                 *        The alias to commit.
1537:                 */
1538:                public void cancel(AliasEdit alias);
1539:
1540:                /**
1541:                 * Remove this alias.
1542:                 * 
1543:                 * @param user
1544:                 *        The alias to remove.
1545:                 */
1546:                public void remove(AliasEdit alias);
1547:
1548:                /**
1549:                 * Read properties from storage into the edit's properties.
1550:                 * 
1551:                 * @param edit
1552:                 *        The user to read properties for.
1553:                 */
1554:                public void readProperties(AliasEdit edit,
1555:                        ResourcePropertiesEdit props);
1556:
1557:            } // Storage
1558:
1559:            /**********************************************************************************************************************************************************************************************************************************************************
1560:             * StorageUser implementation (no container)
1561:             *********************************************************************************************************************************************************************************************************************************************************/
1562:
1563:            /**
1564:             * Construct a new continer given just an id.
1565:             * 
1566:             * @param id
1567:             *        The id for the new object.
1568:             * @return The new containe Resource.
1569:             */
1570:            public Entity newContainer(String ref) {
1571:                return null;
1572:            }
1573:
1574:            /**
1575:             * Construct a new container resource, from an XML element.
1576:             * 
1577:             * @param element
1578:             *        The XML.
1579:             * @return The new container resource.
1580:             */
1581:            public Entity newContainer(Element element) {
1582:                return null;
1583:            }
1584:
1585:            /**
1586:             * Construct a new container resource, as a copy of another
1587:             * 
1588:             * @param other
1589:             *        The other contianer to copy.
1590:             * @return The new container resource.
1591:             */
1592:            public Entity newContainer(Entity other) {
1593:                return null;
1594:            }
1595:
1596:            /**
1597:             * Construct a new resource given just an id.
1598:             * 
1599:             * @param container
1600:             *        The Resource that is the container for the new resource (may be null).
1601:             * @param id
1602:             *        The id for the new object.
1603:             * @param others
1604:             *        (options) array of objects to load into the Resource's fields.
1605:             * @return The new resource.
1606:             */
1607:            public Entity newResource(Entity container, String id,
1608:                    Object[] others) {
1609:                return new BaseAliasEdit(id);
1610:            }
1611:
1612:            /**
1613:             * Construct a new resource, from an XML element.
1614:             * 
1615:             * @param container
1616:             *        The Resource that is the container for the new resource (may be null).
1617:             * @param element
1618:             *        The XML.
1619:             * @return The new resource from the XML.
1620:             */
1621:            public Entity newResource(Entity container, Element element) {
1622:                return new BaseAliasEdit(element);
1623:            }
1624:
1625:            /**
1626:             * Construct a new resource from another resource of the same type.
1627:             * 
1628:             * @param container
1629:             *        The Resource that is the container for the new resource (may be null).
1630:             * @param other
1631:             *        The other resource.
1632:             * @return The new resource as a copy of the other.
1633:             */
1634:            public Entity newResource(Entity container, Entity other) {
1635:                return new BaseAliasEdit((BaseAliasEdit) other);
1636:            }
1637:
1638:            /**
1639:             * Construct a new continer given just an id.
1640:             * 
1641:             * @param id
1642:             *        The id for the new object.
1643:             * @return The new containe Resource.
1644:             */
1645:            public Edit newContainerEdit(String ref) {
1646:                return null;
1647:            }
1648:
1649:            /**
1650:             * Construct a new container resource, from an XML element.
1651:             * 
1652:             * @param element
1653:             *        The XML.
1654:             * @return The new container resource.
1655:             */
1656:            public Edit newContainerEdit(Element element) {
1657:                return null;
1658:            }
1659:
1660:            /**
1661:             * Construct a new container resource, as a copy of another
1662:             * 
1663:             * @param other
1664:             *        The other contianer to copy.
1665:             * @return The new container resource.
1666:             */
1667:            public Edit newContainerEdit(Entity other) {
1668:                return null;
1669:            }
1670:
1671:            /**
1672:             * Construct a new resource given just an id.
1673:             * 
1674:             * @param container
1675:             *        The Resource that is the container for the new resource (may be null).
1676:             * @param id
1677:             *        The id for the new object.
1678:             * @param others
1679:             *        (options) array of objects to load into the Resource's fields.
1680:             * @return The new resource.
1681:             */
1682:            public Edit newResourceEdit(Entity container, String id,
1683:                    Object[] others) {
1684:                BaseAliasEdit e = new BaseAliasEdit(id);
1685:                e.activate();
1686:                return e;
1687:            }
1688:
1689:            /**
1690:             * Construct a new resource, from an XML element.
1691:             * 
1692:             * @param container
1693:             *        The Resource that is the container for the new resource (may be null).
1694:             * @param element
1695:             *        The XML.
1696:             * @return The new resource from the XML.
1697:             */
1698:            public Edit newResourceEdit(Entity container, Element element) {
1699:                BaseAliasEdit e = new BaseAliasEdit(element);
1700:                e.activate();
1701:                return e;
1702:            }
1703:
1704:            /**
1705:             * Construct a new resource from another resource of the same type.
1706:             * 
1707:             * @param container
1708:             *        The Resource that is the container for the new resource (may be null).
1709:             * @param other
1710:             *        The other resource.
1711:             * @return The new resource as a copy of the other.
1712:             */
1713:            public Edit newResourceEdit(Entity container, Entity other) {
1714:                BaseAliasEdit e = new BaseAliasEdit((BaseAliasEdit) other);
1715:                e.activate();
1716:                return e;
1717:            }
1718:
1719:            /**
1720:             * Collect the fields that need to be stored outside the XML (for the resource).
1721:             * 
1722:             * @return An array of field values to store in the record outside the XML (for the resource).
1723:             */
1724:            public Object[] storageFields(Entity r) {
1725:                return null;
1726:            }
1727:
1728:            /**
1729:             * Check if this resource is in draft mode.
1730:             * 
1731:             * @param r
1732:             *        The resource.
1733:             * @return true if the resource is in draft mode, false if not.
1734:             */
1735:            public boolean isDraft(Entity r) {
1736:                return false;
1737:            }
1738:
1739:            /**
1740:             * Access the resource owner user id.
1741:             * 
1742:             * @param r
1743:             *        The resource.
1744:             * @return The resource owner user id.
1745:             */
1746:            public String getOwnerId(Entity r) {
1747:                return null;
1748:            }
1749:
1750:            /**
1751:             * Access the resource date.
1752:             * 
1753:             * @param r
1754:             *        The resource.
1755:             * @return The resource date.
1756:             */
1757:            public Time getDate(Entity r) {
1758:                return null;
1759:            }
1760:
1761:        } // BaseAliasService
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.