/**
  * Construct <code>ShpGeoResourceImpl</code>.
  *
  * @param parent
  * @param typename
  */
 public ShpGeoResourceImpl(ShpServiceImpl parent, String typename) {
   this.service = parent;
   this.parent = parent;
   this.typename = typename;
   try {
     identifier = new URL(parent.getIdentifier().toString() + "#" + typename); // $NON-NLS-1$
     id = new ID(parent.getID(), typename);
   } catch (MalformedURLException e) {
     identifier = parent.getIdentifier();
   }
 }
  public Style style(IProgressMonitor monitor) {
    URL url = parent.getIdentifier();
    File file = URLUtils.urlToFile(url);
    String shp = file.getAbsolutePath();

    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());

    // strip off the extension and check for sld
    String sld = shp.substring(0, shp.length() - 4) + ".sld"; // $NON-NLS-1$
    File f = new File(sld);
    if (!f.exists()) {
      // try upper case
      sld = shp.substring(0, shp.length() - 4) + ".SLD"; // $NON-NLS-1$
      f = new File(sld);
    }

    if (f.exists()) {
      // parse it up
      SLDParser parser = new SLDParser(styleFactory);
      try {
        parser.setInput(f);
      } catch (FileNotFoundException e) {
        return null; // well that is unexpected since f.exists()
      }
      Style[] styles = parser.readXML();

      FeatureSource<SimpleFeatureType, SimpleFeature> source;
      try {
        source = featureSource(null);
      } catch (IOException e) {
        return null; // does not look like there is anything in the shapefile
      }
      SimpleFeatureType featureType = source.getSchema();
      // put the first one on
      if (styles != null && styles.length > 0) {
        Style style = SLD.matchingStyle(styles, featureType);
        if (style == null) {
          style = styles[0];
        }

        makeGraphicsAbsolute(file, style);
        return style;
      }
    }
    return null; // well nothing worked out; make your own style
  }