
from org.gvsig.fmap.dal.feature.impl import DefaultEditableFeature as JEditableFeature
import feature
from java.lang import IllegalArgumentException
from java.lang import RuntimeException

def _setGeometry(self,*args):
  if len(args)==1:
    self.setDefaultGeometry(args[0])
    return
  if len(args)==2:
    self.set(args[0],args[1])
    return
  raise IllegalArgumentException("Incorrent number of arguments ("+len(args)+"), expected 1 or 2")
  
def _setValues(self,*args,**kwargs):
  if len(args)!=0:
    if len(args)!=2:
      raise IllegalArgumentException("Incorrent number of arguments ("+len(args)+"), expected 2.")
    self.set(args[0],args[1])
    return
  for k,v in kwargs.iteritems():
    self.set(k,v)

def _setitem(self,attributeName, value):
  return self.set(attributeName,value)

def _setattr(self,attributeName, value):
  try:
      self.set(attributeName, value)        
  except Exception, ex:
    raise RuntimeException("Can't set the attribute %s of feature (%s)" % (attributeName, str(ex)))    



#
# Inject new methods in the class JEditableFeature
#
JEditableFeature.getValues = feature._getValues
JEditableFeature.geometry = feature._geometry
JEditableFeature.edit = feature._edit
JEditableFeature.__getitem__ = feature._getitem
JEditableFeature.__getattr__ = feature._getattr
JEditableFeature.__call__ = feature._call
JEditableFeature.__len__ = feature._len
JEditableFeature.__iter__ = feature._itervalues
JEditableFeature.itervalues = feature._itervalues
JEditableFeature.iteritems = feature._iteritems
JEditableFeature.iterkeys = feature._iterkeys

JEditableFeature.setValues = _setValues
JEditableFeature.setGeometry = _setGeometry
JEditableFeature.__setitem__ = _setitem
JEditableFeature.__setattr__ = _setattr


