001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/model/repository/sql/plain/PlainWorkspaceLayoutAccessor.java,v 1.1.1.1 2004/03/25 12:08:36 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:36 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.kernel.model.repository.sql.plain;
042:
043: import es.udc.mypersonalizer.kernel.conventions.ServiceConventions;
044: import es.udc.mypersonalizer.kernel.model.properties.Property;
045: import es.udc.mypersonalizer.kernel.model.repository.interfaces.WorkspaceLayout;
046: import es.udc.mypersonalizer.kernel.model.repository.interfaces.WorkspaceLayoutAccessor;
047: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceProperty;
048: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServicePropertyKey;
049: import es.udc.mypersonalizer.kernel.util.exceptions.InstanceNotFoundException;
050: import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
051: import java.util.*;
052:
053: /**
054: * This class is the default implementation for {@link WorkspaceLayoutAccessor},
055: * in charge of being delegated the retrieval, addition, removal or update of
056: * {@link WorkspaceLayout} objects to and from the repository.
057: *
058: * @author Daniel Fernandez
059: * @author Fernando Bellas
060: * @since 1.0
061: */
062: public class PlainWorkspaceLayoutAccessor implements
063: WorkspaceLayoutAccessor {
064:
065: /**
066: * The {@link PlainServicePropertyAccessor} used to access the
067: * repository
068: */
069: private PlainServicePropertyAccessor accessor = null;
070:
071: /**
072: * Creates a new instance of this class.
073: */
074: public PlainWorkspaceLayoutAccessor() {
075: accessor = new PlainServicePropertyAccessor();
076: }
077:
078: public WorkspaceLayout findWorkspaceLayout(Long identifier)
079: throws InternalErrorException, InstanceNotFoundException {
080: String serviceIdentifier = ServiceConventions.WORKSPACE_LAYOUT_SERVICE_IDENTIFIER;
081: ServicePropertyKey servicePropertyKey = new ServicePropertyKey(
082: serviceIdentifier, identifier);
083: ServiceProperty serviceProperty = accessor
084: .findServiceProperty(servicePropertyKey);
085: WorkspaceLayout workspaceLayout = new WorkspaceLayout(
086: identifier, serviceProperty.getProperty());
087:
088: return workspaceLayout;
089: }
090:
091: public Map findWorkspaceLayouts(Collection identifiers)
092: throws InternalErrorException, InstanceNotFoundException {
093: String serviceIdentifier = ServiceConventions.WORKSPACE_LAYOUT_SERVICE_IDENTIFIER;
094: Map workspaceLayouts = new HashMap();
095:
096: /*
097: * The WorkspaceLayouts must be retrieved one by one, because the
098: * ServicePropertyAccessor only allows us to do this due to the
099: * inherent complexity of retrieving a property from the repository.
100: */
101: Iterator identifiersIter = identifiers.iterator();
102: while (identifiersIter.hasNext()) {
103: Long currentIdentifier = (Long) identifiersIter.next();
104: ServicePropertyKey servicePropertyKey = new ServicePropertyKey(
105: serviceIdentifier, currentIdentifier);
106: ServiceProperty serviceProperty = accessor
107: .findServiceProperty(servicePropertyKey);
108: WorkspaceLayout workspaceLayout = new WorkspaceLayout(
109: currentIdentifier, serviceProperty.getProperty());
110: workspaceLayouts.put(currentIdentifier, workspaceLayout);
111: }
112: return workspaceLayouts;
113: }
114:
115: public WorkspaceLayout addWorkspaceLayout(Property property)
116: throws InternalErrorException {
117: String serviceIdentifier = ServiceConventions.WORKSPACE_LAYOUT_SERVICE_IDENTIFIER;
118: ServiceProperty serviceProperty = accessor.addServiceProperty(
119: serviceIdentifier, property);
120: WorkspaceLayout workspaceLayout = new WorkspaceLayout(
121: serviceProperty.getKey().getPropertyIdentifier(),
122: serviceProperty.getProperty());
123: return workspaceLayout;
124: }
125:
126: public void updateWorkspaceLayout(WorkspaceLayout workspaceLayout)
127: throws InternalErrorException, InstanceNotFoundException {
128: String serviceIdentifier = ServiceConventions.WORKSPACE_LAYOUT_SERVICE_IDENTIFIER;
129: ServicePropertyKey servicePropertyKey = new ServicePropertyKey(
130: serviceIdentifier, workspaceLayout.getIdentifier());
131: ServiceProperty serviceProperty = new ServiceProperty(
132: servicePropertyKey, workspaceLayout.getProperty());
133: accessor.updateServiceProperty(serviceProperty);
134: }
135:
136: public void removeWorkspaceLayout(Long identifier)
137: throws InternalErrorException, InstanceNotFoundException {
138: String serviceIdentifier = ServiceConventions.WORKSPACE_LAYOUT_SERVICE_IDENTIFIER;
139: ServicePropertyKey servicePropertyKey = new ServicePropertyKey(
140: serviceIdentifier, identifier);
141: accessor.removeServiceProperty(servicePropertyKey);
142: }
143:
144: }
|