Changeset 1340


Ignore:
Timestamp:
05/19/11 07:33:10 (13 years ago)
Author:
twagoo
Message:

Moved ComponentRegistryUtils? helper methods to ImplBase? class

Location:
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java

    r1339 r1340  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
    4 import clarin.cmdi.componentregistry.ComponentRegistryUtils;
    54import clarin.cmdi.componentregistry.DeleteFailedException;
     5import clarin.cmdi.componentregistry.MDMarshaller;
    66import clarin.cmdi.componentregistry.UserUnauthorizedException;
    77import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     8import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header;
     9import clarin.cmdi.componentregistry.components.CMDComponentType;
    810import clarin.cmdi.componentregistry.model.AbstractDescription;
    911import clarin.cmdi.componentregistry.model.ComponentDescription;
     
    1113import java.io.IOException;
    1214import java.io.OutputStream;
     15import java.io.UnsupportedEncodingException;
    1316import java.security.Principal;
    1417import java.util.ArrayList;
    1518import java.util.List;
     19import javax.xml.bind.JAXBException;
     20import org.apache.commons.lang.StringUtils;
     21import org.slf4j.Logger;
     22import org.slf4j.LoggerFactory;
    1623
    1724/**
     
    2027 */
    2128public abstract class ComponentRegistryImplBase implements ComponentRegistry{
     29        private final static Logger LOG = LoggerFactory.getLogger(ComponentRegistryImplBase.class);
    2230
    2331    @Override
     
    2735        for (ComponentDescription desc : descs) {
    2836            CMDComponentSpec spec = getMDComponent(desc.getId());
    29             if (spec != null && ComponentRegistryUtils.findComponentId(componentId, spec.getCMDComponent())) {
     37            if (spec != null && findComponentId(componentId, spec.getCMDComponent())) {
    3038                result.add(desc);
    3139            }
     
    3947        for (ProfileDescription profileDescription : getProfileDescriptions()) {
    4048            CMDComponentSpec profile = getMDProfile(profileDescription.getId());
    41             if (profile != null && ComponentRegistryUtils.findComponentId(componentId, profile.getCMDComponent())) {
     49            if (profile != null && findComponentId(componentId, profile.getCMDComponent())) {
    4250                result.add(profileDescription);
    4351            }
     
    4553        return result;
    4654    }
     55
     56    /* HELPER METHODS */
     57
     58    protected static String stripRegistryId(String id) {
     59        return StringUtils.removeStart(id, ComponentRegistry.REGISTRY_ID);
     60    }
     61
     62    protected static void enrichSpecHeader(CMDComponentSpec spec, AbstractDescription description) {
     63        Header header = spec.getHeader();
     64        header.setID(description.getId());
     65        if (StringUtils.isEmpty(header.getName())) {
     66            header.setName(description.getName());
     67        }
     68        if (StringUtils.isEmpty(header.getDescription())) {
     69            header.setDescription(description.getDescription());
     70        }
     71    }
     72
     73    protected static boolean findComponentId(String componentId, List<CMDComponentType> componentReferences) {
     74        for (CMDComponentType cmdComponent : componentReferences) {
     75            if (componentId.equals(cmdComponent.getComponentId())) {
     76                return true;
     77            } else if (findComponentId(componentId, cmdComponent.getCMDComponent())) {
     78                return true;
     79            }
     80        }
     81        return false;
     82    }
     83
     84    protected static void writeXsd(CMDComponentSpec expandedSpec, OutputStream outputStream) {
     85        MDMarshaller.generateXsd(expandedSpec, outputStream);
     86    }
     87
     88    protected static void writeXml(CMDComponentSpec spec, OutputStream outputStream) {
     89        try {
     90            MDMarshaller.marshal(spec, outputStream);
     91        } catch (UnsupportedEncodingException e) {
     92            LOG.error("Error in encoding: ", e);
     93        } catch (JAXBException e) {
     94            LOG.error("Cannot marshall spec: " + spec, e);
     95        }
     96    }
     97
     98    /* UNIMPLEMENTED INTERFACE METHODS */
    4799
    48100    @Override
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r1339 r1340  
    22
    33import clarin.cmdi.componentregistry.ComponentRegistry;
    4 import clarin.cmdi.componentregistry.ComponentRegistryUtils;
    54import clarin.cmdi.componentregistry.Configuration;
    65import clarin.cmdi.componentregistry.DeleteFailedException;
     
    131130    @Override
    132131    public int register(AbstractDescription description, CMDComponentSpec spec) {
    133         ComponentRegistryUtils.enrichSpecHeader(spec, description);
     132        enrichSpecHeader(spec, description);
    134133        try {
    135134            String xml = componentSpecToString(spec);
     
    194193        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.
    195194                expandProfile(profileId, this);
    196         ComponentRegistryUtils.writeXml(expandedSpec, output);
     195        writeXml(expandedSpec, output);
    197196    }
    198197
     
    201200        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.
    202201                expandProfile(profileId, this);
    203         ComponentRegistryUtils.writeXsd(expandedSpec, outputStream);
     202        writeXsd(expandedSpec, outputStream);
    204203    }
    205204
     
    208207        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.
    209208                expandComponent(componentId, this);
    210         ComponentRegistryUtils.writeXml(expandedSpec, output);
     209        writeXml(expandedSpec, output);
    211210    }
    212211
     
    215214        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl.
    216215                expandComponent(componentId, this);
    217         ComponentRegistryUtils.writeXsd(expandedSpec, outputStream);
     216        writeXsd(expandedSpec, outputStream);
    218217    }
    219218
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryImpl.java

    r1339 r1340  
    33import clarin.cmdi.componentregistry.impl.ComponentRegistryImplBase;
    44import clarin.cmdi.componentregistry.ComponentRegistry;
    5 import clarin.cmdi.componentregistry.ComponentRegistryUtils;
    65import clarin.cmdi.componentregistry.Configuration;
    76import clarin.cmdi.componentregistry.DeleteFailedException;
     
    167166    public void getMDProfileAsXml(String profileId, OutputStream output) {
    168167        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderImpl.expandProfile(profileId, this);
    169         ComponentRegistryUtils.writeXml(expandedSpec, output);
     168        writeXml(expandedSpec, output);
    170169    }
    171170
     
    173172    public void getMDProfileAsXsd(String profileId, OutputStream outputStream) {
    174173        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderImpl.expandProfile(profileId, this);
    175         ComponentRegistryUtils.writeXsd(expandedSpec, outputStream);
     174        writeXsd(expandedSpec, outputStream);
    176175    }
    177176
    178177    private File getProfileFile(String profileId) {
    179         String id = ComponentRegistryUtils.stripRegistryId(profileId);
     178        String id = stripRegistryId(profileId);
    180179        File file = new File(getProfileDir(), id + File.separator + id + ".xml");
    181180        return file;
     
    195194    public void getMDComponentAsXml(String componentId, OutputStream output) {
    196195        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderImpl.expandComponent(componentId, this);
    197         ComponentRegistryUtils.writeXml(expandedSpec, output);
     196        writeXml(expandedSpec, output);
    198197    }
    199198
     
    201200    public void getMDComponentAsXsd(String componentId, OutputStream outputStream) {
    202201        CMDComponentSpec expandedSpec = CMDComponentSpecExpanderImpl.expandComponent(componentId, this);
    203         ComponentRegistryUtils.writeXsd(expandedSpec, outputStream);
     202        writeXsd(expandedSpec, outputStream);
    204203    }
    205204
    206205    private File getComponentFile(String componentId) {
    207         String id = ComponentRegistryUtils.stripRegistryId(componentId);
     206        String id = stripRegistryId(componentId);
    208207        File file = new File(getComponentDir(), id + File.separator + id + ".xml");
    209208        return file;
     
    265264
    266265    private int register(File storageDir, AbstractDescription description, CMDComponentSpec spec, Closure onFail) {
    267         String strippedId = ComponentRegistryUtils.stripRegistryId(description.getId());
     266        String strippedId = stripRegistryId(description.getId());
    268267        File dir = new File(storageDir, strippedId);
    269268        boolean success = false;
     
    273272                writeDescription(dir, description);
    274273                if (spec != null) {
    275                     ComponentRegistryUtils.enrichSpecHeader(spec, description);
     274                    enrichSpecHeader(spec, description);
    276275                    writeCMDComponentSpec(dir, strippedId + ".xml", spec);
    277276                }
     
    403402        File file = null;
    404403        if (description.isProfile()) {
    405             file = new File(resourceConfig.getProfileDeletionDir(), ComponentRegistryUtils.stripRegistryId(description.getId()));
     404            file = new File(resourceConfig.getProfileDeletionDir(), stripRegistryId(description.getId()));
    406405        } else {
    407             file = new File(resourceConfig.getComponentDeletionDir(), ComponentRegistryUtils.stripRegistryId(description.getId()));
     406            file = new File(resourceConfig.getComponentDeletionDir(), stripRegistryId(description.getId()));
    408407        }
    409408        if (file.exists()) {
Note: See TracChangeset for help on using the changeset viewer.